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.EnumPropertyDefinition; 042import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 043import org.forgerock.opendj.config.ManagedObjectDefinition; 044import org.forgerock.opendj.config.PropertyOption; 045import org.forgerock.opendj.config.PropertyProvider; 046import org.forgerock.opendj.config.server.ConfigurationChangeListener; 047import org.forgerock.opendj.config.server.ServerManagedObject; 048import org.forgerock.opendj.config.Tag; 049import org.forgerock.opendj.ldap.DN; 050import org.forgerock.opendj.ldap.LdapException; 051import org.forgerock.opendj.server.config.client.ChangeNumberControlPluginCfgClient; 052import org.forgerock.opendj.server.config.meta.PluginCfgDefn.PluginType; 053import org.forgerock.opendj.server.config.server.ChangeNumberControlPluginCfg; 054import org.forgerock.opendj.server.config.server.PluginCfg; 055 056 057 058/** 059 * An interface for querying the Change Number Control Plugin managed 060 * object definition meta information. 061 * <p> 062 * The Change Number Control Plugin returns the change number 063 * generated by the replication subsystem. 064 */ 065public final class ChangeNumberControlPluginCfgDefn extends ManagedObjectDefinition<ChangeNumberControlPluginCfgClient, ChangeNumberControlPluginCfg> { 066 067 // The singleton configuration definition instance. 068 private static final ChangeNumberControlPluginCfgDefn INSTANCE = new ChangeNumberControlPluginCfgDefn(); 069 070 071 072 // The "java-class" property definition. 073 private static final ClassPropertyDefinition PD_JAVA_CLASS; 074 075 076 077 // The "plugin-type" property definition. 078 private static final EnumPropertyDefinition<PluginType> PD_PLUGIN_TYPE; 079 080 081 082 // Build the "java-class" property definition. 083 static { 084 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 085 builder.setOption(PropertyOption.MANDATORY); 086 builder.setOption(PropertyOption.ADVANCED); 087 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 088 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.plugins.ChangeNumberControlPlugin"); 089 builder.setDefaultBehaviorProvider(provider); 090 builder.addInstanceOf("org.opends.server.api.plugin.DirectoryServerPlugin"); 091 PD_JAVA_CLASS = builder.getInstance(); 092 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 093 } 094 095 096 097 // Build the "plugin-type" property definition. 098 static { 099 EnumPropertyDefinition.Builder<PluginType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "plugin-type"); 100 builder.setOption(PropertyOption.MULTI_VALUED); 101 builder.setOption(PropertyOption.MANDATORY); 102 builder.setOption(PropertyOption.ADVANCED); 103 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "plugin-type")); 104 DefaultBehaviorProvider<PluginType> provider = new DefinedDefaultBehaviorProvider<PluginType>("postOperationAdd", "postOperationDelete", "postOperationModify", "postOperationModifyDN"); 105 builder.setDefaultBehaviorProvider(provider); 106 builder.setEnumClass(PluginType.class); 107 PD_PLUGIN_TYPE = builder.getInstance(); 108 INSTANCE.registerPropertyDefinition(PD_PLUGIN_TYPE); 109 } 110 111 112 113 // Register the tags associated with this managed object definition. 114 static { 115 INSTANCE.registerTag(Tag.valueOf("core-server")); 116 } 117 118 119 120 /** 121 * Get the Change Number Control Plugin configuration definition 122 * singleton. 123 * 124 * @return Returns the Change Number Control Plugin configuration 125 * definition singleton. 126 */ 127 public static ChangeNumberControlPluginCfgDefn getInstance() { 128 return INSTANCE; 129 } 130 131 132 133 /** 134 * Private constructor. 135 */ 136 private ChangeNumberControlPluginCfgDefn() { 137 super("change-number-control-plugin", PluginCfgDefn.getInstance()); 138 } 139 140 141 142 /** 143 * {@inheritDoc} 144 */ 145 public ChangeNumberControlPluginCfgClient createClientConfiguration( 146 ManagedObject<? extends ChangeNumberControlPluginCfgClient> impl) { 147 return new ChangeNumberControlPluginCfgClientImpl(impl); 148 } 149 150 151 152 /** 153 * {@inheritDoc} 154 */ 155 public ChangeNumberControlPluginCfg createServerConfiguration( 156 ServerManagedObject<? extends ChangeNumberControlPluginCfg> impl) { 157 return new ChangeNumberControlPluginCfgServerImpl(impl); 158 } 159 160 161 162 /** 163 * {@inheritDoc} 164 */ 165 public Class<ChangeNumberControlPluginCfg> getServerConfigurationClass() { 166 return ChangeNumberControlPluginCfg.class; 167 } 168 169 170 171 /** 172 * Get the "enabled" property definition. 173 * <p> 174 * Indicates whether the plug-in is enabled for use. 175 * 176 * @return Returns the "enabled" property definition. 177 */ 178 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 179 return PluginCfgDefn.getInstance().getEnabledPropertyDefinition(); 180 } 181 182 183 184 /** 185 * Get the "invoke-for-internal-operations" property definition. 186 * <p> 187 * Indicates whether the plug-in should be invoked for internal 188 * operations. 189 * <p> 190 * Any plug-in that can be invoked for internal operations must 191 * ensure that it does not create any new internal operatons that can 192 * cause the same plug-in to be re-invoked. 193 * 194 * @return Returns the "invoke-for-internal-operations" property definition. 195 */ 196 public BooleanPropertyDefinition getInvokeForInternalOperationsPropertyDefinition() { 197 return PluginCfgDefn.getInstance().getInvokeForInternalOperationsPropertyDefinition(); 198 } 199 200 201 202 /** 203 * Get the "java-class" property definition. 204 * <p> 205 * Specifies the fully-qualified name of the Java class that 206 * provides the plug-in implementation. 207 * 208 * @return Returns the "java-class" property definition. 209 */ 210 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 211 return PD_JAVA_CLASS; 212 } 213 214 215 216 /** 217 * Get the "plugin-type" property definition. 218 * <p> 219 * Specifies the set of plug-in types for the plug-in, which 220 * specifies the times at which the plug-in is invoked. 221 * 222 * @return Returns the "plugin-type" property definition. 223 */ 224 public EnumPropertyDefinition<PluginType> getPluginTypePropertyDefinition() { 225 return PD_PLUGIN_TYPE; 226 } 227 228 229 230 /** 231 * Managed object client implementation. 232 */ 233 private static class ChangeNumberControlPluginCfgClientImpl implements 234 ChangeNumberControlPluginCfgClient { 235 236 // Private implementation. 237 private ManagedObject<? extends ChangeNumberControlPluginCfgClient> impl; 238 239 240 241 // Private constructor. 242 private ChangeNumberControlPluginCfgClientImpl( 243 ManagedObject<? extends ChangeNumberControlPluginCfgClient> impl) { 244 this.impl = impl; 245 } 246 247 248 249 /** 250 * {@inheritDoc} 251 */ 252 public Boolean isEnabled() { 253 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 254 } 255 256 257 258 /** 259 * {@inheritDoc} 260 */ 261 public void setEnabled(boolean value) { 262 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 263 } 264 265 266 267 /** 268 * {@inheritDoc} 269 */ 270 public boolean isInvokeForInternalOperations() { 271 return impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition()); 272 } 273 274 275 276 /** 277 * {@inheritDoc} 278 */ 279 public void setInvokeForInternalOperations(Boolean value) { 280 impl.setPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition(), value); 281 } 282 283 284 285 /** 286 * {@inheritDoc} 287 */ 288 public String getJavaClass() { 289 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 290 } 291 292 293 294 /** 295 * {@inheritDoc} 296 */ 297 public void setJavaClass(String value) { 298 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 299 } 300 301 302 303 /** 304 * {@inheritDoc} 305 */ 306 public SortedSet<PluginType> getPluginType() { 307 return impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition()); 308 } 309 310 311 312 /** 313 * {@inheritDoc} 314 */ 315 public void setPluginType(Collection<PluginType> values) { 316 impl.setPropertyValues(INSTANCE.getPluginTypePropertyDefinition(), values); 317 } 318 319 320 321 /** 322 * {@inheritDoc} 323 */ 324 public ManagedObjectDefinition<? extends ChangeNumberControlPluginCfgClient, ? extends ChangeNumberControlPluginCfg> definition() { 325 return INSTANCE; 326 } 327 328 329 330 /** 331 * {@inheritDoc} 332 */ 333 public PropertyProvider properties() { 334 return impl; 335 } 336 337 338 339 /** 340 * {@inheritDoc} 341 */ 342 public void commit() throws ManagedObjectAlreadyExistsException, 343 MissingMandatoryPropertiesException, ConcurrentModificationException, 344 OperationRejectedException, LdapException { 345 impl.commit(); 346 } 347 348 } 349 350 351 352 /** 353 * Managed object server implementation. 354 */ 355 private static class ChangeNumberControlPluginCfgServerImpl implements 356 ChangeNumberControlPluginCfg { 357 358 // Private implementation. 359 private ServerManagedObject<? extends ChangeNumberControlPluginCfg> impl; 360 361 // The value of the "enabled" property. 362 private final boolean pEnabled; 363 364 // The value of the "invoke-for-internal-operations" property. 365 private final boolean pInvokeForInternalOperations; 366 367 // The value of the "java-class" property. 368 private final String pJavaClass; 369 370 // The value of the "plugin-type" property. 371 private final SortedSet<PluginType> pPluginType; 372 373 374 375 // Private constructor. 376 private ChangeNumberControlPluginCfgServerImpl(ServerManagedObject<? extends ChangeNumberControlPluginCfg> impl) { 377 this.impl = impl; 378 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 379 this.pInvokeForInternalOperations = impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition()); 380 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 381 this.pPluginType = impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition()); 382 } 383 384 385 386 /** 387 * {@inheritDoc} 388 */ 389 public void addChangeNumberControlChangeListener( 390 ConfigurationChangeListener<ChangeNumberControlPluginCfg> listener) { 391 impl.registerChangeListener(listener); 392 } 393 394 395 396 /** 397 * {@inheritDoc} 398 */ 399 public void removeChangeNumberControlChangeListener( 400 ConfigurationChangeListener<ChangeNumberControlPluginCfg> listener) { 401 impl.deregisterChangeListener(listener); 402 } 403 /** 404 * {@inheritDoc} 405 */ 406 public void addChangeListener( 407 ConfigurationChangeListener<PluginCfg> listener) { 408 impl.registerChangeListener(listener); 409 } 410 411 412 413 /** 414 * {@inheritDoc} 415 */ 416 public void removeChangeListener( 417 ConfigurationChangeListener<PluginCfg> listener) { 418 impl.deregisterChangeListener(listener); 419 } 420 421 422 423 /** 424 * {@inheritDoc} 425 */ 426 public boolean isEnabled() { 427 return pEnabled; 428 } 429 430 431 432 /** 433 * {@inheritDoc} 434 */ 435 public boolean isInvokeForInternalOperations() { 436 return pInvokeForInternalOperations; 437 } 438 439 440 441 /** 442 * {@inheritDoc} 443 */ 444 public String getJavaClass() { 445 return pJavaClass; 446 } 447 448 449 450 /** 451 * {@inheritDoc} 452 */ 453 public SortedSet<PluginType> getPluginType() { 454 return pPluginType; 455 } 456 457 458 459 /** 460 * {@inheritDoc} 461 */ 462 public Class<? extends ChangeNumberControlPluginCfg> configurationClass() { 463 return ChangeNumberControlPluginCfg.class; 464 } 465 466 467 468 /** 469 * {@inheritDoc} 470 */ 471 public DN dn() { 472 return impl.getDN(); 473 } 474 475 } 476}