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