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