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