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