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