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