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  /** {@inheritDoc} */
143  public ChangeNumberControlPluginCfgClient createClientConfiguration(
144      ManagedObject<? extends ChangeNumberControlPluginCfgClient> impl) {
145    return new ChangeNumberControlPluginCfgClientImpl(impl);
146  }
147
148
149
150  /** {@inheritDoc} */
151  public ChangeNumberControlPluginCfg createServerConfiguration(
152      ServerManagedObject<? extends ChangeNumberControlPluginCfg> impl) {
153    return new ChangeNumberControlPluginCfgServerImpl(impl);
154  }
155
156
157
158  /** {@inheritDoc} */
159  public Class<ChangeNumberControlPluginCfg> getServerConfigurationClass() {
160    return ChangeNumberControlPluginCfg.class;
161  }
162
163
164
165  /**
166   * Get the "enabled" property definition.
167   * <p>
168   * Indicates whether the plug-in is enabled for use.
169   *
170   * @return Returns the "enabled" property definition.
171   */
172  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
173    return PluginCfgDefn.getInstance().getEnabledPropertyDefinition();
174  }
175
176
177
178  /**
179   * Get the "invoke-for-internal-operations" property definition.
180   * <p>
181   * Indicates whether the plug-in should be invoked for internal
182   * operations.
183   * <p>
184   * Any plug-in that can be invoked for internal operations must
185   * ensure that it does not create any new internal operatons that can
186   * cause the same plug-in to be re-invoked.
187   *
188   * @return Returns the "invoke-for-internal-operations" property definition.
189   */
190  public BooleanPropertyDefinition getInvokeForInternalOperationsPropertyDefinition() {
191    return PluginCfgDefn.getInstance().getInvokeForInternalOperationsPropertyDefinition();
192  }
193
194
195
196  /**
197   * Get the "java-class" property definition.
198   * <p>
199   * Specifies the fully-qualified name of the Java class that
200   * provides the plug-in implementation.
201   *
202   * @return Returns the "java-class" property definition.
203   */
204  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
205    return PD_JAVA_CLASS;
206  }
207
208
209
210  /**
211   * Get the "plugin-type" property definition.
212   * <p>
213   * Specifies the set of plug-in types for the plug-in, which
214   * specifies the times at which the plug-in is invoked.
215   *
216   * @return Returns the "plugin-type" property definition.
217   */
218  public EnumPropertyDefinition<PluginType> getPluginTypePropertyDefinition() {
219    return PD_PLUGIN_TYPE;
220  }
221
222
223
224  /**
225   * Managed object client implementation.
226   */
227  private static class ChangeNumberControlPluginCfgClientImpl implements
228    ChangeNumberControlPluginCfgClient {
229
230    /** Private implementation. */
231    private ManagedObject<? extends ChangeNumberControlPluginCfgClient> impl;
232
233
234
235    /** Private constructor. */
236    private ChangeNumberControlPluginCfgClientImpl(
237        ManagedObject<? extends ChangeNumberControlPluginCfgClient> impl) {
238      this.impl = impl;
239    }
240
241
242
243    /** {@inheritDoc} */
244    public Boolean isEnabled() {
245      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
246    }
247
248
249
250    /** {@inheritDoc} */
251    public void setEnabled(boolean value) {
252      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
253    }
254
255
256
257    /** {@inheritDoc} */
258    public boolean isInvokeForInternalOperations() {
259      return impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition());
260    }
261
262
263
264    /** {@inheritDoc} */
265    public void setInvokeForInternalOperations(Boolean value) {
266      impl.setPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition(), value);
267    }
268
269
270
271    /** {@inheritDoc} */
272    public String getJavaClass() {
273      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
274    }
275
276
277
278    /** {@inheritDoc} */
279    public void setJavaClass(String value) {
280      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
281    }
282
283
284
285    /** {@inheritDoc} */
286    public SortedSet<PluginType> getPluginType() {
287      return impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition());
288    }
289
290
291
292    /** {@inheritDoc} */
293    public void setPluginType(Collection<PluginType> values) {
294      impl.setPropertyValues(INSTANCE.getPluginTypePropertyDefinition(), values);
295    }
296
297
298
299    /** {@inheritDoc} */
300    public ManagedObjectDefinition<? extends ChangeNumberControlPluginCfgClient, ? extends ChangeNumberControlPluginCfg> definition() {
301      return INSTANCE;
302    }
303
304
305
306    /** {@inheritDoc} */
307    public PropertyProvider properties() {
308      return impl;
309    }
310
311
312
313    /** {@inheritDoc} */
314    public void commit() throws ManagedObjectAlreadyExistsException,
315        MissingMandatoryPropertiesException, ConcurrentModificationException,
316        OperationRejectedException, LdapException {
317      impl.commit();
318    }
319
320
321
322    /** {@inheritDoc} */
323    public String toString() {
324      return impl.toString();
325    }
326  }
327
328
329
330  /**
331   * Managed object server implementation.
332   */
333  private static class ChangeNumberControlPluginCfgServerImpl implements
334    ChangeNumberControlPluginCfg {
335
336    /** Private implementation. */
337    private ServerManagedObject<? extends ChangeNumberControlPluginCfg> impl;
338
339    /** The value of the "enabled" property. */
340    private final boolean pEnabled;
341
342    /** The value of the "invoke-for-internal-operations" property. */
343    private final boolean pInvokeForInternalOperations;
344
345    /** The value of the "java-class" property. */
346    private final String pJavaClass;
347
348    /** The value of the "plugin-type" property. */
349    private final SortedSet<PluginType> pPluginType;
350
351
352
353    /** Private constructor. */
354    private ChangeNumberControlPluginCfgServerImpl(ServerManagedObject<? extends ChangeNumberControlPluginCfg> impl) {
355      this.impl = impl;
356      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
357      this.pInvokeForInternalOperations = impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition());
358      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
359      this.pPluginType = impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition());
360    }
361
362
363
364    /** {@inheritDoc} */
365    public void addChangeNumberControlChangeListener(
366        ConfigurationChangeListener<ChangeNumberControlPluginCfg> listener) {
367      impl.registerChangeListener(listener);
368    }
369
370
371
372    /** {@inheritDoc} */
373    public void removeChangeNumberControlChangeListener(
374        ConfigurationChangeListener<ChangeNumberControlPluginCfg> listener) {
375      impl.deregisterChangeListener(listener);
376    }
377    /** {@inheritDoc} */
378    public void addChangeListener(
379        ConfigurationChangeListener<PluginCfg> listener) {
380      impl.registerChangeListener(listener);
381    }
382
383
384
385    /** {@inheritDoc} */
386    public void removeChangeListener(
387        ConfigurationChangeListener<PluginCfg> listener) {
388      impl.deregisterChangeListener(listener);
389    }
390
391
392
393    /** {@inheritDoc} */
394    public boolean isEnabled() {
395      return pEnabled;
396    }
397
398
399
400    /** {@inheritDoc} */
401    public boolean isInvokeForInternalOperations() {
402      return pInvokeForInternalOperations;
403    }
404
405
406
407    /** {@inheritDoc} */
408    public String getJavaClass() {
409      return pJavaClass;
410    }
411
412
413
414    /** {@inheritDoc} */
415    public SortedSet<PluginType> getPluginType() {
416      return pPluginType;
417    }
418
419
420
421    /** {@inheritDoc} */
422    public Class<? extends ChangeNumberControlPluginCfg> configurationClass() {
423      return ChangeNumberControlPluginCfg.class;
424    }
425
426
427
428    /** {@inheritDoc} */
429    public DN dn() {
430      return impl.getDN();
431    }
432
433
434
435    /** {@inheritDoc} */
436    public String toString() {
437      return impl.toString();
438    }
439  }
440}