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