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