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  /**
145   * {@inheritDoc}
146   */
147  public LastModPluginCfgClient createClientConfiguration(
148      ManagedObject<? extends LastModPluginCfgClient> impl) {
149    return new LastModPluginCfgClientImpl(impl);
150  }
151
152
153
154  /**
155   * {@inheritDoc}
156   */
157  public LastModPluginCfg createServerConfiguration(
158      ServerManagedObject<? extends LastModPluginCfg> impl) {
159    return new LastModPluginCfgServerImpl(impl);
160  }
161
162
163
164  /**
165   * {@inheritDoc}
166   */
167  public Class<LastModPluginCfg> getServerConfigurationClass() {
168    return LastModPluginCfg.class;
169  }
170
171
172
173  /**
174   * Get the "enabled" property definition.
175   * <p>
176   * Indicates whether the plug-in is enabled for use.
177   *
178   * @return Returns the "enabled" property definition.
179   */
180  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
181    return PluginCfgDefn.getInstance().getEnabledPropertyDefinition();
182  }
183
184
185
186  /**
187   * Get the "invoke-for-internal-operations" property definition.
188   * <p>
189   * Indicates whether the plug-in should be invoked for internal
190   * operations.
191   * <p>
192   * Any plug-in that can be invoked for internal operations must
193   * ensure that it does not create any new internal operatons that can
194   * cause the same plug-in to be re-invoked.
195   *
196   * @return Returns the "invoke-for-internal-operations" property definition.
197   */
198  public BooleanPropertyDefinition getInvokeForInternalOperationsPropertyDefinition() {
199    return PluginCfgDefn.getInstance().getInvokeForInternalOperationsPropertyDefinition();
200  }
201
202
203
204  /**
205   * Get the "java-class" property definition.
206   * <p>
207   * Specifies the fully-qualified name of the Java class that
208   * provides the plug-in implementation.
209   *
210   * @return Returns the "java-class" property definition.
211   */
212  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
213    return PD_JAVA_CLASS;
214  }
215
216
217
218  /**
219   * Get the "plugin-type" property definition.
220   * <p>
221   * Specifies the set of plug-in types for the plug-in, which
222   * specifies the times at which the plug-in is invoked.
223   *
224   * @return Returns the "plugin-type" property definition.
225   */
226  public EnumPropertyDefinition<PluginType> getPluginTypePropertyDefinition() {
227    return PD_PLUGIN_TYPE;
228  }
229
230
231
232  /**
233   * Managed object client implementation.
234   */
235  private static class LastModPluginCfgClientImpl implements
236    LastModPluginCfgClient {
237
238    // Private implementation.
239    private ManagedObject<? extends LastModPluginCfgClient> impl;
240
241
242
243    // Private constructor.
244    private LastModPluginCfgClientImpl(
245        ManagedObject<? extends LastModPluginCfgClient> impl) {
246      this.impl = impl;
247    }
248
249
250
251    /**
252     * {@inheritDoc}
253     */
254    public Boolean isEnabled() {
255      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
256    }
257
258
259
260    /**
261     * {@inheritDoc}
262     */
263    public void setEnabled(boolean value) {
264      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
265    }
266
267
268
269    /**
270     * {@inheritDoc}
271     */
272    public boolean isInvokeForInternalOperations() {
273      return impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition());
274    }
275
276
277
278    /**
279     * {@inheritDoc}
280     */
281    public void setInvokeForInternalOperations(Boolean value) {
282      impl.setPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition(), value);
283    }
284
285
286
287    /**
288     * {@inheritDoc}
289     */
290    public String getJavaClass() {
291      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
292    }
293
294
295
296    /**
297     * {@inheritDoc}
298     */
299    public void setJavaClass(String value) {
300      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
301    }
302
303
304
305    /**
306     * {@inheritDoc}
307     */
308    public SortedSet<PluginType> getPluginType() {
309      return impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition());
310    }
311
312
313
314    /**
315     * {@inheritDoc}
316     */
317    public void setPluginType(Collection<PluginType> values) {
318      impl.setPropertyValues(INSTANCE.getPluginTypePropertyDefinition(), values);
319    }
320
321
322
323    /**
324     * {@inheritDoc}
325     */
326    public ManagedObjectDefinition<? extends LastModPluginCfgClient, ? extends LastModPluginCfg> definition() {
327      return INSTANCE;
328    }
329
330
331
332    /**
333     * {@inheritDoc}
334     */
335    public PropertyProvider properties() {
336      return impl;
337    }
338
339
340
341    /**
342     * {@inheritDoc}
343     */
344    public void commit() throws ManagedObjectAlreadyExistsException,
345        MissingMandatoryPropertiesException, ConcurrentModificationException,
346        OperationRejectedException, LdapException {
347      impl.commit();
348    }
349
350  }
351
352
353
354  /**
355   * Managed object server implementation.
356   */
357  private static class LastModPluginCfgServerImpl implements
358    LastModPluginCfg {
359
360    // Private implementation.
361    private ServerManagedObject<? extends LastModPluginCfg> 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 LastModPluginCfgServerImpl(ServerManagedObject<? extends LastModPluginCfg> 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 addLastModChangeListener(
392        ConfigurationChangeListener<LastModPluginCfg> listener) {
393      impl.registerChangeListener(listener);
394    }
395
396
397
398    /**
399     * {@inheritDoc}
400     */
401    public void removeLastModChangeListener(
402        ConfigurationChangeListener<LastModPluginCfg> 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 LastModPluginCfg> configurationClass() {
465      return LastModPluginCfg.class;
466    }
467
468
469
470    /**
471     * {@inheritDoc}
472     */
473    public DN dn() {
474      return impl.getDN();
475    }
476
477  }
478}