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 */
016
017package org.opends.server.admin;
018
019
020
021/**
022 * A visitor of property definitions, in the style of the visitor
023 * design pattern. Classes implementing this interface can query
024 * property definitions in a type-safe manner when the kind of
025 * property definition is unknown at compile time. When a visitor is
026 * passed to a property definition's accept method, the corresponding
027 * visit method most applicable to that property definition is
028 * invoked.
029 * <p>
030 * Each <code>visitXXX</code> method is provided with a default
031 * implementation which calls
032 * {@link #visitUnknown(PropertyDefinition, Object)}. Sub-classes can
033 * override any or all of the methods to provide their own
034 * type-specific behavior.
035 *
036 * @param <R>
037 *          The return type of this visitor's methods. Use
038 *          {@link java.lang.Void} for visitors that do not need to
039 *          return results.
040 * @param <P>
041 *          The type of the additional parameter to this visitor's
042 *          methods. Use {@link java.lang.Void} for visitors that do
043 *          not need an additional parameter.
044 */
045public abstract class PropertyDefinitionVisitor<R, P> {
046
047  /**
048   * Default constructor.
049   */
050  protected PropertyDefinitionVisitor() {
051    // No implementation required.
052  }
053
054
055
056  /**
057   * Visit a dseecompat Global ACI property definition.
058   *
059   * @param pd
060   *          The Global ACI property definition to visit.
061   * @param p
062   *          A visitor specified parameter.
063   * @return Returns a visitor specified result.
064   */
065  public R visitACI(ACIPropertyDefinition pd, P p) {
066    return visitUnknown(pd, p);
067  }
068
069
070
071  /**
072   * Visit an aggregation property definition.
073   *
074   * @param <C>
075   *          The type of client managed object configuration that
076   *          this aggregation property definition refers to.
077   * @param <S>
078   *          The type of server managed object configuration that
079   *          this aggregation property definition refers to.
080   * @param pd
081   *          The aggregation property definition to visit.
082   * @param p
083   *          A visitor specified parameter.
084   * @return Returns a visitor specified result.
085   */
086  public <C extends ConfigurationClient, S extends Configuration>
087  R visitAggregation(AggregationPropertyDefinition<C, S> pd, P p) {
088    return visitUnknown(pd, p);
089  }
090
091
092
093  /**
094   * Visit an attribute type property definition.
095   *
096   * @param pd
097   *          The attribute type property definition to visit.
098   * @param p
099   *          A visitor specified parameter.
100   * @return Returns a visitor specified result.
101   */
102  public R visitAttributeType(AttributeTypePropertyDefinition pd, P p) {
103    return visitUnknown(pd, p);
104  }
105
106
107
108  /**
109   * Visit a boolean property definition.
110   *
111   * @param pd
112   *          The boolean property definition to visit.
113   * @param p
114   *          A visitor specified parameter.
115   * @return Returns a visitor specified result.
116   */
117  public R visitBoolean(BooleanPropertyDefinition pd, P p) {
118    return visitUnknown(pd, p);
119  }
120
121
122
123  /**
124   * Visit a class property definition.
125   *
126   * @param pd
127   *          The class property definition to visit.
128   * @param p
129   *          A visitor specified parameter.
130   * @return Returns a visitor specified result.
131   */
132  public R visitClass(ClassPropertyDefinition pd, P p) {
133    return visitUnknown(pd, p);
134  }
135
136
137
138  /**
139   * Visit a DN property definition.
140   *
141   * @param pd
142   *          The DN property definition to visit.
143   * @param p
144   *          A visitor specified parameter.
145   * @return Returns a visitor specified result.
146   */
147  public R visitDN(DNPropertyDefinition pd, P p) {
148    return visitUnknown(pd, p);
149  }
150
151
152
153  /**
154   * Visit a duration property definition.
155   *
156   * @param pd
157   *          The duration property definition to visit.
158   * @param p
159   *          A visitor specified parameter.
160   * @return Returns a visitor specified result.
161   */
162  public R visitDuration(DurationPropertyDefinition pd, P p) {
163    return visitUnknown(pd, p);
164  }
165
166
167
168  /**
169   * Visit an enumeration property definition.
170   *
171   * @param <E>
172   *          The enumeration that should be used for values of the
173   *          property definition.
174   * @param pd
175   *          The enumeration property definition to visit.
176   * @param p
177   *          A visitor specified parameter.
178   * @return Returns a visitor specified result.
179   */
180  public <E extends Enum<E>> R visitEnum(EnumPropertyDefinition<E> pd, P p) {
181    return visitUnknown(pd, p);
182  }
183
184
185
186  /**
187   * Visit an integer property definition.
188   *
189   * @param pd
190   *          The integer property definition to visit.
191   * @param p
192   *          A visitor specified parameter.
193   * @return Returns a visitor specified result.
194   */
195  public R visitInteger(IntegerPropertyDefinition pd, P p) {
196    return visitUnknown(pd, p);
197  }
198
199
200
201  /**
202   * Visit a IP address property definition.
203   *
204   * @param pd
205   *          The IP address property definition to visit.
206   * @param p
207   *          A visitor specified parameter.
208   * @return Returns a visitor specified result.
209   */
210  public R visitIPAddress(IPAddressPropertyDefinition pd, P p) {
211    return visitUnknown(pd, p);
212  }
213
214
215
216  /**
217   * Visit a IP address mask property definition.
218   *
219   * @param pd
220   *          The IP address mask property definition to visit.
221   * @param p
222   *          A visitor specified parameter.
223   * @return Returns a visitor specified result.
224   */
225  public R visitIPAddressMask(IPAddressMaskPropertyDefinition pd, P p) {
226    return visitUnknown(pd, p);
227  }
228
229
230  /**
231   * Visit a size property definition.
232   *
233   * @param pd
234   *          The size property definition to visit.
235   * @param p
236   *          A visitor specified parameter.
237   * @return Returns a visitor specified result.
238   */
239  public R visitSize(SizePropertyDefinition pd, P p) {
240    return visitUnknown(pd, p);
241  }
242
243
244
245  /**
246   * Visit a string property definition.
247   *
248   * @param pd
249   *          The string property definition to visit.
250   * @param p
251   *          A visitor specified parameter.
252   * @return Returns a visitor specified result.
253   */
254  public R visitString(StringPropertyDefinition pd, P p) {
255    return visitUnknown(pd, p);
256  }
257
258
259
260
261  /**
262   * Visit an unknown type of property definition. Implementations of
263   * this method can provide default behavior for unknown property
264   * definition types.
265   * <p>
266   * The default implementation of this method throws an
267   * {@link PropertyException}. Sub-classes can
268   * override this method with their own default behavior.
269   *
270   * @param <T>
271   *          The type of the underlying property.
272   * @param pd
273   *          The property definition to visit.
274   * @param p
275   *          A visitor specified parameter.
276   * @return Returns a visitor specified result.
277   * @throws PropertyException
278   *           Visitor implementations may optionally throw this
279   *           exception.
280   */
281  public <T> R visitUnknown(PropertyDefinition<T> pd, P p)
282      throws PropertyException {
283    throw PropertyException.unknownPropertyDefinitionException(pd, p);
284  }
285
286}