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.DNPropertyDefinition; 042import org.forgerock.opendj.config.EnumPropertyDefinition; 043import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 044import org.forgerock.opendj.config.ManagedObjectDefinition; 045import org.forgerock.opendj.config.ManagedObjectOption; 046import org.forgerock.opendj.config.PropertyException; 047import org.forgerock.opendj.config.PropertyOption; 048import org.forgerock.opendj.config.PropertyProvider; 049import org.forgerock.opendj.config.server.ConfigurationChangeListener; 050import org.forgerock.opendj.config.server.ServerManagedObject; 051import org.forgerock.opendj.config.StringPropertyDefinition; 052import org.forgerock.opendj.config.Tag; 053import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 054import org.forgerock.opendj.ldap.DN; 055import org.forgerock.opendj.ldap.LdapException; 056import org.forgerock.opendj.server.config.client.SchemaBackendCfgClient; 057import org.forgerock.opendj.server.config.meta.BackendCfgDefn.WritabilityMode; 058import org.forgerock.opendj.server.config.server.BackendCfg; 059import org.forgerock.opendj.server.config.server.SchemaBackendCfg; 060 061 062 063/** 064 * An interface for querying the Schema Backend managed object 065 * definition meta information. 066 * <p> 067 * The Schema Backend provides access to the directory server schema 068 * information, including the attribute types, object classes, 069 * attribute syntaxes, matching rules, matching rule uses, DIT content 070 * rules, and DIT structure rules that it contains. 071 */ 072public final class SchemaBackendCfgDefn extends ManagedObjectDefinition<SchemaBackendCfgClient, SchemaBackendCfg> { 073 074 /** The singleton configuration definition instance. */ 075 private static final SchemaBackendCfgDefn INSTANCE = new SchemaBackendCfgDefn(); 076 077 078 079 /** The "java-class" property definition. */ 080 private static final ClassPropertyDefinition PD_JAVA_CLASS; 081 082 083 084 /** The "schema-entry-dn" property definition. */ 085 private static final DNPropertyDefinition PD_SCHEMA_ENTRY_DN; 086 087 088 089 /** The "show-all-attributes" property definition. */ 090 private static final BooleanPropertyDefinition PD_SHOW_ALL_ATTRIBUTES; 091 092 093 094 /** The "writability-mode" property definition. */ 095 private static final EnumPropertyDefinition<WritabilityMode> PD_WRITABILITY_MODE; 096 097 098 099 /** Build the "java-class" property definition. */ 100 static { 101 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 102 builder.setOption(PropertyOption.MANDATORY); 103 builder.setOption(PropertyOption.ADVANCED); 104 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 105 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.backends.SchemaBackend"); 106 builder.setDefaultBehaviorProvider(provider); 107 builder.addInstanceOf("org.opends.server.api.Backend"); 108 PD_JAVA_CLASS = builder.getInstance(); 109 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 110 } 111 112 113 114 /** Build the "schema-entry-dn" property definition. */ 115 static { 116 DNPropertyDefinition.Builder builder = DNPropertyDefinition.createBuilder(INSTANCE, "schema-entry-dn"); 117 builder.setOption(PropertyOption.MULTI_VALUED); 118 builder.setOption(PropertyOption.ADVANCED); 119 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "schema-entry-dn")); 120 DefaultBehaviorProvider<DN> provider = new DefinedDefaultBehaviorProvider<DN>("cn=schema"); 121 builder.setDefaultBehaviorProvider(provider); 122 PD_SCHEMA_ENTRY_DN = builder.getInstance(); 123 INSTANCE.registerPropertyDefinition(PD_SCHEMA_ENTRY_DN); 124 } 125 126 127 128 /** Build the "show-all-attributes" property definition. */ 129 static { 130 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "show-all-attributes"); 131 builder.setOption(PropertyOption.MANDATORY); 132 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "show-all-attributes")); 133 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>()); 134 PD_SHOW_ALL_ATTRIBUTES = builder.getInstance(); 135 INSTANCE.registerPropertyDefinition(PD_SHOW_ALL_ATTRIBUTES); 136 } 137 138 139 140 /** Build the "writability-mode" property definition. */ 141 static { 142 EnumPropertyDefinition.Builder<WritabilityMode> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "writability-mode"); 143 builder.setOption(PropertyOption.MANDATORY); 144 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "writability-mode")); 145 DefaultBehaviorProvider<WritabilityMode> provider = new DefinedDefaultBehaviorProvider<WritabilityMode>("enabled"); 146 builder.setDefaultBehaviorProvider(provider); 147 builder.setEnumClass(WritabilityMode.class); 148 PD_WRITABILITY_MODE = builder.getInstance(); 149 INSTANCE.registerPropertyDefinition(PD_WRITABILITY_MODE); 150 } 151 152 153 154 // Register the options associated with this managed object definition. 155 static { 156 INSTANCE.registerOption(ManagedObjectOption.ADVANCED); 157 } 158 159 160 161 // Register the tags associated with this managed object definition. 162 static { 163 INSTANCE.registerTag(Tag.valueOf("database")); 164 } 165 166 167 168 /** 169 * Get the Schema Backend configuration definition singleton. 170 * 171 * @return Returns the Schema Backend configuration definition 172 * singleton. 173 */ 174 public static SchemaBackendCfgDefn getInstance() { 175 return INSTANCE; 176 } 177 178 179 180 /** 181 * Private constructor. 182 */ 183 private SchemaBackendCfgDefn() { 184 super("schema-backend", BackendCfgDefn.getInstance()); 185 } 186 187 188 189 /** {@inheritDoc} */ 190 public SchemaBackendCfgClient createClientConfiguration( 191 ManagedObject<? extends SchemaBackendCfgClient> impl) { 192 return new SchemaBackendCfgClientImpl(impl); 193 } 194 195 196 197 /** {@inheritDoc} */ 198 public SchemaBackendCfg createServerConfiguration( 199 ServerManagedObject<? extends SchemaBackendCfg> impl) { 200 return new SchemaBackendCfgServerImpl(impl); 201 } 202 203 204 205 /** {@inheritDoc} */ 206 public Class<SchemaBackendCfg> getServerConfigurationClass() { 207 return SchemaBackendCfg.class; 208 } 209 210 211 212 /** 213 * Get the "backend-id" property definition. 214 * <p> 215 * Specifies a name to identify the associated backend. 216 * <p> 217 * The name must be unique among all backends in the server. The 218 * backend ID may not be altered after the backend is created in the 219 * server. 220 * 221 * @return Returns the "backend-id" property definition. 222 */ 223 public StringPropertyDefinition getBackendIdPropertyDefinition() { 224 return BackendCfgDefn.getInstance().getBackendIdPropertyDefinition(); 225 } 226 227 228 229 /** 230 * Get the "base-dn" property definition. 231 * <p> 232 * Specifies the base DN(s) for the data that the backend handles. 233 * <p> 234 * A single backend may be responsible for one or more base DNs. 235 * Note that no two backends may have the same base DN although one 236 * backend may have a base DN that is below a base DN provided by 237 * another backend (similar to the use of sub-suffixes in the Sun 238 * Java System Directory Server). If any of the base DNs is 239 * subordinate to a base DN for another backend, then all base DNs 240 * for that backend must be subordinate to that same base DN. 241 * 242 * @return Returns the "base-dn" property definition. 243 */ 244 public DNPropertyDefinition getBaseDNPropertyDefinition() { 245 return BackendCfgDefn.getInstance().getBaseDNPropertyDefinition(); 246 } 247 248 249 250 /** 251 * Get the "enabled" property definition. 252 * <p> 253 * Indicates whether the backend is enabled in the server. 254 * <p> 255 * If a backend is not enabled, then its contents are not accessible 256 * when processing operations. 257 * 258 * @return Returns the "enabled" property definition. 259 */ 260 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 261 return BackendCfgDefn.getInstance().getEnabledPropertyDefinition(); 262 } 263 264 265 266 /** 267 * Get the "java-class" property definition. 268 * <p> 269 * Specifies the fully-qualified name of the Java class that 270 * provides the backend implementation. 271 * 272 * @return Returns the "java-class" property definition. 273 */ 274 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 275 return PD_JAVA_CLASS; 276 } 277 278 279 280 /** 281 * Get the "schema-entry-dn" property definition. 282 * <p> 283 * Defines the base DNs of the subtrees in which the schema 284 * information is published in addition to the value included in the 285 * base-dn property. 286 * <p> 287 * The value provided in the base-dn property is the only one that 288 * appears in the subschemaSubentry operational attribute of the 289 * server's root DSE (which is necessary because that is a 290 * single-valued attribute) and as a virtual attribute in other 291 * entries. The schema-entry-dn attribute may be used to make the 292 * schema information available in other locations to accommodate 293 * certain client applications that have been hard-coded to expect 294 * the schema to reside in a specific location. 295 * 296 * @return Returns the "schema-entry-dn" property definition. 297 */ 298 public DNPropertyDefinition getSchemaEntryDNPropertyDefinition() { 299 return PD_SCHEMA_ENTRY_DN; 300 } 301 302 303 304 /** 305 * Get the "show-all-attributes" property definition. 306 * <p> 307 * Indicates whether to treat all attributes in the schema entry as 308 * if they were user attributes regardless of their configuration. 309 * <p> 310 * This may provide compatibility with some applications that expect 311 * schema attributes like attributeTypes and objectClasses to be 312 * included by default even if they are not requested. Note that the 313 * ldapSyntaxes attribute is always treated as operational in order 314 * to avoid problems with attempts to modify the schema over 315 * protocol. 316 * 317 * @return Returns the "show-all-attributes" property definition. 318 */ 319 public BooleanPropertyDefinition getShowAllAttributesPropertyDefinition() { 320 return PD_SHOW_ALL_ATTRIBUTES; 321 } 322 323 324 325 /** 326 * Get the "writability-mode" property definition. 327 * <p> 328 * Specifies the behavior that the backend should use when 329 * processing write operations. 330 * 331 * @return Returns the "writability-mode" property definition. 332 */ 333 public EnumPropertyDefinition<WritabilityMode> getWritabilityModePropertyDefinition() { 334 return PD_WRITABILITY_MODE; 335 } 336 337 338 339 /** 340 * Managed object client implementation. 341 */ 342 private static class SchemaBackendCfgClientImpl implements 343 SchemaBackendCfgClient { 344 345 /** Private implementation. */ 346 private ManagedObject<? extends SchemaBackendCfgClient> impl; 347 348 349 350 /** Private constructor. */ 351 private SchemaBackendCfgClientImpl( 352 ManagedObject<? extends SchemaBackendCfgClient> impl) { 353 this.impl = impl; 354 } 355 356 357 358 /** {@inheritDoc} */ 359 public String getBackendId() { 360 return impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition()); 361 } 362 363 364 365 /** {@inheritDoc} */ 366 public void setBackendId(String value) throws PropertyException { 367 impl.setPropertyValue(INSTANCE.getBackendIdPropertyDefinition(), value); 368 } 369 370 371 372 /** {@inheritDoc} */ 373 public SortedSet<DN> getBaseDN() { 374 return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition()); 375 } 376 377 378 379 /** {@inheritDoc} */ 380 public void setBaseDN(Collection<DN> values) { 381 impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values); 382 } 383 384 385 386 /** {@inheritDoc} */ 387 public Boolean isEnabled() { 388 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 389 } 390 391 392 393 /** {@inheritDoc} */ 394 public void setEnabled(boolean value) { 395 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 396 } 397 398 399 400 /** {@inheritDoc} */ 401 public String getJavaClass() { 402 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 403 } 404 405 406 407 /** {@inheritDoc} */ 408 public void setJavaClass(String value) { 409 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 410 } 411 412 413 414 /** {@inheritDoc} */ 415 public SortedSet<DN> getSchemaEntryDN() { 416 return impl.getPropertyValues(INSTANCE.getSchemaEntryDNPropertyDefinition()); 417 } 418 419 420 421 /** {@inheritDoc} */ 422 public void setSchemaEntryDN(Collection<DN> values) { 423 impl.setPropertyValues(INSTANCE.getSchemaEntryDNPropertyDefinition(), values); 424 } 425 426 427 428 /** {@inheritDoc} */ 429 public Boolean isShowAllAttributes() { 430 return impl.getPropertyValue(INSTANCE.getShowAllAttributesPropertyDefinition()); 431 } 432 433 434 435 /** {@inheritDoc} */ 436 public void setShowAllAttributes(boolean value) { 437 impl.setPropertyValue(INSTANCE.getShowAllAttributesPropertyDefinition(), value); 438 } 439 440 441 442 /** {@inheritDoc} */ 443 public WritabilityMode getWritabilityMode() { 444 return impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition()); 445 } 446 447 448 449 /** {@inheritDoc} */ 450 public void setWritabilityMode(WritabilityMode value) { 451 impl.setPropertyValue(INSTANCE.getWritabilityModePropertyDefinition(), value); 452 } 453 454 455 456 /** {@inheritDoc} */ 457 public ManagedObjectDefinition<? extends SchemaBackendCfgClient, ? extends SchemaBackendCfg> definition() { 458 return INSTANCE; 459 } 460 461 462 463 /** {@inheritDoc} */ 464 public PropertyProvider properties() { 465 return impl; 466 } 467 468 469 470 /** {@inheritDoc} */ 471 public void commit() throws ManagedObjectAlreadyExistsException, 472 MissingMandatoryPropertiesException, ConcurrentModificationException, 473 OperationRejectedException, LdapException { 474 impl.commit(); 475 } 476 477 478 479 /** {@inheritDoc} */ 480 public String toString() { 481 return impl.toString(); 482 } 483 } 484 485 486 487 /** 488 * Managed object server implementation. 489 */ 490 private static class SchemaBackendCfgServerImpl implements 491 SchemaBackendCfg { 492 493 /** Private implementation. */ 494 private ServerManagedObject<? extends SchemaBackendCfg> impl; 495 496 /** The value of the "backend-id" property. */ 497 private final String pBackendId; 498 499 /** The value of the "base-dn" property. */ 500 private final SortedSet<DN> pBaseDN; 501 502 /** The value of the "enabled" property. */ 503 private final boolean pEnabled; 504 505 /** The value of the "java-class" property. */ 506 private final String pJavaClass; 507 508 /** The value of the "schema-entry-dn" property. */ 509 private final SortedSet<DN> pSchemaEntryDN; 510 511 /** The value of the "show-all-attributes" property. */ 512 private final boolean pShowAllAttributes; 513 514 /** The value of the "writability-mode" property. */ 515 private final WritabilityMode pWritabilityMode; 516 517 518 519 /** Private constructor. */ 520 private SchemaBackendCfgServerImpl(ServerManagedObject<? extends SchemaBackendCfg> impl) { 521 this.impl = impl; 522 this.pBackendId = impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition()); 523 this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition()); 524 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 525 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 526 this.pSchemaEntryDN = impl.getPropertyValues(INSTANCE.getSchemaEntryDNPropertyDefinition()); 527 this.pShowAllAttributes = impl.getPropertyValue(INSTANCE.getShowAllAttributesPropertyDefinition()); 528 this.pWritabilityMode = impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition()); 529 } 530 531 532 533 /** {@inheritDoc} */ 534 public void addSchemaChangeListener( 535 ConfigurationChangeListener<SchemaBackendCfg> listener) { 536 impl.registerChangeListener(listener); 537 } 538 539 540 541 /** {@inheritDoc} */ 542 public void removeSchemaChangeListener( 543 ConfigurationChangeListener<SchemaBackendCfg> listener) { 544 impl.deregisterChangeListener(listener); 545 } 546 /** {@inheritDoc} */ 547 public void addChangeListener( 548 ConfigurationChangeListener<BackendCfg> listener) { 549 impl.registerChangeListener(listener); 550 } 551 552 553 554 /** {@inheritDoc} */ 555 public void removeChangeListener( 556 ConfigurationChangeListener<BackendCfg> listener) { 557 impl.deregisterChangeListener(listener); 558 } 559 560 561 562 /** {@inheritDoc} */ 563 public String getBackendId() { 564 return pBackendId; 565 } 566 567 568 569 /** {@inheritDoc} */ 570 public SortedSet<DN> getBaseDN() { 571 return pBaseDN; 572 } 573 574 575 576 /** {@inheritDoc} */ 577 public boolean isEnabled() { 578 return pEnabled; 579 } 580 581 582 583 /** {@inheritDoc} */ 584 public String getJavaClass() { 585 return pJavaClass; 586 } 587 588 589 590 /** {@inheritDoc} */ 591 public SortedSet<DN> getSchemaEntryDN() { 592 return pSchemaEntryDN; 593 } 594 595 596 597 /** {@inheritDoc} */ 598 public boolean isShowAllAttributes() { 599 return pShowAllAttributes; 600 } 601 602 603 604 /** {@inheritDoc} */ 605 public WritabilityMode getWritabilityMode() { 606 return pWritabilityMode; 607 } 608 609 610 611 /** {@inheritDoc} */ 612 public Class<? extends SchemaBackendCfg> configurationClass() { 613 return SchemaBackendCfg.class; 614 } 615 616 617 618 /** {@inheritDoc} */ 619 public DN dn() { 620 return impl.getDN(); 621 } 622 623 624 625 /** {@inheritDoc} */ 626 public String toString() { 627 return impl.toString(); 628 } 629 } 630}