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.forgerock.opendj.server.config.meta;
017
018
019
020import java.util.Collection;
021import java.util.SortedSet;
022import org.forgerock.opendj.config.AdministratorAction;
023import org.forgerock.opendj.config.BooleanPropertyDefinition;
024import org.forgerock.opendj.config.ClassPropertyDefinition;
025import org.forgerock.opendj.config.client.ConcurrentModificationException;
026import org.forgerock.opendj.config.client.ManagedObject;
027import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
028import org.forgerock.opendj.config.client.OperationRejectedException;
029import org.forgerock.opendj.config.DefaultBehaviorProvider;
030import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
031import org.forgerock.opendj.config.EnumPropertyDefinition;
032import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
033import org.forgerock.opendj.config.ManagedObjectDefinition;
034import org.forgerock.opendj.config.PropertyOption;
035import org.forgerock.opendj.config.PropertyProvider;
036import org.forgerock.opendj.config.server.ConfigurationChangeListener;
037import org.forgerock.opendj.config.server.ServerManagedObject;
038import org.forgerock.opendj.config.Tag;
039import org.forgerock.opendj.ldap.DN;
040import org.forgerock.opendj.ldap.LdapException;
041import org.forgerock.opendj.server.config.client.EntryUUIDPluginCfgClient;
042import org.forgerock.opendj.server.config.meta.PluginCfgDefn.PluginType;
043import org.forgerock.opendj.server.config.server.EntryUUIDPluginCfg;
044import org.forgerock.opendj.server.config.server.PluginCfg;
045
046
047
048/**
049 * An interface for querying the Entry UUID Plugin managed object
050 * definition meta information.
051 * <p>
052 * The Entry UUID Plugin generates values for the entryUUID
053 * operational attribute whenever an entry is added via protocol or
054 * imported from LDIF.
055 */
056public final class EntryUUIDPluginCfgDefn extends ManagedObjectDefinition<EntryUUIDPluginCfgClient, EntryUUIDPluginCfg> {
057
058  /** The singleton configuration definition instance. */
059  private static final EntryUUIDPluginCfgDefn INSTANCE = new EntryUUIDPluginCfgDefn();
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.EntryUUIDPlugin");
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>("ldifimport", "preoperationadd");
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 Entry UUID Plugin configuration definition singleton.
113   *
114   * @return Returns the Entry UUID Plugin configuration definition
115   *         singleton.
116   */
117  public static EntryUUIDPluginCfgDefn getInstance() {
118    return INSTANCE;
119  }
120
121
122
123  /**
124   * Private constructor.
125   */
126  private EntryUUIDPluginCfgDefn() {
127    super("entry-uuid-plugin", PluginCfgDefn.getInstance());
128  }
129
130
131
132  /** {@inheritDoc} */
133  public EntryUUIDPluginCfgClient createClientConfiguration(
134      ManagedObject<? extends EntryUUIDPluginCfgClient> impl) {
135    return new EntryUUIDPluginCfgClientImpl(impl);
136  }
137
138
139
140  /** {@inheritDoc} */
141  public EntryUUIDPluginCfg createServerConfiguration(
142      ServerManagedObject<? extends EntryUUIDPluginCfg> impl) {
143    return new EntryUUIDPluginCfgServerImpl(impl);
144  }
145
146
147
148  /** {@inheritDoc} */
149  public Class<EntryUUIDPluginCfg> getServerConfigurationClass() {
150    return EntryUUIDPluginCfg.class;
151  }
152
153
154
155  /**
156   * Get the "enabled" property definition.
157   * <p>
158   * Indicates whether the plug-in is enabled for use.
159   *
160   * @return Returns the "enabled" property definition.
161   */
162  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
163    return PluginCfgDefn.getInstance().getEnabledPropertyDefinition();
164  }
165
166
167
168  /**
169   * Get the "invoke-for-internal-operations" property definition.
170   * <p>
171   * Indicates whether the plug-in should be invoked for internal
172   * operations.
173   * <p>
174   * Any plug-in that can be invoked for internal operations must
175   * ensure that it does not create any new internal operatons that can
176   * cause the same plug-in to be re-invoked.
177   *
178   * @return Returns the "invoke-for-internal-operations" property definition.
179   */
180  public BooleanPropertyDefinition getInvokeForInternalOperationsPropertyDefinition() {
181    return PluginCfgDefn.getInstance().getInvokeForInternalOperationsPropertyDefinition();
182  }
183
184
185
186  /**
187   * Get the "java-class" property definition.
188   * <p>
189   * Specifies the fully-qualified name of the Java class that
190   * provides the plug-in implementation.
191   *
192   * @return Returns the "java-class" property definition.
193   */
194  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
195    return PD_JAVA_CLASS;
196  }
197
198
199
200  /**
201   * Get the "plugin-type" property definition.
202   * <p>
203   * Specifies the set of plug-in types for the plug-in, which
204   * specifies the times at which the plug-in is invoked.
205   *
206   * @return Returns the "plugin-type" property definition.
207   */
208  public EnumPropertyDefinition<PluginType> getPluginTypePropertyDefinition() {
209    return PD_PLUGIN_TYPE;
210  }
211
212
213
214  /**
215   * Managed object client implementation.
216   */
217  private static class EntryUUIDPluginCfgClientImpl implements
218    EntryUUIDPluginCfgClient {
219
220    /** Private implementation. */
221    private ManagedObject<? extends EntryUUIDPluginCfgClient> impl;
222
223
224
225    /** Private constructor. */
226    private EntryUUIDPluginCfgClientImpl(
227        ManagedObject<? extends EntryUUIDPluginCfgClient> impl) {
228      this.impl = impl;
229    }
230
231
232
233    /** {@inheritDoc} */
234    public Boolean isEnabled() {
235      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
236    }
237
238
239
240    /** {@inheritDoc} */
241    public void setEnabled(boolean value) {
242      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
243    }
244
245
246
247    /** {@inheritDoc} */
248    public boolean isInvokeForInternalOperations() {
249      return impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition());
250    }
251
252
253
254    /** {@inheritDoc} */
255    public void setInvokeForInternalOperations(Boolean value) {
256      impl.setPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition(), value);
257    }
258
259
260
261    /** {@inheritDoc} */
262    public String getJavaClass() {
263      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
264    }
265
266
267
268    /** {@inheritDoc} */
269    public void setJavaClass(String value) {
270      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
271    }
272
273
274
275    /** {@inheritDoc} */
276    public SortedSet<PluginType> getPluginType() {
277      return impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition());
278    }
279
280
281
282    /** {@inheritDoc} */
283    public void setPluginType(Collection<PluginType> values) {
284      impl.setPropertyValues(INSTANCE.getPluginTypePropertyDefinition(), values);
285    }
286
287
288
289    /** {@inheritDoc} */
290    public ManagedObjectDefinition<? extends EntryUUIDPluginCfgClient, ? extends EntryUUIDPluginCfg> definition() {
291      return INSTANCE;
292    }
293
294
295
296    /** {@inheritDoc} */
297    public PropertyProvider properties() {
298      return impl;
299    }
300
301
302
303    /** {@inheritDoc} */
304    public void commit() throws ManagedObjectAlreadyExistsException,
305        MissingMandatoryPropertiesException, ConcurrentModificationException,
306        OperationRejectedException, LdapException {
307      impl.commit();
308    }
309
310
311
312    /** {@inheritDoc} */
313    public String toString() {
314      return impl.toString();
315    }
316  }
317
318
319
320  /**
321   * Managed object server implementation.
322   */
323  private static class EntryUUIDPluginCfgServerImpl implements
324    EntryUUIDPluginCfg {
325
326    /** Private implementation. */
327    private ServerManagedObject<? extends EntryUUIDPluginCfg> impl;
328
329    /** The value of the "enabled" property. */
330    private final boolean pEnabled;
331
332    /** The value of the "invoke-for-internal-operations" property. */
333    private final boolean pInvokeForInternalOperations;
334
335    /** The value of the "java-class" property. */
336    private final String pJavaClass;
337
338    /** The value of the "plugin-type" property. */
339    private final SortedSet<PluginType> pPluginType;
340
341
342
343    /** Private constructor. */
344    private EntryUUIDPluginCfgServerImpl(ServerManagedObject<? extends EntryUUIDPluginCfg> impl) {
345      this.impl = impl;
346      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
347      this.pInvokeForInternalOperations = impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition());
348      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
349      this.pPluginType = impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition());
350    }
351
352
353
354    /** {@inheritDoc} */
355    public void addEntryUUIDChangeListener(
356        ConfigurationChangeListener<EntryUUIDPluginCfg> listener) {
357      impl.registerChangeListener(listener);
358    }
359
360
361
362    /** {@inheritDoc} */
363    public void removeEntryUUIDChangeListener(
364        ConfigurationChangeListener<EntryUUIDPluginCfg> listener) {
365      impl.deregisterChangeListener(listener);
366    }
367    /** {@inheritDoc} */
368    public void addChangeListener(
369        ConfigurationChangeListener<PluginCfg> listener) {
370      impl.registerChangeListener(listener);
371    }
372
373
374
375    /** {@inheritDoc} */
376    public void removeChangeListener(
377        ConfigurationChangeListener<PluginCfg> listener) {
378      impl.deregisterChangeListener(listener);
379    }
380
381
382
383    /** {@inheritDoc} */
384    public boolean isEnabled() {
385      return pEnabled;
386    }
387
388
389
390    /** {@inheritDoc} */
391    public boolean isInvokeForInternalOperations() {
392      return pInvokeForInternalOperations;
393    }
394
395
396
397    /** {@inheritDoc} */
398    public String getJavaClass() {
399      return pJavaClass;
400    }
401
402
403
404    /** {@inheritDoc} */
405    public SortedSet<PluginType> getPluginType() {
406      return pPluginType;
407    }
408
409
410
411    /** {@inheritDoc} */
412    public Class<? extends EntryUUIDPluginCfg> configurationClass() {
413      return EntryUUIDPluginCfg.class;
414    }
415
416
417
418    /** {@inheritDoc} */
419    public DN dn() {
420      return impl.getDN();
421    }
422
423
424
425    /** {@inheritDoc} */
426    public String toString() {
427      return impl.toString();
428    }
429  }
430}