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 org.forgerock.opendj.config.AdministratorAction;
021import org.forgerock.opendj.config.BooleanPropertyDefinition;
022import org.forgerock.opendj.config.ClassPropertyDefinition;
023import org.forgerock.opendj.config.client.ConcurrentModificationException;
024import org.forgerock.opendj.config.client.ManagedObject;
025import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
026import org.forgerock.opendj.config.client.OperationRejectedException;
027import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
028import org.forgerock.opendj.config.ManagedObjectDefinition;
029import org.forgerock.opendj.config.PropertyOption;
030import org.forgerock.opendj.config.PropertyProvider;
031import org.forgerock.opendj.config.server.ConfigurationChangeListener;
032import org.forgerock.opendj.config.server.ServerManagedObject;
033import org.forgerock.opendj.config.Tag;
034import org.forgerock.opendj.config.TopCfgDefn;
035import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
036import org.forgerock.opendj.ldap.DN;
037import org.forgerock.opendj.ldap.LdapException;
038import org.forgerock.opendj.server.config.client.AccountStatusNotificationHandlerCfgClient;
039import org.forgerock.opendj.server.config.server.AccountStatusNotificationHandlerCfg;
040
041
042
043/**
044 * An interface for querying the Account Status Notification Handler
045 * managed object definition meta information.
046 * <p>
047 * Account Status Notification Handlers are invoked to provide
048 * notification to users in some form (for example, by an email
049 * message) when the status of a user's account has changed in some
050 * way. The Account Status Notification Handler can be used to notify
051 * the user and/or administrators of the change.
052 */
053public final class AccountStatusNotificationHandlerCfgDefn extends ManagedObjectDefinition<AccountStatusNotificationHandlerCfgClient, AccountStatusNotificationHandlerCfg> {
054
055  /** The singleton configuration definition instance. */
056  private static final AccountStatusNotificationHandlerCfgDefn INSTANCE = new AccountStatusNotificationHandlerCfgDefn();
057
058
059
060  /** The "enabled" property definition. */
061  private static final BooleanPropertyDefinition PD_ENABLED;
062
063
064
065  /** The "java-class" property definition. */
066  private static final ClassPropertyDefinition PD_JAVA_CLASS;
067
068
069
070  /** Build the "enabled" property definition. */
071  static {
072      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled");
073      builder.setOption(PropertyOption.MANDATORY);
074      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled"));
075      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
076      PD_ENABLED = builder.getInstance();
077      INSTANCE.registerPropertyDefinition(PD_ENABLED);
078  }
079
080
081
082  /** Build the "java-class" property definition. */
083  static {
084      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
085      builder.setOption(PropertyOption.MANDATORY);
086      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
087      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
088      builder.addInstanceOf("org.opends.server.api.AccountStatusNotificationHandler");
089      PD_JAVA_CLASS = builder.getInstance();
090      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
091  }
092
093
094
095  // Register the tags associated with this managed object definition.
096  static {
097    INSTANCE.registerTag(Tag.valueOf("user-management"));
098  }
099
100
101
102  /**
103   * Get the Account Status Notification Handler configuration
104   * definition singleton.
105   *
106   * @return Returns the Account Status Notification Handler
107   *         configuration definition singleton.
108   */
109  public static AccountStatusNotificationHandlerCfgDefn getInstance() {
110    return INSTANCE;
111  }
112
113
114
115  /**
116   * Private constructor.
117   */
118  private AccountStatusNotificationHandlerCfgDefn() {
119    super("account-status-notification-handler", TopCfgDefn.getInstance());
120  }
121
122
123
124  /** {@inheritDoc} */
125  public AccountStatusNotificationHandlerCfgClient createClientConfiguration(
126      ManagedObject<? extends AccountStatusNotificationHandlerCfgClient> impl) {
127    return new AccountStatusNotificationHandlerCfgClientImpl(impl);
128  }
129
130
131
132  /** {@inheritDoc} */
133  public AccountStatusNotificationHandlerCfg createServerConfiguration(
134      ServerManagedObject<? extends AccountStatusNotificationHandlerCfg> impl) {
135    return new AccountStatusNotificationHandlerCfgServerImpl(impl);
136  }
137
138
139
140  /** {@inheritDoc} */
141  public Class<AccountStatusNotificationHandlerCfg> getServerConfigurationClass() {
142    return AccountStatusNotificationHandlerCfg.class;
143  }
144
145
146
147  /**
148   * Get the "enabled" property definition.
149   * <p>
150   * Indicates whether the Account Status Notification Handler is
151   * enabled. Only enabled handlers are invoked whenever a related
152   * event occurs in the server.
153   *
154   * @return Returns the "enabled" property definition.
155   */
156  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
157    return PD_ENABLED;
158  }
159
160
161
162  /**
163   * Get the "java-class" property definition.
164   * <p>
165   * Specifies the fully-qualified name of the Java class that
166   * provides the Account Status Notification Handler implementation.
167   *
168   * @return Returns the "java-class" property definition.
169   */
170  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
171    return PD_JAVA_CLASS;
172  }
173
174
175
176  /**
177   * Managed object client implementation.
178   */
179  private static class AccountStatusNotificationHandlerCfgClientImpl implements
180    AccountStatusNotificationHandlerCfgClient {
181
182    /** Private implementation. */
183    private ManagedObject<? extends AccountStatusNotificationHandlerCfgClient> impl;
184
185
186
187    /** Private constructor. */
188    private AccountStatusNotificationHandlerCfgClientImpl(
189        ManagedObject<? extends AccountStatusNotificationHandlerCfgClient> impl) {
190      this.impl = impl;
191    }
192
193
194
195    /** {@inheritDoc} */
196    public Boolean isEnabled() {
197      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
198    }
199
200
201
202    /** {@inheritDoc} */
203    public void setEnabled(boolean value) {
204      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
205    }
206
207
208
209    /** {@inheritDoc} */
210    public String getJavaClass() {
211      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
212    }
213
214
215
216    /** {@inheritDoc} */
217    public void setJavaClass(String value) {
218      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
219    }
220
221
222
223    /** {@inheritDoc} */
224    public ManagedObjectDefinition<? extends AccountStatusNotificationHandlerCfgClient, ? extends AccountStatusNotificationHandlerCfg> definition() {
225      return INSTANCE;
226    }
227
228
229
230    /** {@inheritDoc} */
231    public PropertyProvider properties() {
232      return impl;
233    }
234
235
236
237    /** {@inheritDoc} */
238    public void commit() throws ManagedObjectAlreadyExistsException,
239        MissingMandatoryPropertiesException, ConcurrentModificationException,
240        OperationRejectedException, LdapException {
241      impl.commit();
242    }
243
244
245
246    /** {@inheritDoc} */
247    public String toString() {
248      return impl.toString();
249    }
250  }
251
252
253
254  /**
255   * Managed object server implementation.
256   */
257  private static class AccountStatusNotificationHandlerCfgServerImpl implements
258    AccountStatusNotificationHandlerCfg {
259
260    /** Private implementation. */
261    private ServerManagedObject<? extends AccountStatusNotificationHandlerCfg> impl;
262
263    /** The value of the "enabled" property. */
264    private final boolean pEnabled;
265
266    /** The value of the "java-class" property. */
267    private final String pJavaClass;
268
269
270
271    /** Private constructor. */
272    private AccountStatusNotificationHandlerCfgServerImpl(ServerManagedObject<? extends AccountStatusNotificationHandlerCfg> impl) {
273      this.impl = impl;
274      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
275      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
276    }
277
278
279
280    /** {@inheritDoc} */
281    public void addChangeListener(
282        ConfigurationChangeListener<AccountStatusNotificationHandlerCfg> listener) {
283      impl.registerChangeListener(listener);
284    }
285
286
287
288    /** {@inheritDoc} */
289    public void removeChangeListener(
290        ConfigurationChangeListener<AccountStatusNotificationHandlerCfg> listener) {
291      impl.deregisterChangeListener(listener);
292    }
293
294
295
296    /** {@inheritDoc} */
297    public boolean isEnabled() {
298      return pEnabled;
299    }
300
301
302
303    /** {@inheritDoc} */
304    public String getJavaClass() {
305      return pJavaClass;
306    }
307
308
309
310    /** {@inheritDoc} */
311    public Class<? extends AccountStatusNotificationHandlerCfg> configurationClass() {
312      return AccountStatusNotificationHandlerCfg.class;
313    }
314
315
316
317    /** {@inheritDoc} */
318    public DN dn() {
319      return impl.getDN();
320    }
321
322
323
324    /** {@inheritDoc} */
325    public String toString() {
326      return impl.toString();
327    }
328  }
329}