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.EntryUUIDPluginCfgClient;
052import org.forgerock.opendj.server.config.meta.PluginCfgDefn.PluginType;
053import org.forgerock.opendj.server.config.server.EntryUUIDPluginCfg;
054import org.forgerock.opendj.server.config.server.PluginCfg;
055
056
057
058/**
059 * An interface for querying the Entry UUID Plugin managed object
060 * definition meta information.
061 * <p>
062 * The Entry UUID Plugin generates values for the entryUUID
063 * operational attribute whenever an entry is added via protocol or
064 * imported from LDIF.
065 */
066public final class EntryUUIDPluginCfgDefn extends ManagedObjectDefinition<EntryUUIDPluginCfgClient, EntryUUIDPluginCfg> {
067
068  /** The singleton configuration definition instance. */
069  private static final EntryUUIDPluginCfgDefn INSTANCE = new EntryUUIDPluginCfgDefn();
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.EntryUUIDPlugin");
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>("ldifimport", "preoperationadd");
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 Entry UUID Plugin configuration definition singleton.
123   *
124   * @return Returns the Entry UUID Plugin configuration definition
125   *         singleton.
126   */
127  public static EntryUUIDPluginCfgDefn getInstance() {
128    return INSTANCE;
129  }
130
131
132
133  /**
134   * Private constructor.
135   */
136  private EntryUUIDPluginCfgDefn() {
137    super("entry-uuid-plugin", PluginCfgDefn.getInstance());
138  }
139
140
141
142  /** {@inheritDoc} */
143  public EntryUUIDPluginCfgClient createClientConfiguration(
144      ManagedObject<? extends EntryUUIDPluginCfgClient> impl) {
145    return new EntryUUIDPluginCfgClientImpl(impl);
146  }
147
148
149
150  /** {@inheritDoc} */
151  public EntryUUIDPluginCfg createServerConfiguration(
152      ServerManagedObject<? extends EntryUUIDPluginCfg> impl) {
153    return new EntryUUIDPluginCfgServerImpl(impl);
154  }
155
156
157
158  /** {@inheritDoc} */
159  public Class<EntryUUIDPluginCfg> getServerConfigurationClass() {
160    return EntryUUIDPluginCfg.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 EntryUUIDPluginCfgClientImpl implements
228    EntryUUIDPluginCfgClient {
229
230    /** Private implementation. */
231    private ManagedObject<? extends EntryUUIDPluginCfgClient> impl;
232
233
234
235    /** Private constructor. */
236    private EntryUUIDPluginCfgClientImpl(
237        ManagedObject<? extends EntryUUIDPluginCfgClient> 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 EntryUUIDPluginCfgClient, ? extends EntryUUIDPluginCfg> 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 EntryUUIDPluginCfgServerImpl implements
334    EntryUUIDPluginCfg {
335
336    /** Private implementation. */
337    private ServerManagedObject<? extends EntryUUIDPluginCfg> 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 EntryUUIDPluginCfgServerImpl(ServerManagedObject<? extends EntryUUIDPluginCfg> 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 addEntryUUIDChangeListener(
366        ConfigurationChangeListener<EntryUUIDPluginCfg> listener) {
367      impl.registerChangeListener(listener);
368    }
369
370
371
372    /** {@inheritDoc} */
373    public void removeEntryUUIDChangeListener(
374        ConfigurationChangeListener<EntryUUIDPluginCfg> 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 EntryUUIDPluginCfg> configurationClass() {
423      return EntryUUIDPluginCfg.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}