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