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