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