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