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