001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008-2009 Sun Microsystems, Inc. 015 * Portions copyright 2015-2016 ForgeRock AS. 016 */ 017package org.opends.server.admin; 018 019import java.net.InetAddress; 020 021import org.forgerock.opendj.ldap.AddressMask; 022import org.forgerock.opendj.ldap.schema.AttributeType; 023import org.forgerock.opendj.ldap.DN; 024import org.opends.server.authorization.dseecompat.Aci; 025 026/** 027 * A visitor of property values, in the style of the visitor design 028 * pattern. Classes implementing this interface can query a property a 029 * value and its associated property definition in a type-safe manner 030 * when the kind of property value is unknown at compile time. When a 031 * visitor is passed to a property definition's accept method, the 032 * corresponding visit method most applicable to that property 033 * definition is invoked. 034 * <p> 035 * Each <code>visitXXX</code> method is provided with a default 036 * implementation which calls 037 * {@link #visitUnknown(PropertyDefinition, Object, Object)}. 038 * Sub-classes can override any or all of the methods to provide their 039 * own type-specific behavior. 040 * 041 * @param <R> 042 * The return type of this visitor's methods. Use 043 * {@link java.lang.Void} for visitors that do not need to 044 * return results. 045 * @param <P> 046 * The type of the additional parameter to this visitor's 047 * methods. Use {@link java.lang.Void} for visitors that do 048 * not need an additional parameter. 049 */ 050public abstract class PropertyValueVisitor<R, P> { 051 052 /** 053 * Default constructor. 054 */ 055 protected PropertyValueVisitor() { 056 // No implementation required. 057 } 058 059 060 061 /** 062 * Visit a dseecompat ACI. 063 * 064 * @param pd 065 * The dseecompat ACI property definition. 066 * @param v 067 * The property value to visit. 068 * @param p 069 * A visitor specified parameter. 070 * @return Returns a visitor specified result. 071 */ 072 public R visitACI(ACIPropertyDefinition pd, Aci v, 073 P p) { 074 return visitUnknown(pd, v, p); 075 } 076 077 078 079 /** 080 * Visit an aggregation property value. 081 * 082 * @param <C> 083 * The type of client managed object configuration that 084 * this aggregation property definition refers to. 085 * @param <S> 086 * The type of server managed object configuration that 087 * this aggregation property definition refers to. 088 * @param pd 089 * The aggregation property definition to visit. 090 * @param v 091 * The property value to visit. 092 * @param p 093 * A visitor specified parameter. 094 * @return Returns a visitor specified result. 095 */ 096 public <C extends ConfigurationClient, S extends Configuration> 097 R visitAggregation( 098 AggregationPropertyDefinition<C, S> pd, String v, P p) { 099 return visitUnknown(pd, v, p); 100 } 101 102 103 104 /** 105 * Visit an attribute type. 106 * 107 * @param pd 108 * The attribute type property definition. 109 * @param v 110 * The property value to visit. 111 * @param p 112 * A visitor specified parameter. 113 * @return Returns a visitor specified result. 114 */ 115 public R visitAttributeType(AttributeTypePropertyDefinition pd, 116 AttributeType v, P p) { 117 return visitUnknown(pd, v, p); 118 } 119 120 121 122 /** 123 * Visit a boolean. 124 * 125 * @param pd 126 * The boolean property definition. 127 * @param v 128 * The property value to visit. 129 * @param p 130 * A visitor specified parameter. 131 * @return Returns a visitor specified result. 132 */ 133 public R visitBoolean(BooleanPropertyDefinition pd, Boolean v, P p) { 134 return visitUnknown(pd, v, p); 135 } 136 137 138 139 /** 140 * Visit a class. 141 * 142 * @param pd 143 * The class property definition. 144 * @param v 145 * The property value to visit. 146 * @param p 147 * A visitor specified parameter. 148 * @return Returns a visitor specified result. 149 */ 150 public R visitClass(ClassPropertyDefinition pd, String v, P p) { 151 return visitUnknown(pd, v, p); 152 } 153 154 155 156 /** 157 * Visit a DN. 158 * 159 * @param pd 160 * The DN property definition. 161 * @param v 162 * The property value to visit. 163 * @param p 164 * A visitor specified parameter. 165 * @return Returns a visitor specified result. 166 */ 167 public R visitDN(DNPropertyDefinition pd, DN v, P p) { 168 return visitUnknown(pd, v, p); 169 } 170 171 172 173 /** 174 * Visit a duration. 175 * 176 * @param pd 177 * The duration property definition. 178 * @param v 179 * The property value to visit. 180 * @param p 181 * A visitor specified parameter. 182 * @return Returns a visitor specified result. 183 */ 184 public R visitDuration(DurationPropertyDefinition pd, Long v, P p) { 185 return visitUnknown(pd, v, p); 186 } 187 188 189 190 /** 191 * Visit an enumeration. 192 * 193 * @param <E> 194 * The enumeration that should be used for values of the 195 * property definition. 196 * @param pd 197 * The enumeration property definition. 198 * @param v 199 * The property value to visit. 200 * @param p 201 * A visitor specified parameter. 202 * @return Returns a visitor specified result. 203 */ 204 public <E extends Enum<E>> 205 R visitEnum(EnumPropertyDefinition<E> pd, E v, P p) { 206 return visitUnknown(pd, v, p); 207 } 208 209 210 211 /** 212 * Visit an integer. 213 * 214 * @param pd 215 * The integer property definition. 216 * @param v 217 * The property value to visit. 218 * @param p 219 * A visitor specified parameter. 220 * @return Returns a visitor specified result. 221 */ 222 public R visitInteger(IntegerPropertyDefinition pd, Integer v, P p) { 223 return visitUnknown(pd, v, p); 224 } 225 226 227 228 /** 229 * Visit a IP address. 230 * 231 * @param pd 232 * The IP address property definition. 233 * @param v 234 * The property value to visit. 235 * @param p 236 * A visitor specified parameter. 237 * @return Returns a visitor specified result. 238 */ 239 public R visitIPAddress(IPAddressPropertyDefinition pd, InetAddress v, P p) { 240 return visitUnknown(pd, v, p); 241 } 242 243 244 245 /** 246 * Visit a IP address mask. 247 * 248 * @param pd 249 * The IP address mask property definition. 250 * @param v 251 * The property value to visit. 252 * @param p 253 * A visitor specified parameter. 254 * @return Returns a visitor specified result. 255 */ 256 public R visitIPAddressMask(IPAddressMaskPropertyDefinition pd, AddressMask v, 257 P p) { 258 return visitUnknown(pd, v, p); 259 } 260 261 262 /** 263 * Visit a size. 264 * 265 * @param pd 266 * The size property definition. 267 * @param v 268 * The property value to visit. 269 * @param p 270 * A visitor specified parameter. 271 * @return Returns a visitor specified result. 272 */ 273 public R visitSize(SizePropertyDefinition pd, Long v, P p) { 274 return visitUnknown(pd, v, p); 275 } 276 277 278 279 /** 280 * Visit a string. 281 * 282 * @param pd 283 * The string property definition. 284 * @param v 285 * The property value to visit. 286 * @param p 287 * A visitor specified parameter. 288 * @return Returns a visitor specified result. 289 */ 290 public R visitString(StringPropertyDefinition pd, String v, P p) { 291 return visitUnknown(pd, v, p); 292 } 293 294 295 296 /** 297 * Visit an unknown type of property value. Implementations of this 298 * method can provide default behavior for unknown types of 299 * property. 300 * <p> 301 * The default implementation of this method throws an 302 * {@link PropertyException}. Sub-classes can 303 * override this method with their own default behavior. 304 * 305 * @param <T> 306 * The type of property value to visit. 307 * @param pd 308 * The property definition. 309 * @param v 310 * The property value. 311 * @param p 312 * A visitor specified parameter. 313 * @return Returns a visitor specified result. 314 * @throws PropertyException 315 * Visitor implementations may optionally throw this 316 * exception. 317 */ 318 public <T> R visitUnknown(PropertyDefinition<T> pd, T v, P p) 319 throws PropertyException { 320 throw PropertyException.unknownPropertyDefinitionException(pd, p); 321 } 322 323}