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 java.util.Collection; 031import java.util.SortedSet; 032import org.forgerock.opendj.config.AdministratorAction; 033import org.forgerock.opendj.config.BooleanPropertyDefinition; 034import org.forgerock.opendj.config.ClassPropertyDefinition; 035import org.forgerock.opendj.config.client.ConcurrentModificationException; 036import org.forgerock.opendj.config.client.ManagedObject; 037import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 038import org.forgerock.opendj.config.client.OperationRejectedException; 039import org.forgerock.opendj.config.DefaultBehaviorProvider; 040import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 041import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 042import org.forgerock.opendj.config.ManagedObjectDefinition; 043import org.forgerock.opendj.config.PropertyOption; 044import org.forgerock.opendj.config.PropertyProvider; 045import org.forgerock.opendj.config.server.ConfigurationChangeListener; 046import org.forgerock.opendj.config.server.ServerManagedObject; 047import org.forgerock.opendj.config.StringPropertyDefinition; 048import org.forgerock.opendj.ldap.DN; 049import org.forgerock.opendj.ldap.LdapException; 050import org.forgerock.opendj.server.config.client.CoreSchemaCfgClient; 051import org.forgerock.opendj.server.config.server.CoreSchemaCfg; 052import org.forgerock.opendj.server.config.server.SchemaProviderCfg; 053 054 055 056/** 057 * An interface for querying the Core Schema managed object definition 058 * meta information. 059 * <p> 060 * Core Schema define the core schema elements to load. 061 */ 062public final class CoreSchemaCfgDefn extends ManagedObjectDefinition<CoreSchemaCfgClient, CoreSchemaCfg> { 063 064 /** The singleton configuration definition instance. */ 065 private static final CoreSchemaCfgDefn INSTANCE = new CoreSchemaCfgDefn(); 066 067 068 069 /** The "allow-zero-length-values-directory-string" property definition. */ 070 private static final BooleanPropertyDefinition PD_ALLOW_ZERO_LENGTH_VALUES_DIRECTORY_STRING; 071 072 073 074 /** The "disabled-matching-rule" property definition. */ 075 private static final StringPropertyDefinition PD_DISABLED_MATCHING_RULE; 076 077 078 079 /** The "disabled-syntax" property definition. */ 080 private static final StringPropertyDefinition PD_DISABLED_SYNTAX; 081 082 083 084 /** The "java-class" property definition. */ 085 private static final ClassPropertyDefinition PD_JAVA_CLASS; 086 087 088 089 /** The "strict-format-country-string" property definition. */ 090 private static final BooleanPropertyDefinition PD_STRICT_FORMAT_COUNTRY_STRING; 091 092 093 094 /** The "strip-syntax-min-upper-bound-attribute-type-description" property definition. */ 095 private static final BooleanPropertyDefinition PD_STRIP_SYNTAX_MIN_UPPER_BOUND_ATTRIBUTE_TYPE_DESCRIPTION; 096 097 098 099 /** Build the "allow-zero-length-values-directory-string" property definition. */ 100 static { 101 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "allow-zero-length-values-directory-string"); 102 builder.setOption(PropertyOption.ADVANCED); 103 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "allow-zero-length-values-directory-string")); 104 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false"); 105 builder.setDefaultBehaviorProvider(provider); 106 PD_ALLOW_ZERO_LENGTH_VALUES_DIRECTORY_STRING = builder.getInstance(); 107 INSTANCE.registerPropertyDefinition(PD_ALLOW_ZERO_LENGTH_VALUES_DIRECTORY_STRING); 108 } 109 110 111 112 /** Build the "disabled-matching-rule" property definition. */ 113 static { 114 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "disabled-matching-rule"); 115 builder.setOption(PropertyOption.MULTI_VALUED); 116 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "disabled-matching-rule")); 117 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("NONE"); 118 builder.setDefaultBehaviorProvider(provider); 119 builder.setPattern("^([0-9.]+\\d|NONE)$", "OID"); 120 PD_DISABLED_MATCHING_RULE = builder.getInstance(); 121 INSTANCE.registerPropertyDefinition(PD_DISABLED_MATCHING_RULE); 122 } 123 124 125 126 /** Build the "disabled-syntax" property definition. */ 127 static { 128 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "disabled-syntax"); 129 builder.setOption(PropertyOption.MULTI_VALUED); 130 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "disabled-syntax")); 131 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("NONE"); 132 builder.setDefaultBehaviorProvider(provider); 133 builder.setPattern("^([0-9.]+\\d|NONE)$", "OID"); 134 PD_DISABLED_SYNTAX = builder.getInstance(); 135 INSTANCE.registerPropertyDefinition(PD_DISABLED_SYNTAX); 136 } 137 138 139 140 /** Build the "java-class" property definition. */ 141 static { 142 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 143 builder.setOption(PropertyOption.MANDATORY); 144 builder.setOption(PropertyOption.ADVANCED); 145 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 146 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.schema.CoreSchemaProvider"); 147 builder.setDefaultBehaviorProvider(provider); 148 builder.addInstanceOf("org.opends.server.schema.SchemaProvider"); 149 PD_JAVA_CLASS = builder.getInstance(); 150 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 151 } 152 153 154 155 /** Build the "strict-format-country-string" property definition. */ 156 static { 157 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "strict-format-country-string"); 158 builder.setOption(PropertyOption.ADVANCED); 159 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "strict-format-country-string")); 160 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("true"); 161 builder.setDefaultBehaviorProvider(provider); 162 PD_STRICT_FORMAT_COUNTRY_STRING = builder.getInstance(); 163 INSTANCE.registerPropertyDefinition(PD_STRICT_FORMAT_COUNTRY_STRING); 164 } 165 166 167 168 /** Build the "strip-syntax-min-upper-bound-attribute-type-description" property definition. */ 169 static { 170 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "strip-syntax-min-upper-bound-attribute-type-description"); 171 builder.setOption(PropertyOption.ADVANCED); 172 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "strip-syntax-min-upper-bound-attribute-type-description")); 173 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false"); 174 builder.setDefaultBehaviorProvider(provider); 175 PD_STRIP_SYNTAX_MIN_UPPER_BOUND_ATTRIBUTE_TYPE_DESCRIPTION = builder.getInstance(); 176 INSTANCE.registerPropertyDefinition(PD_STRIP_SYNTAX_MIN_UPPER_BOUND_ATTRIBUTE_TYPE_DESCRIPTION); 177 } 178 179 180 181 /** 182 * Get the Core Schema configuration definition singleton. 183 * 184 * @return Returns the Core Schema configuration definition 185 * singleton. 186 */ 187 public static CoreSchemaCfgDefn getInstance() { 188 return INSTANCE; 189 } 190 191 192 193 /** 194 * Private constructor. 195 */ 196 private CoreSchemaCfgDefn() { 197 super("core-schema", SchemaProviderCfgDefn.getInstance()); 198 } 199 200 201 202 /** {@inheritDoc} */ 203 public CoreSchemaCfgClient createClientConfiguration( 204 ManagedObject<? extends CoreSchemaCfgClient> impl) { 205 return new CoreSchemaCfgClientImpl(impl); 206 } 207 208 209 210 /** {@inheritDoc} */ 211 public CoreSchemaCfg createServerConfiguration( 212 ServerManagedObject<? extends CoreSchemaCfg> impl) { 213 return new CoreSchemaCfgServerImpl(impl); 214 } 215 216 217 218 /** {@inheritDoc} */ 219 public Class<CoreSchemaCfg> getServerConfigurationClass() { 220 return CoreSchemaCfg.class; 221 } 222 223 224 225 /** 226 * Get the "allow-zero-length-values-directory-string" property definition. 227 * <p> 228 * Indicates whether zero-length (that is, an empty string) values 229 * are allowed for directory string. 230 * <p> 231 * This is technically not allowed by the revised LDAPv3 232 * specification, but some environments may require it for backward 233 * compatibility with servers that do allow it. 234 * 235 * @return Returns the "allow-zero-length-values-directory-string" property definition. 236 */ 237 public BooleanPropertyDefinition getAllowZeroLengthValuesDirectoryStringPropertyDefinition() { 238 return PD_ALLOW_ZERO_LENGTH_VALUES_DIRECTORY_STRING; 239 } 240 241 242 243 /** 244 * Get the "disabled-matching-rule" property definition. 245 * <p> 246 * The set of disabled matching rules. 247 * <p> 248 * Matching rules must be specified using the syntax: OID, or use 249 * the default value 'NONE' to specify no value. 250 * 251 * @return Returns the "disabled-matching-rule" property definition. 252 */ 253 public StringPropertyDefinition getDisabledMatchingRulePropertyDefinition() { 254 return PD_DISABLED_MATCHING_RULE; 255 } 256 257 258 259 /** 260 * Get the "disabled-syntax" property definition. 261 * <p> 262 * The set of disabled syntaxes. 263 * <p> 264 * Syntaxes must be specified using the syntax: OID, or use the 265 * default value 'NONE' to specify no value. 266 * 267 * @return Returns the "disabled-syntax" property definition. 268 */ 269 public StringPropertyDefinition getDisabledSyntaxPropertyDefinition() { 270 return PD_DISABLED_SYNTAX; 271 } 272 273 274 275 /** 276 * Get the "enabled" property definition. 277 * <p> 278 * Indicates whether the Core Schema is enabled for use. 279 * 280 * @return Returns the "enabled" property definition. 281 */ 282 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 283 return SchemaProviderCfgDefn.getInstance().getEnabledPropertyDefinition(); 284 } 285 286 287 288 /** 289 * Get the "java-class" property definition. 290 * <p> 291 * Specifies the fully-qualified name of the Java class that 292 * provides the Core Schema implementation. 293 * 294 * @return Returns the "java-class" property definition. 295 */ 296 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 297 return PD_JAVA_CLASS; 298 } 299 300 301 302 /** 303 * Get the "strict-format-country-string" property definition. 304 * <p> 305 * Indicates whether or not country code values are required to 306 * strictly comply with the standard definition for this syntax. 307 * <p> 308 * When set to false, country codes will not be validated and, as a 309 * result any string containing 2 characters will be acceptable. 310 * 311 * @return Returns the "strict-format-country-string" property definition. 312 */ 313 public BooleanPropertyDefinition getStrictFormatCountryStringPropertyDefinition() { 314 return PD_STRICT_FORMAT_COUNTRY_STRING; 315 } 316 317 318 319 /** 320 * Get the "strip-syntax-min-upper-bound-attribute-type-description" property definition. 321 * <p> 322 * Indicates whether the suggested minimum upper bound appended to 323 * an attribute's syntax OID in it's schema definition Attribute Type 324 * Description is stripped off. 325 * <p> 326 * When retrieving the server's schema, some APIs (JNDI) fail in 327 * their syntax lookup methods, because they do not parse this value 328 * correctly. This configuration option allows the server to be 329 * configured to provide schema definitions these APIs can parse 330 * correctly. 331 * 332 * @return Returns the "strip-syntax-min-upper-bound-attribute-type-description" property definition. 333 */ 334 public BooleanPropertyDefinition getStripSyntaxMinUpperBoundAttributeTypeDescriptionPropertyDefinition() { 335 return PD_STRIP_SYNTAX_MIN_UPPER_BOUND_ATTRIBUTE_TYPE_DESCRIPTION; 336 } 337 338 339 340 /** 341 * Managed object client implementation. 342 */ 343 private static class CoreSchemaCfgClientImpl implements 344 CoreSchemaCfgClient { 345 346 /** Private implementation. */ 347 private ManagedObject<? extends CoreSchemaCfgClient> impl; 348 349 350 351 /** Private constructor. */ 352 private CoreSchemaCfgClientImpl( 353 ManagedObject<? extends CoreSchemaCfgClient> impl) { 354 this.impl = impl; 355 } 356 357 358 359 /** {@inheritDoc} */ 360 public boolean isAllowZeroLengthValuesDirectoryString() { 361 return impl.getPropertyValue(INSTANCE.getAllowZeroLengthValuesDirectoryStringPropertyDefinition()); 362 } 363 364 365 366 /** {@inheritDoc} */ 367 public void setAllowZeroLengthValuesDirectoryString(Boolean value) { 368 impl.setPropertyValue(INSTANCE.getAllowZeroLengthValuesDirectoryStringPropertyDefinition(), value); 369 } 370 371 372 373 /** {@inheritDoc} */ 374 public SortedSet<String> getDisabledMatchingRule() { 375 return impl.getPropertyValues(INSTANCE.getDisabledMatchingRulePropertyDefinition()); 376 } 377 378 379 380 /** {@inheritDoc} */ 381 public void setDisabledMatchingRule(Collection<String> values) { 382 impl.setPropertyValues(INSTANCE.getDisabledMatchingRulePropertyDefinition(), values); 383 } 384 385 386 387 /** {@inheritDoc} */ 388 public SortedSet<String> getDisabledSyntax() { 389 return impl.getPropertyValues(INSTANCE.getDisabledSyntaxPropertyDefinition()); 390 } 391 392 393 394 /** {@inheritDoc} */ 395 public void setDisabledSyntax(Collection<String> values) { 396 impl.setPropertyValues(INSTANCE.getDisabledSyntaxPropertyDefinition(), values); 397 } 398 399 400 401 /** {@inheritDoc} */ 402 public Boolean isEnabled() { 403 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 404 } 405 406 407 408 /** {@inheritDoc} */ 409 public void setEnabled(boolean value) { 410 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 411 } 412 413 414 415 /** {@inheritDoc} */ 416 public String getJavaClass() { 417 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 418 } 419 420 421 422 /** {@inheritDoc} */ 423 public void setJavaClass(String value) { 424 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 425 } 426 427 428 429 /** {@inheritDoc} */ 430 public boolean isStrictFormatCountryString() { 431 return impl.getPropertyValue(INSTANCE.getStrictFormatCountryStringPropertyDefinition()); 432 } 433 434 435 436 /** {@inheritDoc} */ 437 public void setStrictFormatCountryString(Boolean value) { 438 impl.setPropertyValue(INSTANCE.getStrictFormatCountryStringPropertyDefinition(), value); 439 } 440 441 442 443 /** {@inheritDoc} */ 444 public boolean isStripSyntaxMinUpperBoundAttributeTypeDescription() { 445 return impl.getPropertyValue(INSTANCE.getStripSyntaxMinUpperBoundAttributeTypeDescriptionPropertyDefinition()); 446 } 447 448 449 450 /** {@inheritDoc} */ 451 public void setStripSyntaxMinUpperBoundAttributeTypeDescription(Boolean value) { 452 impl.setPropertyValue(INSTANCE.getStripSyntaxMinUpperBoundAttributeTypeDescriptionPropertyDefinition(), value); 453 } 454 455 456 457 /** {@inheritDoc} */ 458 public ManagedObjectDefinition<? extends CoreSchemaCfgClient, ? extends CoreSchemaCfg> definition() { 459 return INSTANCE; 460 } 461 462 463 464 /** {@inheritDoc} */ 465 public PropertyProvider properties() { 466 return impl; 467 } 468 469 470 471 /** {@inheritDoc} */ 472 public void commit() throws ManagedObjectAlreadyExistsException, 473 MissingMandatoryPropertiesException, ConcurrentModificationException, 474 OperationRejectedException, LdapException { 475 impl.commit(); 476 } 477 478 479 480 /** {@inheritDoc} */ 481 public String toString() { 482 return impl.toString(); 483 } 484 } 485 486 487 488 /** 489 * Managed object server implementation. 490 */ 491 private static class CoreSchemaCfgServerImpl implements 492 CoreSchemaCfg { 493 494 /** Private implementation. */ 495 private ServerManagedObject<? extends CoreSchemaCfg> impl; 496 497 /** The value of the "allow-zero-length-values-directory-string" property. */ 498 private final boolean pAllowZeroLengthValuesDirectoryString; 499 500 /** The value of the "disabled-matching-rule" property. */ 501 private final SortedSet<String> pDisabledMatchingRule; 502 503 /** The value of the "disabled-syntax" property. */ 504 private final SortedSet<String> pDisabledSyntax; 505 506 /** The value of the "enabled" property. */ 507 private final boolean pEnabled; 508 509 /** The value of the "java-class" property. */ 510 private final String pJavaClass; 511 512 /** The value of the "strict-format-country-string" property. */ 513 private final boolean pStrictFormatCountryString; 514 515 /** The value of the "strip-syntax-min-upper-bound-attribute-type-description" property. */ 516 private final boolean pStripSyntaxMinUpperBoundAttributeTypeDescription; 517 518 519 520 /** Private constructor. */ 521 private CoreSchemaCfgServerImpl(ServerManagedObject<? extends CoreSchemaCfg> impl) { 522 this.impl = impl; 523 this.pAllowZeroLengthValuesDirectoryString = impl.getPropertyValue(INSTANCE.getAllowZeroLengthValuesDirectoryStringPropertyDefinition()); 524 this.pDisabledMatchingRule = impl.getPropertyValues(INSTANCE.getDisabledMatchingRulePropertyDefinition()); 525 this.pDisabledSyntax = impl.getPropertyValues(INSTANCE.getDisabledSyntaxPropertyDefinition()); 526 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 527 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 528 this.pStrictFormatCountryString = impl.getPropertyValue(INSTANCE.getStrictFormatCountryStringPropertyDefinition()); 529 this.pStripSyntaxMinUpperBoundAttributeTypeDescription = impl.getPropertyValue(INSTANCE.getStripSyntaxMinUpperBoundAttributeTypeDescriptionPropertyDefinition()); 530 } 531 532 533 534 /** {@inheritDoc} */ 535 public void addCoreSchemaChangeListener( 536 ConfigurationChangeListener<CoreSchemaCfg> listener) { 537 impl.registerChangeListener(listener); 538 } 539 540 541 542 /** {@inheritDoc} */ 543 public void removeCoreSchemaChangeListener( 544 ConfigurationChangeListener<CoreSchemaCfg> listener) { 545 impl.deregisterChangeListener(listener); 546 } 547 /** {@inheritDoc} */ 548 public void addChangeListener( 549 ConfigurationChangeListener<SchemaProviderCfg> listener) { 550 impl.registerChangeListener(listener); 551 } 552 553 554 555 /** {@inheritDoc} */ 556 public void removeChangeListener( 557 ConfigurationChangeListener<SchemaProviderCfg> listener) { 558 impl.deregisterChangeListener(listener); 559 } 560 561 562 563 /** {@inheritDoc} */ 564 public boolean isAllowZeroLengthValuesDirectoryString() { 565 return pAllowZeroLengthValuesDirectoryString; 566 } 567 568 569 570 /** {@inheritDoc} */ 571 public SortedSet<String> getDisabledMatchingRule() { 572 return pDisabledMatchingRule; 573 } 574 575 576 577 /** {@inheritDoc} */ 578 public SortedSet<String> getDisabledSyntax() { 579 return pDisabledSyntax; 580 } 581 582 583 584 /** {@inheritDoc} */ 585 public boolean isEnabled() { 586 return pEnabled; 587 } 588 589 590 591 /** {@inheritDoc} */ 592 public String getJavaClass() { 593 return pJavaClass; 594 } 595 596 597 598 /** {@inheritDoc} */ 599 public boolean isStrictFormatCountryString() { 600 return pStrictFormatCountryString; 601 } 602 603 604 605 /** {@inheritDoc} */ 606 public boolean isStripSyntaxMinUpperBoundAttributeTypeDescription() { 607 return pStripSyntaxMinUpperBoundAttributeTypeDescription; 608 } 609 610 611 612 /** {@inheritDoc} */ 613 public Class<? extends CoreSchemaCfg> configurationClass() { 614 return CoreSchemaCfg.class; 615 } 616 617 618 619 /** {@inheritDoc} */ 620 public DN dn() { 621 return impl.getDN(); 622 } 623 624 625 626 /** {@inheritDoc} */ 627 public String toString() { 628 return impl.toString(); 629 } 630 } 631}