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