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    /** {@inheritDoc} */
355    public String toString() {
356      return impl.toString();
357    }
358  }
359
360
361
362  /**
363   * Managed object server implementation.
364   */
365  private static class LastModPluginCfgServerImpl implements
366    LastModPluginCfg {
367
368    // Private implementation.
369    private ServerManagedObject<? extends LastModPluginCfg> impl;
370
371    // The value of the "enabled" property.
372    private final boolean pEnabled;
373
374    // The value of the "invoke-for-internal-operations" property.
375    private final boolean pInvokeForInternalOperations;
376
377    // The value of the "java-class" property.
378    private final String pJavaClass;
379
380    // The value of the "plugin-type" property.
381    private final SortedSet<PluginType> pPluginType;
382
383
384
385    // Private constructor.
386    private LastModPluginCfgServerImpl(ServerManagedObject<? extends LastModPluginCfg> impl) {
387      this.impl = impl;
388      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
389      this.pInvokeForInternalOperations = impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition());
390      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
391      this.pPluginType = impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition());
392    }
393
394
395
396    /**
397     * {@inheritDoc}
398     */
399    public void addLastModChangeListener(
400        ConfigurationChangeListener<LastModPluginCfg> listener) {
401      impl.registerChangeListener(listener);
402    }
403
404
405
406    /**
407     * {@inheritDoc}
408     */
409    public void removeLastModChangeListener(
410        ConfigurationChangeListener<LastModPluginCfg> listener) {
411      impl.deregisterChangeListener(listener);
412    }
413    /**
414     * {@inheritDoc}
415     */
416    public void addChangeListener(
417        ConfigurationChangeListener<PluginCfg> listener) {
418      impl.registerChangeListener(listener);
419    }
420
421
422
423    /**
424     * {@inheritDoc}
425     */
426    public void removeChangeListener(
427        ConfigurationChangeListener<PluginCfg> listener) {
428      impl.deregisterChangeListener(listener);
429    }
430
431
432
433    /**
434     * {@inheritDoc}
435     */
436    public boolean isEnabled() {
437      return pEnabled;
438    }
439
440
441
442    /**
443     * {@inheritDoc}
444     */
445    public boolean isInvokeForInternalOperations() {
446      return pInvokeForInternalOperations;
447    }
448
449
450
451    /**
452     * {@inheritDoc}
453     */
454    public String getJavaClass() {
455      return pJavaClass;
456    }
457
458
459
460    /**
461     * {@inheritDoc}
462     */
463    public SortedSet<PluginType> getPluginType() {
464      return pPluginType;
465    }
466
467
468
469    /**
470     * {@inheritDoc}
471     */
472    public Class<? extends LastModPluginCfg> configurationClass() {
473      return LastModPluginCfg.class;
474    }
475
476
477
478    /**
479     * {@inheritDoc}
480     */
481    public DN dn() {
482      return impl.getDN();
483    }
484
485
486
487    /** {@inheritDoc} */
488    public String toString() {
489      return impl.toString();
490    }
491  }
492}