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