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