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