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