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