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 /** {@inheritDoc} */ 155 public ConfigFileHandlerBackendCfgClient createClientConfiguration( 156 ManagedObject<? extends ConfigFileHandlerBackendCfgClient> impl) { 157 return new ConfigFileHandlerBackendCfgClientImpl(impl); 158 } 159 160 161 162 /** {@inheritDoc} */ 163 public ConfigFileHandlerBackendCfg createServerConfiguration( 164 ServerManagedObject<? extends ConfigFileHandlerBackendCfg> impl) { 165 return new ConfigFileHandlerBackendCfgServerImpl(impl); 166 } 167 168 169 170 /** {@inheritDoc} */ 171 public Class<ConfigFileHandlerBackendCfg> getServerConfigurationClass() { 172 return ConfigFileHandlerBackendCfg.class; 173 } 174 175 176 177 /** 178 * Get the "backend-id" property definition. 179 * <p> 180 * Specifies a name to identify the associated backend. 181 * <p> 182 * The name must be unique among all backends in the server. The 183 * backend ID may not be altered after the backend is created in the 184 * server. 185 * 186 * @return Returns the "backend-id" property definition. 187 */ 188 public StringPropertyDefinition getBackendIdPropertyDefinition() { 189 return BackendCfgDefn.getInstance().getBackendIdPropertyDefinition(); 190 } 191 192 193 194 /** 195 * Get the "base-dn" property definition. 196 * <p> 197 * Specifies the base DN(s) for the data that the backend handles. 198 * <p> 199 * A single backend may be responsible for one or more base DNs. 200 * Note that no two backends may have the same base DN although one 201 * backend may have a base DN that is below a base DN provided by 202 * another backend (similar to the use of sub-suffixes in the Sun 203 * Java System Directory Server). If any of the base DNs is 204 * subordinate to a base DN for another backend, then all base DNs 205 * for that backend must be subordinate to that same base DN. 206 * 207 * @return Returns the "base-dn" property definition. 208 */ 209 public DNPropertyDefinition getBaseDNPropertyDefinition() { 210 return BackendCfgDefn.getInstance().getBaseDNPropertyDefinition(); 211 } 212 213 214 215 /** 216 * Get the "enabled" property definition. 217 * <p> 218 * Indicates whether the backend is enabled in the server. 219 * <p> 220 * If a backend is not enabled, then its contents are not accessible 221 * when processing operations. 222 * 223 * @return Returns the "enabled" property definition. 224 */ 225 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 226 return BackendCfgDefn.getInstance().getEnabledPropertyDefinition(); 227 } 228 229 230 231 /** 232 * Get the "java-class" property definition. 233 * <p> 234 * Specifies the fully-qualified name of the Java class that 235 * provides the backend implementation. 236 * 237 * @return Returns the "java-class" property definition. 238 */ 239 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 240 return PD_JAVA_CLASS; 241 } 242 243 244 245 /** 246 * Get the "writability-mode" property definition. 247 * <p> 248 * Specifies the behavior that the backend should use when 249 * processing write operations. 250 * 251 * @return Returns the "writability-mode" property definition. 252 */ 253 public EnumPropertyDefinition<WritabilityMode> getWritabilityModePropertyDefinition() { 254 return PD_WRITABILITY_MODE; 255 } 256 257 258 259 /** 260 * Managed object client implementation. 261 */ 262 private static class ConfigFileHandlerBackendCfgClientImpl implements 263 ConfigFileHandlerBackendCfgClient { 264 265 /** Private implementation. */ 266 private ManagedObject<? extends ConfigFileHandlerBackendCfgClient> impl; 267 268 269 270 /** Private constructor. */ 271 private ConfigFileHandlerBackendCfgClientImpl( 272 ManagedObject<? extends ConfigFileHandlerBackendCfgClient> impl) { 273 this.impl = impl; 274 } 275 276 277 278 /** {@inheritDoc} */ 279 public String getBackendId() { 280 return impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition()); 281 } 282 283 284 285 /** {@inheritDoc} */ 286 public void setBackendId(String value) throws PropertyException { 287 impl.setPropertyValue(INSTANCE.getBackendIdPropertyDefinition(), value); 288 } 289 290 291 292 /** {@inheritDoc} */ 293 public SortedSet<DN> getBaseDN() { 294 return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition()); 295 } 296 297 298 299 /** {@inheritDoc} */ 300 public void setBaseDN(Collection<DN> values) { 301 impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values); 302 } 303 304 305 306 /** {@inheritDoc} */ 307 public Boolean isEnabled() { 308 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 309 } 310 311 312 313 /** {@inheritDoc} */ 314 public void setEnabled(boolean value) { 315 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 316 } 317 318 319 320 /** {@inheritDoc} */ 321 public String getJavaClass() { 322 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 323 } 324 325 326 327 /** {@inheritDoc} */ 328 public void setJavaClass(String value) { 329 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 330 } 331 332 333 334 /** {@inheritDoc} */ 335 public WritabilityMode getWritabilityMode() { 336 return impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition()); 337 } 338 339 340 341 /** {@inheritDoc} */ 342 public void setWritabilityMode(WritabilityMode value) { 343 impl.setPropertyValue(INSTANCE.getWritabilityModePropertyDefinition(), value); 344 } 345 346 347 348 /** {@inheritDoc} */ 349 public ManagedObjectDefinition<? extends ConfigFileHandlerBackendCfgClient, ? extends ConfigFileHandlerBackendCfg> definition() { 350 return INSTANCE; 351 } 352 353 354 355 /** {@inheritDoc} */ 356 public PropertyProvider properties() { 357 return impl; 358 } 359 360 361 362 /** {@inheritDoc} */ 363 public void commit() throws ManagedObjectAlreadyExistsException, 364 MissingMandatoryPropertiesException, ConcurrentModificationException, 365 OperationRejectedException, LdapException { 366 impl.commit(); 367 } 368 369 370 371 /** {@inheritDoc} */ 372 public String toString() { 373 return impl.toString(); 374 } 375 } 376 377 378 379 /** 380 * Managed object server implementation. 381 */ 382 private static class ConfigFileHandlerBackendCfgServerImpl implements 383 ConfigFileHandlerBackendCfg { 384 385 /** Private implementation. */ 386 private ServerManagedObject<? extends ConfigFileHandlerBackendCfg> impl; 387 388 /** The value of the "backend-id" property. */ 389 private final String pBackendId; 390 391 /** The value of the "base-dn" property. */ 392 private final SortedSet<DN> pBaseDN; 393 394 /** The value of the "enabled" property. */ 395 private final boolean pEnabled; 396 397 /** The value of the "java-class" property. */ 398 private final String pJavaClass; 399 400 /** The value of the "writability-mode" property. */ 401 private final WritabilityMode pWritabilityMode; 402 403 404 405 /** Private constructor. */ 406 private ConfigFileHandlerBackendCfgServerImpl(ServerManagedObject<? extends ConfigFileHandlerBackendCfg> impl) { 407 this.impl = impl; 408 this.pBackendId = impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition()); 409 this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition()); 410 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 411 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 412 this.pWritabilityMode = impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition()); 413 } 414 415 416 417 /** {@inheritDoc} */ 418 public void addConfigFileHandlerChangeListener( 419 ConfigurationChangeListener<ConfigFileHandlerBackendCfg> listener) { 420 impl.registerChangeListener(listener); 421 } 422 423 424 425 /** {@inheritDoc} */ 426 public void removeConfigFileHandlerChangeListener( 427 ConfigurationChangeListener<ConfigFileHandlerBackendCfg> listener) { 428 impl.deregisterChangeListener(listener); 429 } 430 /** {@inheritDoc} */ 431 public void addChangeListener( 432 ConfigurationChangeListener<BackendCfg> listener) { 433 impl.registerChangeListener(listener); 434 } 435 436 437 438 /** {@inheritDoc} */ 439 public void removeChangeListener( 440 ConfigurationChangeListener<BackendCfg> listener) { 441 impl.deregisterChangeListener(listener); 442 } 443 444 445 446 /** {@inheritDoc} */ 447 public String getBackendId() { 448 return pBackendId; 449 } 450 451 452 453 /** {@inheritDoc} */ 454 public SortedSet<DN> getBaseDN() { 455 return pBaseDN; 456 } 457 458 459 460 /** {@inheritDoc} */ 461 public boolean isEnabled() { 462 return pEnabled; 463 } 464 465 466 467 /** {@inheritDoc} */ 468 public String getJavaClass() { 469 return pJavaClass; 470 } 471 472 473 474 /** {@inheritDoc} */ 475 public WritabilityMode getWritabilityMode() { 476 return pWritabilityMode; 477 } 478 479 480 481 /** {@inheritDoc} */ 482 public Class<? extends ConfigFileHandlerBackendCfg> configurationClass() { 483 return ConfigFileHandlerBackendCfg.class; 484 } 485 486 487 488 /** {@inheritDoc} */ 489 public DN dn() { 490 return impl.getDN(); 491 } 492 493 494 495 /** {@inheritDoc} */ 496 public String toString() { 497 return impl.toString(); 498 } 499 } 500}