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