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.EntryUUIDPluginCfgClient;
051import org.opends.server.admin.std.meta.PluginCfgDefn.PluginType;
052import org.opends.server.admin.std.server.EntryUUIDPluginCfg;
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 Entry UUID Plugin managed object
061 * definition meta information.
062 * <p>
063 * The Entry UUID Plugin generates values for the entryUUID
064 * operational attribute whenever an entry is added via protocol or
065 * imported from LDIF.
066 */
067public final class EntryUUIDPluginCfgDefn extends ManagedObjectDefinition<EntryUUIDPluginCfgClient, EntryUUIDPluginCfg> {
068
069  // The singleton configuration definition instance.
070  private static final EntryUUIDPluginCfgDefn INSTANCE = new EntryUUIDPluginCfgDefn();
071
072
073
074  // The "java-class" property definition.
075  private static final ClassPropertyDefinition PD_JAVA_CLASS;
076
077
078
079  // The "plugin-type" property definition.
080  private static final EnumPropertyDefinition<PluginType> PD_PLUGIN_TYPE;
081
082
083
084  // Build the "java-class" property definition.
085  static {
086      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
087      builder.setOption(PropertyOption.MANDATORY);
088      builder.setOption(PropertyOption.ADVANCED);
089      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
090      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.plugins.EntryUUIDPlugin");
091      builder.setDefaultBehaviorProvider(provider);
092      builder.addInstanceOf("org.opends.server.api.plugin.DirectoryServerPlugin");
093      PD_JAVA_CLASS = builder.getInstance();
094      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
095  }
096
097
098
099  // Build the "plugin-type" property definition.
100  static {
101      EnumPropertyDefinition.Builder<PluginType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "plugin-type");
102      builder.setOption(PropertyOption.MULTI_VALUED);
103      builder.setOption(PropertyOption.MANDATORY);
104      builder.setOption(PropertyOption.ADVANCED);
105      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "plugin-type"));
106      DefaultBehaviorProvider<PluginType> provider = new DefinedDefaultBehaviorProvider<PluginType>("ldifimport", "preoperationadd");
107      builder.setDefaultBehaviorProvider(provider);
108      builder.setEnumClass(PluginType.class);
109      PD_PLUGIN_TYPE = builder.getInstance();
110      INSTANCE.registerPropertyDefinition(PD_PLUGIN_TYPE);
111  }
112
113
114
115  // Register the tags associated with this managed object definition.
116  static {
117    INSTANCE.registerTag(Tag.valueOf("core-server"));
118  }
119
120
121
122  /**
123   * Get the Entry UUID Plugin configuration definition singleton.
124   *
125   * @return Returns the Entry UUID Plugin configuration definition
126   *         singleton.
127   */
128  public static EntryUUIDPluginCfgDefn getInstance() {
129    return INSTANCE;
130  }
131
132
133
134  /**
135   * Private constructor.
136   */
137  private EntryUUIDPluginCfgDefn() {
138    super("entry-uuid-plugin", PluginCfgDefn.getInstance());
139  }
140
141
142
143  /**
144   * {@inheritDoc}
145   */
146  public EntryUUIDPluginCfgClient createClientConfiguration(
147      ManagedObject<? extends EntryUUIDPluginCfgClient> impl) {
148    return new EntryUUIDPluginCfgClientImpl(impl);
149  }
150
151
152
153  /**
154   * {@inheritDoc}
155   */
156  public EntryUUIDPluginCfg createServerConfiguration(
157      ServerManagedObject<? extends EntryUUIDPluginCfg> impl) {
158    return new EntryUUIDPluginCfgServerImpl(impl);
159  }
160
161
162
163  /**
164   * {@inheritDoc}
165   */
166  public Class<EntryUUIDPluginCfg> getServerConfigurationClass() {
167    return EntryUUIDPluginCfg.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 EntryUUIDPluginCfgClientImpl implements
235    EntryUUIDPluginCfgClient {
236
237    // Private implementation.
238    private ManagedObject<? extends EntryUUIDPluginCfgClient> impl;
239
240
241
242    // Private constructor.
243    private EntryUUIDPluginCfgClientImpl(
244        ManagedObject<? extends EntryUUIDPluginCfgClient> 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 EntryUUIDPluginCfgClient, ? extends EntryUUIDPluginCfg> 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 EntryUUIDPluginCfgServerImpl implements
358    EntryUUIDPluginCfg {
359
360    // Private implementation.
361    private ServerManagedObject<? extends EntryUUIDPluginCfg> 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 EntryUUIDPluginCfgServerImpl(ServerManagedObject<? extends EntryUUIDPluginCfg> 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 addEntryUUIDChangeListener(
392        ConfigurationChangeListener<EntryUUIDPluginCfg> listener) {
393      impl.registerChangeListener(listener);
394    }
395
396
397
398    /**
399     * {@inheritDoc}
400     */
401    public void removeEntryUUIDChangeListener(
402        ConfigurationChangeListener<EntryUUIDPluginCfg> 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 EntryUUIDPluginCfg> configurationClass() {
465      return EntryUUIDPluginCfg.class;
466    }
467
468
469
470    /**
471     * {@inheritDoc}
472     */
473    public DN dn() {
474      return impl.getDN();
475    }
476
477  }
478}