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