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