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