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