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