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.forgerock.opendj.server.config.meta;
017
018
019
020import java.util.Collection;
021import java.util.SortedSet;
022import org.forgerock.opendj.config.AdministratorAction;
023import org.forgerock.opendj.config.AliasDefaultBehaviorProvider;
024import org.forgerock.opendj.config.BooleanPropertyDefinition;
025import org.forgerock.opendj.config.ClassPropertyDefinition;
026import org.forgerock.opendj.config.client.ConcurrentModificationException;
027import org.forgerock.opendj.config.client.ManagedObject;
028import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
029import org.forgerock.opendj.config.client.OperationRejectedException;
030import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
031import org.forgerock.opendj.config.ManagedObjectDefinition;
032import org.forgerock.opendj.config.PropertyOption;
033import org.forgerock.opendj.config.PropertyProvider;
034import org.forgerock.opendj.config.server.ConfigurationChangeListener;
035import org.forgerock.opendj.config.server.ServerManagedObject;
036import org.forgerock.opendj.config.StringPropertyDefinition;
037import org.forgerock.opendj.config.Tag;
038import org.forgerock.opendj.config.TopCfgDefn;
039import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
040import org.forgerock.opendj.ldap.DN;
041import org.forgerock.opendj.ldap.LdapException;
042import org.forgerock.opendj.server.config.client.AlertHandlerCfgClient;
043import org.forgerock.opendj.server.config.server.AlertHandlerCfg;
044
045
046
047/**
048 * An interface for querying the Alert Handler managed object
049 * definition meta information.
050 * <p>
051 * Alert Handlers are used to notify administrators of significant
052 * problems or notable events that occur in the OpenDJ directory
053 * server.
054 */
055public final class AlertHandlerCfgDefn extends ManagedObjectDefinition<AlertHandlerCfgClient, AlertHandlerCfg> {
056
057  /** The singleton configuration definition instance. */
058  private static final AlertHandlerCfgDefn INSTANCE = new AlertHandlerCfgDefn();
059
060
061
062  /** The "disabled-alert-type" property definition. */
063  private static final StringPropertyDefinition PD_DISABLED_ALERT_TYPE;
064
065
066
067  /** The "enabled" property definition. */
068  private static final BooleanPropertyDefinition PD_ENABLED;
069
070
071
072  /** The "enabled-alert-type" property definition. */
073  private static final StringPropertyDefinition PD_ENABLED_ALERT_TYPE;
074
075
076
077  /** The "java-class" property definition. */
078  private static final ClassPropertyDefinition PD_JAVA_CLASS;
079
080
081
082  /** Build the "disabled-alert-type" property definition. */
083  static {
084      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "disabled-alert-type");
085      builder.setOption(PropertyOption.MULTI_VALUED);
086      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "disabled-alert-type"));
087      builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "disabled-alert-type"));
088      PD_DISABLED_ALERT_TYPE = builder.getInstance();
089      INSTANCE.registerPropertyDefinition(PD_DISABLED_ALERT_TYPE);
090  }
091
092
093
094  /** Build the "enabled" property definition. */
095  static {
096      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled");
097      builder.setOption(PropertyOption.MANDATORY);
098      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled"));
099      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
100      PD_ENABLED = builder.getInstance();
101      INSTANCE.registerPropertyDefinition(PD_ENABLED);
102  }
103
104
105
106  /** Build the "enabled-alert-type" property definition. */
107  static {
108      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "enabled-alert-type");
109      builder.setOption(PropertyOption.MULTI_VALUED);
110      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled-alert-type"));
111      builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "enabled-alert-type"));
112      PD_ENABLED_ALERT_TYPE = builder.getInstance();
113      INSTANCE.registerPropertyDefinition(PD_ENABLED_ALERT_TYPE);
114  }
115
116
117
118  /** Build the "java-class" property definition. */
119  static {
120      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
121      builder.setOption(PropertyOption.MANDATORY);
122      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
123      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
124      builder.addInstanceOf("org.opends.server.api.AlertHandler");
125      PD_JAVA_CLASS = builder.getInstance();
126      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
127  }
128
129
130
131  // Register the tags associated with this managed object definition.
132  static {
133    INSTANCE.registerTag(Tag.valueOf("core-server"));
134  }
135
136
137
138  /**
139   * Get the Alert Handler configuration definition singleton.
140   *
141   * @return Returns the Alert Handler configuration definition
142   *         singleton.
143   */
144  public static AlertHandlerCfgDefn getInstance() {
145    return INSTANCE;
146  }
147
148
149
150  /**
151   * Private constructor.
152   */
153  private AlertHandlerCfgDefn() {
154    super("alert-handler", TopCfgDefn.getInstance());
155  }
156
157
158
159  /** {@inheritDoc} */
160  public AlertHandlerCfgClient createClientConfiguration(
161      ManagedObject<? extends AlertHandlerCfgClient> impl) {
162    return new AlertHandlerCfgClientImpl(impl);
163  }
164
165
166
167  /** {@inheritDoc} */
168  public AlertHandlerCfg createServerConfiguration(
169      ServerManagedObject<? extends AlertHandlerCfg> impl) {
170    return new AlertHandlerCfgServerImpl(impl);
171  }
172
173
174
175  /** {@inheritDoc} */
176  public Class<AlertHandlerCfg> getServerConfigurationClass() {
177    return AlertHandlerCfg.class;
178  }
179
180
181
182  /**
183   * Get the "disabled-alert-type" property definition.
184   * <p>
185   * Specifies the names of the alert types that are disabled for this
186   * alert handler.
187   * <p>
188   * If there are any values for this attribute, then no alerts with
189   * any of the specified types are allowed. If there are no values for
190   * this attribute, then only alerts with a type included in the set
191   * of enabled alert types are allowed, or if there are no values for
192   * the enabled alert types option, then all alert types are allowed.
193   *
194   * @return Returns the "disabled-alert-type" property definition.
195   */
196  public StringPropertyDefinition getDisabledAlertTypePropertyDefinition() {
197    return PD_DISABLED_ALERT_TYPE;
198  }
199
200
201
202  /**
203   * Get the "enabled" property definition.
204   * <p>
205   * Indicates whether the Alert Handler is enabled.
206   *
207   * @return Returns the "enabled" property definition.
208   */
209  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
210    return PD_ENABLED;
211  }
212
213
214
215  /**
216   * Get the "enabled-alert-type" property definition.
217   * <p>
218   * Specifies the names of the alert types that are enabled for this
219   * alert handler.
220   * <p>
221   * If there are any values for this attribute, then only alerts with
222   * one of the specified types are allowed (unless they are also
223   * included in the disabled alert types). If there are no values for
224   * this attribute, then any alert with a type not included in the
225   * list of disabled alert types is allowed.
226   *
227   * @return Returns the "enabled-alert-type" property definition.
228   */
229  public StringPropertyDefinition getEnabledAlertTypePropertyDefinition() {
230    return PD_ENABLED_ALERT_TYPE;
231  }
232
233
234
235  /**
236   * Get the "java-class" property definition.
237   * <p>
238   * Specifies the fully-qualified name of the Java class that
239   * provides the Alert Handler implementation.
240   *
241   * @return Returns the "java-class" property definition.
242   */
243  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
244    return PD_JAVA_CLASS;
245  }
246
247
248
249  /**
250   * Managed object client implementation.
251   */
252  private static class AlertHandlerCfgClientImpl implements
253    AlertHandlerCfgClient {
254
255    /** Private implementation. */
256    private ManagedObject<? extends AlertHandlerCfgClient> impl;
257
258
259
260    /** Private constructor. */
261    private AlertHandlerCfgClientImpl(
262        ManagedObject<? extends AlertHandlerCfgClient> impl) {
263      this.impl = impl;
264    }
265
266
267
268    /** {@inheritDoc} */
269    public SortedSet<String> getDisabledAlertType() {
270      return impl.getPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition());
271    }
272
273
274
275    /** {@inheritDoc} */
276    public void setDisabledAlertType(Collection<String> values) {
277      impl.setPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition(), values);
278    }
279
280
281
282    /** {@inheritDoc} */
283    public Boolean isEnabled() {
284      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
285    }
286
287
288
289    /** {@inheritDoc} */
290    public void setEnabled(boolean value) {
291      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
292    }
293
294
295
296    /** {@inheritDoc} */
297    public SortedSet<String> getEnabledAlertType() {
298      return impl.getPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition());
299    }
300
301
302
303    /** {@inheritDoc} */
304    public void setEnabledAlertType(Collection<String> values) {
305      impl.setPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition(), values);
306    }
307
308
309
310    /** {@inheritDoc} */
311    public String getJavaClass() {
312      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
313    }
314
315
316
317    /** {@inheritDoc} */
318    public void setJavaClass(String value) {
319      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
320    }
321
322
323
324    /** {@inheritDoc} */
325    public ManagedObjectDefinition<? extends AlertHandlerCfgClient, ? extends AlertHandlerCfg> definition() {
326      return INSTANCE;
327    }
328
329
330
331    /** {@inheritDoc} */
332    public PropertyProvider properties() {
333      return impl;
334    }
335
336
337
338    /** {@inheritDoc} */
339    public void commit() throws ManagedObjectAlreadyExistsException,
340        MissingMandatoryPropertiesException, ConcurrentModificationException,
341        OperationRejectedException, LdapException {
342      impl.commit();
343    }
344
345
346
347    /** {@inheritDoc} */
348    public String toString() {
349      return impl.toString();
350    }
351  }
352
353
354
355  /**
356   * Managed object server implementation.
357   */
358  private static class AlertHandlerCfgServerImpl implements
359    AlertHandlerCfg {
360
361    /** Private implementation. */
362    private ServerManagedObject<? extends AlertHandlerCfg> impl;
363
364    /** The value of the "disabled-alert-type" property. */
365    private final SortedSet<String> pDisabledAlertType;
366
367    /** The value of the "enabled" property. */
368    private final boolean pEnabled;
369
370    /** The value of the "enabled-alert-type" property. */
371    private final SortedSet<String> pEnabledAlertType;
372
373    /** The value of the "java-class" property. */
374    private final String pJavaClass;
375
376
377
378    /** Private constructor. */
379    private AlertHandlerCfgServerImpl(ServerManagedObject<? extends AlertHandlerCfg> impl) {
380      this.impl = impl;
381      this.pDisabledAlertType = impl.getPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition());
382      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
383      this.pEnabledAlertType = impl.getPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition());
384      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
385    }
386
387
388
389    /** {@inheritDoc} */
390    public void addChangeListener(
391        ConfigurationChangeListener<AlertHandlerCfg> listener) {
392      impl.registerChangeListener(listener);
393    }
394
395
396
397    /** {@inheritDoc} */
398    public void removeChangeListener(
399        ConfigurationChangeListener<AlertHandlerCfg> listener) {
400      impl.deregisterChangeListener(listener);
401    }
402
403
404
405    /** {@inheritDoc} */
406    public SortedSet<String> getDisabledAlertType() {
407      return pDisabledAlertType;
408    }
409
410
411
412    /** {@inheritDoc} */
413    public boolean isEnabled() {
414      return pEnabled;
415    }
416
417
418
419    /** {@inheritDoc} */
420    public SortedSet<String> getEnabledAlertType() {
421      return pEnabledAlertType;
422    }
423
424
425
426    /** {@inheritDoc} */
427    public String getJavaClass() {
428      return pJavaClass;
429    }
430
431
432
433    /** {@inheritDoc} */
434    public Class<? extends AlertHandlerCfg> configurationClass() {
435      return AlertHandlerCfg.class;
436    }
437
438
439
440    /** {@inheritDoc} */
441    public DN dn() {
442      return impl.getDN();
443    }
444
445
446
447    /** {@inheritDoc} */
448    public String toString() {
449      return impl.toString();
450    }
451  }
452}