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 /** 138 * {@inheritDoc} 139 */ 140 public DirectoryStringAttributeSyntaxCfgClient createClientConfiguration( 141 ManagedObject<? extends DirectoryStringAttributeSyntaxCfgClient> impl) { 142 return new DirectoryStringAttributeSyntaxCfgClientImpl(impl); 143 } 144 145 146 147 /** 148 * {@inheritDoc} 149 */ 150 public DirectoryStringAttributeSyntaxCfg createServerConfiguration( 151 ServerManagedObject<? extends DirectoryStringAttributeSyntaxCfg> impl) { 152 return new DirectoryStringAttributeSyntaxCfgServerImpl(impl); 153 } 154 155 156 157 /** 158 * {@inheritDoc} 159 */ 160 public Class<DirectoryStringAttributeSyntaxCfg> getServerConfigurationClass() { 161 return DirectoryStringAttributeSyntaxCfg.class; 162 } 163 164 165 166 /** 167 * Get the "allow-zero-length-values" property definition. 168 * <p> 169 * Indicates whether zero-length (that is, an empty string) values 170 * are allowed. 171 * <p> 172 * This is technically not allowed by the revised LDAPv3 173 * specification, but some environments may require it for backward 174 * compatibility with servers that do allow it. 175 * 176 * @return Returns the "allow-zero-length-values" property definition. 177 */ 178 public BooleanPropertyDefinition getAllowZeroLengthValuesPropertyDefinition() { 179 return PD_ALLOW_ZERO_LENGTH_VALUES; 180 } 181 182 183 184 /** 185 * Get the "enabled" property definition. 186 * <p> 187 * Indicates whether the Directory String Attribute Syntax is 188 * enabled. 189 * 190 * @return Returns the "enabled" property definition. 191 */ 192 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 193 return AttributeSyntaxCfgDefn.getInstance().getEnabledPropertyDefinition(); 194 } 195 196 197 198 /** 199 * Get the "java-class" property definition. 200 * <p> 201 * Specifies the fully-qualified name of the Java class that 202 * provides the Directory String Attribute Syntax implementation. 203 * 204 * @return Returns the "java-class" property definition. 205 */ 206 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 207 return PD_JAVA_CLASS; 208 } 209 210 211 212 /** 213 * Managed object client implementation. 214 */ 215 private static class DirectoryStringAttributeSyntaxCfgClientImpl implements 216 DirectoryStringAttributeSyntaxCfgClient { 217 218 // Private implementation. 219 private ManagedObject<? extends DirectoryStringAttributeSyntaxCfgClient> impl; 220 221 222 223 // Private constructor. 224 private DirectoryStringAttributeSyntaxCfgClientImpl( 225 ManagedObject<? extends DirectoryStringAttributeSyntaxCfgClient> impl) { 226 this.impl = impl; 227 } 228 229 230 231 /** 232 * {@inheritDoc} 233 */ 234 public boolean isAllowZeroLengthValues() { 235 return impl.getPropertyValue(INSTANCE.getAllowZeroLengthValuesPropertyDefinition()); 236 } 237 238 239 240 /** 241 * {@inheritDoc} 242 */ 243 public void setAllowZeroLengthValues(Boolean value) { 244 impl.setPropertyValue(INSTANCE.getAllowZeroLengthValuesPropertyDefinition(), value); 245 } 246 247 248 249 /** 250 * {@inheritDoc} 251 */ 252 public Boolean isEnabled() { 253 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 254 } 255 256 257 258 /** 259 * {@inheritDoc} 260 */ 261 public void setEnabled(boolean value) { 262 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 263 } 264 265 266 267 /** 268 * {@inheritDoc} 269 */ 270 public String getJavaClass() { 271 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 272 } 273 274 275 276 /** 277 * {@inheritDoc} 278 */ 279 public void setJavaClass(String value) throws PropertyException { 280 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 281 } 282 283 284 285 /** 286 * {@inheritDoc} 287 */ 288 public ManagedObjectDefinition<? extends DirectoryStringAttributeSyntaxCfgClient, ? extends DirectoryStringAttributeSyntaxCfg> definition() { 289 return INSTANCE; 290 } 291 292 293 294 /** 295 * {@inheritDoc} 296 */ 297 public PropertyProvider properties() { 298 return impl; 299 } 300 301 302 303 /** 304 * {@inheritDoc} 305 */ 306 public void commit() throws ManagedObjectAlreadyExistsException, 307 MissingMandatoryPropertiesException, ConcurrentModificationException, 308 OperationRejectedException, LdapException { 309 impl.commit(); 310 } 311 312 } 313 314 315 316 /** 317 * Managed object server implementation. 318 */ 319 private static class DirectoryStringAttributeSyntaxCfgServerImpl implements 320 DirectoryStringAttributeSyntaxCfg { 321 322 // Private implementation. 323 private ServerManagedObject<? extends DirectoryStringAttributeSyntaxCfg> impl; 324 325 // The value of the "allow-zero-length-values" property. 326 private final boolean pAllowZeroLengthValues; 327 328 // The value of the "enabled" property. 329 private final boolean pEnabled; 330 331 // The value of the "java-class" property. 332 private final String pJavaClass; 333 334 335 336 // Private constructor. 337 private DirectoryStringAttributeSyntaxCfgServerImpl(ServerManagedObject<? extends DirectoryStringAttributeSyntaxCfg> impl) { 338 this.impl = impl; 339 this.pAllowZeroLengthValues = impl.getPropertyValue(INSTANCE.getAllowZeroLengthValuesPropertyDefinition()); 340 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 341 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 342 } 343 344 345 346 /** 347 * {@inheritDoc} 348 */ 349 public void addDirectoryStringChangeListener( 350 ConfigurationChangeListener<DirectoryStringAttributeSyntaxCfg> listener) { 351 impl.registerChangeListener(listener); 352 } 353 354 355 356 /** 357 * {@inheritDoc} 358 */ 359 public void removeDirectoryStringChangeListener( 360 ConfigurationChangeListener<DirectoryStringAttributeSyntaxCfg> listener) { 361 impl.deregisterChangeListener(listener); 362 } 363 /** 364 * {@inheritDoc} 365 */ 366 public void addChangeListener( 367 ConfigurationChangeListener<AttributeSyntaxCfg> listener) { 368 impl.registerChangeListener(listener); 369 } 370 371 372 373 /** 374 * {@inheritDoc} 375 */ 376 public void removeChangeListener( 377 ConfigurationChangeListener<AttributeSyntaxCfg> listener) { 378 impl.deregisterChangeListener(listener); 379 } 380 381 382 383 /** 384 * {@inheritDoc} 385 */ 386 public boolean isAllowZeroLengthValues() { 387 return pAllowZeroLengthValues; 388 } 389 390 391 392 /** 393 * {@inheritDoc} 394 */ 395 public boolean isEnabled() { 396 return pEnabled; 397 } 398 399 400 401 /** 402 * {@inheritDoc} 403 */ 404 public String getJavaClass() { 405 return pJavaClass; 406 } 407 408 409 410 /** 411 * {@inheritDoc} 412 */ 413 public Class<? extends DirectoryStringAttributeSyntaxCfg> configurationClass() { 414 return DirectoryStringAttributeSyntaxCfg.class; 415 } 416 417 418 419 /** 420 * {@inheritDoc} 421 */ 422 public DN dn() { 423 return impl.getDN(); 424 } 425 426 } 427}