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.PropertyException; 039import org.opends.server.admin.PropertyOption; 040import org.opends.server.admin.PropertyProvider; 041import org.opends.server.admin.server.ConfigurationChangeListener; 042import org.opends.server.admin.server.ServerManagedObject; 043import org.opends.server.admin.std.client.LDIFBackendCfgClient; 044import org.opends.server.admin.std.meta.BackendCfgDefn.WritabilityMode; 045import org.opends.server.admin.std.server.BackendCfg; 046import org.opends.server.admin.std.server.LDIFBackendCfg; 047import org.opends.server.admin.StringPropertyDefinition; 048import org.opends.server.admin.Tag; 049import org.opends.server.admin.UndefinedDefaultBehaviorProvider; 050 051 052 053/** 054 * An interface for querying the LDIF Backend managed object 055 * definition meta information. 056 * <p> 057 * The LDIF Backend provides a mechanism for interacting with data 058 * stored in an LDIF file. 059 */ 060public final class LDIFBackendCfgDefn extends ManagedObjectDefinition<LDIFBackendCfgClient, LDIFBackendCfg> { 061 062 // The singleton configuration definition instance. 063 private static final LDIFBackendCfgDefn INSTANCE = new LDIFBackendCfgDefn(); 064 065 066 067 // The "is-private-backend" property definition. 068 private static final BooleanPropertyDefinition PD_IS_PRIVATE_BACKEND; 069 070 071 072 // The "java-class" property definition. 073 private static final ClassPropertyDefinition PD_JAVA_CLASS; 074 075 076 077 // The "ldif-file" property definition. 078 private static final StringPropertyDefinition PD_LDIF_FILE; 079 080 081 082 // The "writability-mode" property definition. 083 private static final EnumPropertyDefinition<WritabilityMode> PD_WRITABILITY_MODE; 084 085 086 087 // Build the "is-private-backend" property definition. 088 static { 089 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "is-private-backend"); 090 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "is-private-backend")); 091 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false"); 092 builder.setDefaultBehaviorProvider(provider); 093 PD_IS_PRIVATE_BACKEND = builder.getInstance(); 094 INSTANCE.registerPropertyDefinition(PD_IS_PRIVATE_BACKEND); 095 } 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.LDIFBackend"); 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 "ldif-file" property definition. 115 static { 116 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "ldif-file"); 117 builder.setOption(PropertyOption.MANDATORY); 118 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "ldif-file")); 119 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 120 PD_LDIF_FILE = builder.getInstance(); 121 INSTANCE.registerPropertyDefinition(PD_LDIF_FILE); 122 } 123 124 125 126 // Build the "writability-mode" property definition. 127 static { 128 EnumPropertyDefinition.Builder<WritabilityMode> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "writability-mode"); 129 builder.setOption(PropertyOption.MANDATORY); 130 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "writability-mode")); 131 DefaultBehaviorProvider<WritabilityMode> provider = new DefinedDefaultBehaviorProvider<WritabilityMode>("enabled"); 132 builder.setDefaultBehaviorProvider(provider); 133 builder.setEnumClass(WritabilityMode.class); 134 PD_WRITABILITY_MODE = builder.getInstance(); 135 INSTANCE.registerPropertyDefinition(PD_WRITABILITY_MODE); 136 } 137 138 139 140 // Register the tags associated with this managed object definition. 141 static { 142 INSTANCE.registerTag(Tag.valueOf("database")); 143 } 144 145 146 147 /** 148 * Get the LDIF Backend configuration definition singleton. 149 * 150 * @return Returns the LDIF Backend configuration definition 151 * singleton. 152 */ 153 public static LDIFBackendCfgDefn getInstance() { 154 return INSTANCE; 155 } 156 157 158 159 /** 160 * Private constructor. 161 */ 162 private LDIFBackendCfgDefn() { 163 super("ldif-backend", BackendCfgDefn.getInstance()); 164 } 165 166 167 168 /** 169 * {@inheritDoc} 170 */ 171 public LDIFBackendCfgClient createClientConfiguration( 172 ManagedObject<? extends LDIFBackendCfgClient> impl) { 173 return new LDIFBackendCfgClientImpl(impl); 174 } 175 176 177 178 /** 179 * {@inheritDoc} 180 */ 181 public LDIFBackendCfg createServerConfiguration( 182 ServerManagedObject<? extends LDIFBackendCfg> impl) { 183 return new LDIFBackendCfgServerImpl(impl); 184 } 185 186 187 188 /** 189 * {@inheritDoc} 190 */ 191 public Class<LDIFBackendCfg> getServerConfigurationClass() { 192 return LDIFBackendCfg.class; 193 } 194 195 196 197 /** 198 * Get the "backend-id" property definition. 199 * <p> 200 * Specifies a name to identify the associated backend. 201 * <p> 202 * The name must be unique among all backends in the server. The 203 * backend ID may not be altered after the backend is created in the 204 * server. 205 * 206 * @return Returns the "backend-id" property definition. 207 */ 208 public StringPropertyDefinition getBackendIdPropertyDefinition() { 209 return BackendCfgDefn.getInstance().getBackendIdPropertyDefinition(); 210 } 211 212 213 214 /** 215 * Get the "base-dn" property definition. 216 * <p> 217 * Specifies the base DN(s) for the data that the backend handles. 218 * <p> 219 * A single backend may be responsible for one or more base DNs. 220 * Note that no two backends may have the same base DN although one 221 * backend may have a base DN that is below a base DN provided by 222 * another backend (similar to the use of sub-suffixes in the Sun 223 * Java System Directory Server). If any of the base DNs is 224 * subordinate to a base DN for another backend, then all base DNs 225 * for that backend must be subordinate to that same base DN. 226 * 227 * @return Returns the "base-dn" property definition. 228 */ 229 public DNPropertyDefinition getBaseDNPropertyDefinition() { 230 return BackendCfgDefn.getInstance().getBaseDNPropertyDefinition(); 231 } 232 233 234 235 /** 236 * Get the "enabled" property definition. 237 * <p> 238 * Indicates whether the backend is enabled in the server. 239 * <p> 240 * If a backend is not enabled, then its contents are not accessible 241 * when processing operations. 242 * 243 * @return Returns the "enabled" property definition. 244 */ 245 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 246 return BackendCfgDefn.getInstance().getEnabledPropertyDefinition(); 247 } 248 249 250 251 /** 252 * Get the "is-private-backend" property definition. 253 * <p> 254 * Indicates whether the backend should be considered a private 255 * backend, which indicates that it is used for storing operational 256 * data rather than user-defined information. 257 * 258 * @return Returns the "is-private-backend" property definition. 259 */ 260 public BooleanPropertyDefinition getIsPrivateBackendPropertyDefinition() { 261 return PD_IS_PRIVATE_BACKEND; 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 "ldif-file" property definition. 282 * <p> 283 * Specifies the path to the LDIF file containing the data for this 284 * backend. 285 * 286 * @return Returns the "ldif-file" property definition. 287 */ 288 public StringPropertyDefinition getLDIFFilePropertyDefinition() { 289 return PD_LDIF_FILE; 290 } 291 292 293 294 /** 295 * Get the "writability-mode" property definition. 296 * <p> 297 * Specifies the behavior that the backend should use when 298 * processing write operations. 299 * 300 * @return Returns the "writability-mode" property definition. 301 */ 302 public EnumPropertyDefinition<WritabilityMode> getWritabilityModePropertyDefinition() { 303 return PD_WRITABILITY_MODE; 304 } 305 306 307 308 /** 309 * Managed object client implementation. 310 */ 311 private static class LDIFBackendCfgClientImpl implements 312 LDIFBackendCfgClient { 313 314 // Private implementation. 315 private ManagedObject<? extends LDIFBackendCfgClient> impl; 316 317 318 319 // Private constructor. 320 private LDIFBackendCfgClientImpl( 321 ManagedObject<? extends LDIFBackendCfgClient> impl) { 322 this.impl = impl; 323 } 324 325 326 327 /** 328 * {@inheritDoc} 329 */ 330 public String getBackendId() { 331 return impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition()); 332 } 333 334 335 336 /** 337 * {@inheritDoc} 338 */ 339 public void setBackendId(String value) throws PropertyException { 340 impl.setPropertyValue(INSTANCE.getBackendIdPropertyDefinition(), value); 341 } 342 343 344 345 /** 346 * {@inheritDoc} 347 */ 348 public SortedSet<DN> getBaseDN() { 349 return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition()); 350 } 351 352 353 354 /** 355 * {@inheritDoc} 356 */ 357 public void setBaseDN(Collection<DN> values) { 358 impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values); 359 } 360 361 362 363 /** 364 * {@inheritDoc} 365 */ 366 public Boolean isEnabled() { 367 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 368 } 369 370 371 372 /** 373 * {@inheritDoc} 374 */ 375 public void setEnabled(boolean value) { 376 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 377 } 378 379 380 381 /** 382 * {@inheritDoc} 383 */ 384 public boolean isIsPrivateBackend() { 385 return impl.getPropertyValue(INSTANCE.getIsPrivateBackendPropertyDefinition()); 386 } 387 388 389 390 /** 391 * {@inheritDoc} 392 */ 393 public void setIsPrivateBackend(Boolean value) { 394 impl.setPropertyValue(INSTANCE.getIsPrivateBackendPropertyDefinition(), value); 395 } 396 397 398 399 /** 400 * {@inheritDoc} 401 */ 402 public String getJavaClass() { 403 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 404 } 405 406 407 408 /** 409 * {@inheritDoc} 410 */ 411 public void setJavaClass(String value) { 412 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 413 } 414 415 416 417 /** 418 * {@inheritDoc} 419 */ 420 public String getLDIFFile() { 421 return impl.getPropertyValue(INSTANCE.getLDIFFilePropertyDefinition()); 422 } 423 424 425 426 /** 427 * {@inheritDoc} 428 */ 429 public void setLDIFFile(String value) { 430 impl.setPropertyValue(INSTANCE.getLDIFFilePropertyDefinition(), value); 431 } 432 433 434 435 /** 436 * {@inheritDoc} 437 */ 438 public WritabilityMode getWritabilityMode() { 439 return impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition()); 440 } 441 442 443 444 /** 445 * {@inheritDoc} 446 */ 447 public void setWritabilityMode(WritabilityMode value) { 448 impl.setPropertyValue(INSTANCE.getWritabilityModePropertyDefinition(), value); 449 } 450 451 452 453 /** 454 * {@inheritDoc} 455 */ 456 public ManagedObjectDefinition<? extends LDIFBackendCfgClient, ? extends LDIFBackendCfg> definition() { 457 return INSTANCE; 458 } 459 460 461 462 /** 463 * {@inheritDoc} 464 */ 465 public PropertyProvider properties() { 466 return impl; 467 } 468 469 470 471 /** 472 * {@inheritDoc} 473 */ 474 public void commit() throws ManagedObjectAlreadyExistsException, 475 MissingMandatoryPropertiesException, ConcurrentModificationException, 476 OperationRejectedException, AuthorizationException, 477 CommunicationException { 478 impl.commit(); 479 } 480 481 482 483 /** {@inheritDoc} */ 484 public String toString() { 485 return impl.toString(); 486 } 487 } 488 489 490 491 /** 492 * Managed object server implementation. 493 */ 494 private static class LDIFBackendCfgServerImpl implements 495 LDIFBackendCfg { 496 497 // Private implementation. 498 private ServerManagedObject<? extends LDIFBackendCfg> impl; 499 500 // The value of the "backend-id" property. 501 private final String pBackendId; 502 503 // The value of the "base-dn" property. 504 private final SortedSet<DN> pBaseDN; 505 506 // The value of the "enabled" property. 507 private final boolean pEnabled; 508 509 // The value of the "is-private-backend" property. 510 private final boolean pIsPrivateBackend; 511 512 // The value of the "java-class" property. 513 private final String pJavaClass; 514 515 // The value of the "ldif-file" property. 516 private final String pLDIFFile; 517 518 // The value of the "writability-mode" property. 519 private final WritabilityMode pWritabilityMode; 520 521 522 523 // Private constructor. 524 private LDIFBackendCfgServerImpl(ServerManagedObject<? extends LDIFBackendCfg> impl) { 525 this.impl = impl; 526 this.pBackendId = impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition()); 527 this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition()); 528 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 529 this.pIsPrivateBackend = impl.getPropertyValue(INSTANCE.getIsPrivateBackendPropertyDefinition()); 530 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 531 this.pLDIFFile = impl.getPropertyValue(INSTANCE.getLDIFFilePropertyDefinition()); 532 this.pWritabilityMode = impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition()); 533 } 534 535 536 537 /** 538 * {@inheritDoc} 539 */ 540 public void addLDIFChangeListener( 541 ConfigurationChangeListener<LDIFBackendCfg> listener) { 542 impl.registerChangeListener(listener); 543 } 544 545 546 547 /** 548 * {@inheritDoc} 549 */ 550 public void removeLDIFChangeListener( 551 ConfigurationChangeListener<LDIFBackendCfg> listener) { 552 impl.deregisterChangeListener(listener); 553 } 554 /** 555 * {@inheritDoc} 556 */ 557 public void addChangeListener( 558 ConfigurationChangeListener<BackendCfg> listener) { 559 impl.registerChangeListener(listener); 560 } 561 562 563 564 /** 565 * {@inheritDoc} 566 */ 567 public void removeChangeListener( 568 ConfigurationChangeListener<BackendCfg> listener) { 569 impl.deregisterChangeListener(listener); 570 } 571 572 573 574 /** 575 * {@inheritDoc} 576 */ 577 public String getBackendId() { 578 return pBackendId; 579 } 580 581 582 583 /** 584 * {@inheritDoc} 585 */ 586 public SortedSet<DN> getBaseDN() { 587 return pBaseDN; 588 } 589 590 591 592 /** 593 * {@inheritDoc} 594 */ 595 public boolean isEnabled() { 596 return pEnabled; 597 } 598 599 600 601 /** 602 * {@inheritDoc} 603 */ 604 public boolean isIsPrivateBackend() { 605 return pIsPrivateBackend; 606 } 607 608 609 610 /** 611 * {@inheritDoc} 612 */ 613 public String getJavaClass() { 614 return pJavaClass; 615 } 616 617 618 619 /** 620 * {@inheritDoc} 621 */ 622 public String getLDIFFile() { 623 return pLDIFFile; 624 } 625 626 627 628 /** 629 * {@inheritDoc} 630 */ 631 public WritabilityMode getWritabilityMode() { 632 return pWritabilityMode; 633 } 634 635 636 637 /** 638 * {@inheritDoc} 639 */ 640 public Class<? extends LDIFBackendCfg> configurationClass() { 641 return LDIFBackendCfg.class; 642 } 643 644 645 646 /** 647 * {@inheritDoc} 648 */ 649 public DN dn() { 650 return impl.getDN(); 651 } 652 653 654 655 /** {@inheritDoc} */ 656 public String toString() { 657 return impl.toString(); 658 } 659 } 660}