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