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