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 Sun Microsystems, Inc. 025 */ 026package org.forgerock.opendj.server.config.meta; 027 028 029 030import org.forgerock.opendj.config.AdministratorAction; 031import org.forgerock.opendj.config.BooleanPropertyDefinition; 032import org.forgerock.opendj.config.ClassPropertyDefinition; 033import org.forgerock.opendj.config.client.ConcurrentModificationException; 034import org.forgerock.opendj.config.client.ManagedObject; 035import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 036import org.forgerock.opendj.config.client.OperationRejectedException; 037import org.forgerock.opendj.config.DefaultBehaviorProvider; 038import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 039import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 040import org.forgerock.opendj.config.ManagedObjectDefinition; 041import org.forgerock.opendj.config.PropertyException; 042import org.forgerock.opendj.config.PropertyOption; 043import org.forgerock.opendj.config.PropertyProvider; 044import org.forgerock.opendj.config.server.ConfigurationChangeListener; 045import org.forgerock.opendj.config.server.ServerManagedObject; 046import org.forgerock.opendj.config.Tag; 047import org.forgerock.opendj.ldap.DN; 048import org.forgerock.opendj.ldap.LdapException; 049import org.forgerock.opendj.server.config.client.DirectoryStringAttributeSyntaxCfgClient; 050import org.forgerock.opendj.server.config.server.AttributeSyntaxCfg; 051import org.forgerock.opendj.server.config.server.DirectoryStringAttributeSyntaxCfg; 052 053 054 055/** 056 * An interface for querying the Directory String Attribute Syntax 057 * managed object definition meta information. 058 * <p> 059 * The Directory String Attribute Syntax defines an attribute syntax 060 * for storing arbitrary string (and sometimes binary) data. 061 */ 062public final class DirectoryStringAttributeSyntaxCfgDefn extends ManagedObjectDefinition<DirectoryStringAttributeSyntaxCfgClient, DirectoryStringAttributeSyntaxCfg> { 063 064 /** The singleton configuration definition instance. */ 065 private static final DirectoryStringAttributeSyntaxCfgDefn INSTANCE = new DirectoryStringAttributeSyntaxCfgDefn(); 066 067 068 069 /** The "allow-zero-length-values" property definition. */ 070 private static final BooleanPropertyDefinition PD_ALLOW_ZERO_LENGTH_VALUES; 071 072 073 074 /** The "java-class" property definition. */ 075 private static final ClassPropertyDefinition PD_JAVA_CLASS; 076 077 078 079 /** Build the "allow-zero-length-values" property definition. */ 080 static { 081 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "allow-zero-length-values"); 082 builder.setOption(PropertyOption.ADVANCED); 083 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "allow-zero-length-values")); 084 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false"); 085 builder.setDefaultBehaviorProvider(provider); 086 PD_ALLOW_ZERO_LENGTH_VALUES = builder.getInstance(); 087 INSTANCE.registerPropertyDefinition(PD_ALLOW_ZERO_LENGTH_VALUES); 088 } 089 090 091 092 /** Build the "java-class" property definition. */ 093 static { 094 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 095 builder.setOption(PropertyOption.READ_ONLY); 096 builder.setOption(PropertyOption.MANDATORY); 097 builder.setOption(PropertyOption.ADVANCED); 098 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 099 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.schema.DirectoryStringSyntax"); 100 builder.setDefaultBehaviorProvider(provider); 101 builder.addInstanceOf("org.opends.server.api.AttributeSyntax"); 102 PD_JAVA_CLASS = builder.getInstance(); 103 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 104 } 105 106 107 108 // Register the tags associated with this managed object definition. 109 static { 110 INSTANCE.registerTag(Tag.valueOf("core-server")); 111 } 112 113 114 115 /** 116 * Get the Directory String Attribute Syntax configuration 117 * definition singleton. 118 * 119 * @return Returns the Directory String Attribute Syntax 120 * configuration definition singleton. 121 */ 122 public static DirectoryStringAttributeSyntaxCfgDefn getInstance() { 123 return INSTANCE; 124 } 125 126 127 128 /** 129 * Private constructor. 130 */ 131 private DirectoryStringAttributeSyntaxCfgDefn() { 132 super("directory-string-attribute-syntax", AttributeSyntaxCfgDefn.getInstance()); 133 } 134 135 136 137 /** {@inheritDoc} */ 138 public DirectoryStringAttributeSyntaxCfgClient createClientConfiguration( 139 ManagedObject<? extends DirectoryStringAttributeSyntaxCfgClient> impl) { 140 return new DirectoryStringAttributeSyntaxCfgClientImpl(impl); 141 } 142 143 144 145 /** {@inheritDoc} */ 146 public DirectoryStringAttributeSyntaxCfg createServerConfiguration( 147 ServerManagedObject<? extends DirectoryStringAttributeSyntaxCfg> impl) { 148 return new DirectoryStringAttributeSyntaxCfgServerImpl(impl); 149 } 150 151 152 153 /** {@inheritDoc} */ 154 public Class<DirectoryStringAttributeSyntaxCfg> getServerConfigurationClass() { 155 return DirectoryStringAttributeSyntaxCfg.class; 156 } 157 158 159 160 /** 161 * Get the "allow-zero-length-values" property definition. 162 * <p> 163 * Indicates whether zero-length (that is, an empty string) values 164 * are allowed. 165 * <p> 166 * This is technically not allowed by the revised LDAPv3 167 * specification, but some environments may require it for backward 168 * compatibility with servers that do allow it. 169 * 170 * @return Returns the "allow-zero-length-values" property definition. 171 */ 172 public BooleanPropertyDefinition getAllowZeroLengthValuesPropertyDefinition() { 173 return PD_ALLOW_ZERO_LENGTH_VALUES; 174 } 175 176 177 178 /** 179 * Get the "enabled" property definition. 180 * <p> 181 * Indicates whether the Directory String Attribute Syntax is 182 * enabled. 183 * 184 * @return Returns the "enabled" property definition. 185 */ 186 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 187 return AttributeSyntaxCfgDefn.getInstance().getEnabledPropertyDefinition(); 188 } 189 190 191 192 /** 193 * Get the "java-class" property definition. 194 * <p> 195 * Specifies the fully-qualified name of the Java class that 196 * provides the Directory String Attribute Syntax implementation. 197 * 198 * @return Returns the "java-class" property definition. 199 */ 200 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 201 return PD_JAVA_CLASS; 202 } 203 204 205 206 /** 207 * Managed object client implementation. 208 */ 209 private static class DirectoryStringAttributeSyntaxCfgClientImpl implements 210 DirectoryStringAttributeSyntaxCfgClient { 211 212 /** Private implementation. */ 213 private ManagedObject<? extends DirectoryStringAttributeSyntaxCfgClient> impl; 214 215 216 217 /** Private constructor. */ 218 private DirectoryStringAttributeSyntaxCfgClientImpl( 219 ManagedObject<? extends DirectoryStringAttributeSyntaxCfgClient> impl) { 220 this.impl = impl; 221 } 222 223 224 225 /** {@inheritDoc} */ 226 public boolean isAllowZeroLengthValues() { 227 return impl.getPropertyValue(INSTANCE.getAllowZeroLengthValuesPropertyDefinition()); 228 } 229 230 231 232 /** {@inheritDoc} */ 233 public void setAllowZeroLengthValues(Boolean value) { 234 impl.setPropertyValue(INSTANCE.getAllowZeroLengthValuesPropertyDefinition(), value); 235 } 236 237 238 239 /** {@inheritDoc} */ 240 public Boolean isEnabled() { 241 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 242 } 243 244 245 246 /** {@inheritDoc} */ 247 public void setEnabled(boolean value) { 248 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 249 } 250 251 252 253 /** {@inheritDoc} */ 254 public String getJavaClass() { 255 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 256 } 257 258 259 260 /** {@inheritDoc} */ 261 public void setJavaClass(String value) throws PropertyException { 262 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 263 } 264 265 266 267 /** {@inheritDoc} */ 268 public ManagedObjectDefinition<? extends DirectoryStringAttributeSyntaxCfgClient, ? extends DirectoryStringAttributeSyntaxCfg> definition() { 269 return INSTANCE; 270 } 271 272 273 274 /** {@inheritDoc} */ 275 public PropertyProvider properties() { 276 return impl; 277 } 278 279 280 281 /** {@inheritDoc} */ 282 public void commit() throws ManagedObjectAlreadyExistsException, 283 MissingMandatoryPropertiesException, ConcurrentModificationException, 284 OperationRejectedException, LdapException { 285 impl.commit(); 286 } 287 288 289 290 /** {@inheritDoc} */ 291 public String toString() { 292 return impl.toString(); 293 } 294 } 295 296 297 298 /** 299 * Managed object server implementation. 300 */ 301 private static class DirectoryStringAttributeSyntaxCfgServerImpl implements 302 DirectoryStringAttributeSyntaxCfg { 303 304 /** Private implementation. */ 305 private ServerManagedObject<? extends DirectoryStringAttributeSyntaxCfg> impl; 306 307 /** The value of the "allow-zero-length-values" property. */ 308 private final boolean pAllowZeroLengthValues; 309 310 /** The value of the "enabled" property. */ 311 private final boolean pEnabled; 312 313 /** The value of the "java-class" property. */ 314 private final String pJavaClass; 315 316 317 318 /** Private constructor. */ 319 private DirectoryStringAttributeSyntaxCfgServerImpl(ServerManagedObject<? extends DirectoryStringAttributeSyntaxCfg> impl) { 320 this.impl = impl; 321 this.pAllowZeroLengthValues = impl.getPropertyValue(INSTANCE.getAllowZeroLengthValuesPropertyDefinition()); 322 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 323 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 324 } 325 326 327 328 /** {@inheritDoc} */ 329 public void addDirectoryStringChangeListener( 330 ConfigurationChangeListener<DirectoryStringAttributeSyntaxCfg> listener) { 331 impl.registerChangeListener(listener); 332 } 333 334 335 336 /** {@inheritDoc} */ 337 public void removeDirectoryStringChangeListener( 338 ConfigurationChangeListener<DirectoryStringAttributeSyntaxCfg> listener) { 339 impl.deregisterChangeListener(listener); 340 } 341 /** {@inheritDoc} */ 342 public void addChangeListener( 343 ConfigurationChangeListener<AttributeSyntaxCfg> listener) { 344 impl.registerChangeListener(listener); 345 } 346 347 348 349 /** {@inheritDoc} */ 350 public void removeChangeListener( 351 ConfigurationChangeListener<AttributeSyntaxCfg> listener) { 352 impl.deregisterChangeListener(listener); 353 } 354 355 356 357 /** {@inheritDoc} */ 358 public boolean isAllowZeroLengthValues() { 359 return pAllowZeroLengthValues; 360 } 361 362 363 364 /** {@inheritDoc} */ 365 public boolean isEnabled() { 366 return pEnabled; 367 } 368 369 370 371 /** {@inheritDoc} */ 372 public String getJavaClass() { 373 return pJavaClass; 374 } 375 376 377 378 /** {@inheritDoc} */ 379 public Class<? extends DirectoryStringAttributeSyntaxCfg> configurationClass() { 380 return DirectoryStringAttributeSyntaxCfg.class; 381 } 382 383 384 385 /** {@inheritDoc} */ 386 public DN dn() { 387 return impl.getDN(); 388 } 389 390 391 392 /** {@inheritDoc} */ 393 public String toString() { 394 return impl.toString(); 395 } 396 } 397}