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