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