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.opends.server.admin.std.meta;
017
018
019
020import java.util.Collection;
021import java.util.SortedSet;
022import org.forgerock.opendj.ldap.DN;
023import org.opends.server.admin.AdministratorAction;
024import org.opends.server.admin.BooleanPropertyDefinition;
025import org.opends.server.admin.ClassPropertyDefinition;
026import org.opends.server.admin.client.AuthorizationException;
027import org.opends.server.admin.client.CommunicationException;
028import org.opends.server.admin.client.ConcurrentModificationException;
029import org.opends.server.admin.client.ManagedObject;
030import org.opends.server.admin.client.MissingMandatoryPropertiesException;
031import org.opends.server.admin.client.OperationRejectedException;
032import org.opends.server.admin.DefaultBehaviorProvider;
033import org.opends.server.admin.DefinedDefaultBehaviorProvider;
034import org.opends.server.admin.EnumPropertyDefinition;
035import org.opends.server.admin.ManagedObjectAlreadyExistsException;
036import org.opends.server.admin.ManagedObjectDefinition;
037import org.opends.server.admin.PropertyOption;
038import org.opends.server.admin.PropertyProvider;
039import org.opends.server.admin.server.ConfigurationChangeListener;
040import org.opends.server.admin.server.ServerManagedObject;
041import org.opends.server.admin.std.client.LastModPluginCfgClient;
042import org.opends.server.admin.std.meta.PluginCfgDefn.PluginType;
043import org.opends.server.admin.std.server.LastModPluginCfg;
044import org.opends.server.admin.std.server.PluginCfg;
045import org.opends.server.admin.Tag;
046
047
048
049/**
050 * An interface for querying the Last Mod Plugin managed object
051 * definition meta information.
052 * <p>
053 * The Last Mod Plugin is used to ensure that the creatorsName and
054 * createTimestamp attributes are included in an entry whenever it is
055 * added to the server and also to ensure that the modifiersName and
056 * modifyTimestamp attributes are updated whenever an entry is modified
057 * or renamed.
058 */
059public final class LastModPluginCfgDefn extends ManagedObjectDefinition<LastModPluginCfgClient, LastModPluginCfg> {
060
061  // The singleton configuration definition instance.
062  private static final LastModPluginCfgDefn INSTANCE = new LastModPluginCfgDefn();
063
064
065
066  // The "java-class" property definition.
067  private static final ClassPropertyDefinition PD_JAVA_CLASS;
068
069
070
071  // The "plugin-type" property definition.
072  private static final EnumPropertyDefinition<PluginType> PD_PLUGIN_TYPE;
073
074
075
076  // Build the "java-class" property definition.
077  static {
078      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
079      builder.setOption(PropertyOption.MANDATORY);
080      builder.setOption(PropertyOption.ADVANCED);
081      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
082      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.plugins.LastModPlugin");
083      builder.setDefaultBehaviorProvider(provider);
084      builder.addInstanceOf("org.opends.server.api.plugin.DirectoryServerPlugin");
085      PD_JAVA_CLASS = builder.getInstance();
086      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
087  }
088
089
090
091  // Build the "plugin-type" property definition.
092  static {
093      EnumPropertyDefinition.Builder<PluginType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "plugin-type");
094      builder.setOption(PropertyOption.MULTI_VALUED);
095      builder.setOption(PropertyOption.MANDATORY);
096      builder.setOption(PropertyOption.ADVANCED);
097      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "plugin-type"));
098      DefaultBehaviorProvider<PluginType> provider = new DefinedDefaultBehaviorProvider<PluginType>("preoperationadd", "preoperationmodify", "preoperationmodifydn");
099      builder.setDefaultBehaviorProvider(provider);
100      builder.setEnumClass(PluginType.class);
101      PD_PLUGIN_TYPE = builder.getInstance();
102      INSTANCE.registerPropertyDefinition(PD_PLUGIN_TYPE);
103  }
104
105
106
107  // Register the tags associated with this managed object definition.
108  static {
109    INSTANCE.registerTag(Tag.valueOf("core-server"));
110  }
111
112
113
114  /**
115   * Get the Last Mod Plugin configuration definition singleton.
116   *
117   * @return Returns the Last Mod Plugin configuration definition
118   *         singleton.
119   */
120  public static LastModPluginCfgDefn getInstance() {
121    return INSTANCE;
122  }
123
124
125
126  /**
127   * Private constructor.
128   */
129  private LastModPluginCfgDefn() {
130    super("last-mod-plugin", PluginCfgDefn.getInstance());
131  }
132
133
134
135  /**
136   * {@inheritDoc}
137   */
138  public LastModPluginCfgClient createClientConfiguration(
139      ManagedObject<? extends LastModPluginCfgClient> impl) {
140    return new LastModPluginCfgClientImpl(impl);
141  }
142
143
144
145  /**
146   * {@inheritDoc}
147   */
148  public LastModPluginCfg createServerConfiguration(
149      ServerManagedObject<? extends LastModPluginCfg> impl) {
150    return new LastModPluginCfgServerImpl(impl);
151  }
152
153
154
155  /**
156   * {@inheritDoc}
157   */
158  public Class<LastModPluginCfg> getServerConfigurationClass() {
159    return LastModPluginCfg.class;
160  }
161
162
163
164  /**
165   * Get the "enabled" property definition.
166   * <p>
167   * Indicates whether the plug-in is enabled for use.
168   *
169   * @return Returns the "enabled" property definition.
170   */
171  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
172    return PluginCfgDefn.getInstance().getEnabledPropertyDefinition();
173  }
174
175
176
177  /**
178   * Get the "invoke-for-internal-operations" property definition.
179   * <p>
180   * Indicates whether the plug-in should be invoked for internal
181   * operations.
182   * <p>
183   * Any plug-in that can be invoked for internal operations must
184   * ensure that it does not create any new internal operatons that can
185   * cause the same plug-in to be re-invoked.
186   *
187   * @return Returns the "invoke-for-internal-operations" property definition.
188   */
189  public BooleanPropertyDefinition getInvokeForInternalOperationsPropertyDefinition() {
190    return PluginCfgDefn.getInstance().getInvokeForInternalOperationsPropertyDefinition();
191  }
192
193
194
195  /**
196   * Get the "java-class" property definition.
197   * <p>
198   * Specifies the fully-qualified name of the Java class that
199   * provides the plug-in implementation.
200   *
201   * @return Returns the "java-class" property definition.
202   */
203  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
204    return PD_JAVA_CLASS;
205  }
206
207
208
209  /**
210   * Get the "plugin-type" property definition.
211   * <p>
212   * Specifies the set of plug-in types for the plug-in, which
213   * specifies the times at which the plug-in is invoked.
214   *
215   * @return Returns the "plugin-type" property definition.
216   */
217  public EnumPropertyDefinition<PluginType> getPluginTypePropertyDefinition() {
218    return PD_PLUGIN_TYPE;
219  }
220
221
222
223  /**
224   * Managed object client implementation.
225   */
226  private static class LastModPluginCfgClientImpl implements
227    LastModPluginCfgClient {
228
229    // Private implementation.
230    private ManagedObject<? extends LastModPluginCfgClient> impl;
231
232
233
234    // Private constructor.
235    private LastModPluginCfgClientImpl(
236        ManagedObject<? extends LastModPluginCfgClient> impl) {
237      this.impl = impl;
238    }
239
240
241
242    /**
243     * {@inheritDoc}
244     */
245    public Boolean isEnabled() {
246      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
247    }
248
249
250
251    /**
252     * {@inheritDoc}
253     */
254    public void setEnabled(boolean value) {
255      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
256    }
257
258
259
260    /**
261     * {@inheritDoc}
262     */
263    public boolean isInvokeForInternalOperations() {
264      return impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition());
265    }
266
267
268
269    /**
270     * {@inheritDoc}
271     */
272    public void setInvokeForInternalOperations(Boolean value) {
273      impl.setPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition(), value);
274    }
275
276
277
278    /**
279     * {@inheritDoc}
280     */
281    public String getJavaClass() {
282      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
283    }
284
285
286
287    /**
288     * {@inheritDoc}
289     */
290    public void setJavaClass(String value) {
291      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
292    }
293
294
295
296    /**
297     * {@inheritDoc}
298     */
299    public SortedSet<PluginType> getPluginType() {
300      return impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition());
301    }
302
303
304
305    /**
306     * {@inheritDoc}
307     */
308    public void setPluginType(Collection<PluginType> values) {
309      impl.setPropertyValues(INSTANCE.getPluginTypePropertyDefinition(), values);
310    }
311
312
313
314    /**
315     * {@inheritDoc}
316     */
317    public ManagedObjectDefinition<? extends LastModPluginCfgClient, ? extends LastModPluginCfg> definition() {
318      return INSTANCE;
319    }
320
321
322
323    /**
324     * {@inheritDoc}
325     */
326    public PropertyProvider properties() {
327      return impl;
328    }
329
330
331
332    /**
333     * {@inheritDoc}
334     */
335    public void commit() throws ManagedObjectAlreadyExistsException,
336        MissingMandatoryPropertiesException, ConcurrentModificationException,
337        OperationRejectedException, AuthorizationException,
338        CommunicationException {
339      impl.commit();
340    }
341
342
343
344    /** {@inheritDoc} */
345    public String toString() {
346      return impl.toString();
347    }
348  }
349
350
351
352  /**
353   * Managed object server implementation.
354   */
355  private static class LastModPluginCfgServerImpl implements
356    LastModPluginCfg {
357
358    // Private implementation.
359    private ServerManagedObject<? extends LastModPluginCfg> 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 LastModPluginCfgServerImpl(ServerManagedObject<? extends LastModPluginCfg> 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 addLastModChangeListener(
390        ConfigurationChangeListener<LastModPluginCfg> listener) {
391      impl.registerChangeListener(listener);
392    }
393
394
395
396    /**
397     * {@inheritDoc}
398     */
399    public void removeLastModChangeListener(
400        ConfigurationChangeListener<LastModPluginCfg> 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 LastModPluginCfg> configurationClass() {
463      return LastModPluginCfg.class;
464    }
465
466
467
468    /**
469     * {@inheritDoc}
470     */
471    public DN dn() {
472      return impl.getDN();
473    }
474
475
476
477    /** {@inheritDoc} */
478    public String toString() {
479      return impl.toString();
480    }
481  }
482}