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 legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2008 Sun Microsystems, Inc.
025 */
026package org.forgerock.opendj.server.config.meta;
027
028
029
030import org.forgerock.opendj.config.AdministratorAction;
031import org.forgerock.opendj.config.BooleanPropertyDefinition;
032import org.forgerock.opendj.config.ClassPropertyDefinition;
033import org.forgerock.opendj.config.client.ConcurrentModificationException;
034import org.forgerock.opendj.config.client.ManagedObject;
035import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
036import org.forgerock.opendj.config.client.OperationRejectedException;
037import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
038import org.forgerock.opendj.config.ManagedObjectDefinition;
039import org.forgerock.opendj.config.PropertyOption;
040import org.forgerock.opendj.config.PropertyProvider;
041import org.forgerock.opendj.config.server.ConfigurationChangeListener;
042import org.forgerock.opendj.config.server.ServerManagedObject;
043import org.forgerock.opendj.config.TopCfgDefn;
044import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
045import org.forgerock.opendj.ldap.DN;
046import org.forgerock.opendj.ldap.LdapException;
047import org.forgerock.opendj.server.config.client.SchemaProviderCfgClient;
048import org.forgerock.opendj.server.config.server.SchemaProviderCfg;
049
050
051
052/**
053 * An interface for querying the Schema Provider managed object
054 * definition meta information.
055 * <p>
056 * Schema Providers define the schema elements to load.
057 */
058public final class SchemaProviderCfgDefn extends ManagedObjectDefinition<SchemaProviderCfgClient, SchemaProviderCfg> {
059
060  // The singleton configuration definition instance.
061  private static final SchemaProviderCfgDefn INSTANCE = new SchemaProviderCfgDefn();
062
063
064
065  // The "enabled" property definition.
066  private static final BooleanPropertyDefinition PD_ENABLED;
067
068
069
070  // The "java-class" property definition.
071  private static final ClassPropertyDefinition PD_JAVA_CLASS;
072
073
074
075  // Build the "enabled" property definition.
076  static {
077      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled");
078      builder.setOption(PropertyOption.MANDATORY);
079      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled"));
080      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
081      PD_ENABLED = builder.getInstance();
082      INSTANCE.registerPropertyDefinition(PD_ENABLED);
083  }
084
085
086
087  // Build the "java-class" property definition.
088  static {
089      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
090      builder.setOption(PropertyOption.MANDATORY);
091      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
092      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
093      builder.addInstanceOf("org.opends.server.schema.SchemaProvider");
094      PD_JAVA_CLASS = builder.getInstance();
095      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
096  }
097
098
099
100  /**
101   * Get the Schema Provider configuration definition singleton.
102   *
103   * @return Returns the Schema Provider configuration definition
104   *         singleton.
105   */
106  public static SchemaProviderCfgDefn getInstance() {
107    return INSTANCE;
108  }
109
110
111
112  /**
113   * Private constructor.
114   */
115  private SchemaProviderCfgDefn() {
116    super("schema-provider", TopCfgDefn.getInstance());
117  }
118
119
120
121  /**
122   * {@inheritDoc}
123   */
124  public SchemaProviderCfgClient createClientConfiguration(
125      ManagedObject<? extends SchemaProviderCfgClient> impl) {
126    return new SchemaProviderCfgClientImpl(impl);
127  }
128
129
130
131  /**
132   * {@inheritDoc}
133   */
134  public SchemaProviderCfg createServerConfiguration(
135      ServerManagedObject<? extends SchemaProviderCfg> impl) {
136    return new SchemaProviderCfgServerImpl(impl);
137  }
138
139
140
141  /**
142   * {@inheritDoc}
143   */
144  public Class<SchemaProviderCfg> getServerConfigurationClass() {
145    return SchemaProviderCfg.class;
146  }
147
148
149
150  /**
151   * Get the "enabled" property definition.
152   * <p>
153   * Indicates whether the Schema 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 Schema 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 SchemaProviderCfgClientImpl implements
181    SchemaProviderCfgClient {
182
183    // Private implementation.
184    private ManagedObject<? extends SchemaProviderCfgClient> impl;
185
186
187
188    // Private constructor.
189    private SchemaProviderCfgClientImpl(
190        ManagedObject<? extends SchemaProviderCfgClient> 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 SchemaProviderCfgClient, ? extends SchemaProviderCfg> 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, LdapException {
256      impl.commit();
257    }
258
259  }
260
261
262
263  /**
264   * Managed object server implementation.
265   */
266  private static class SchemaProviderCfgServerImpl implements
267    SchemaProviderCfg {
268
269    // Private implementation.
270    private ServerManagedObject<? extends SchemaProviderCfg> impl;
271
272    // The value of the "enabled" property.
273    private final boolean pEnabled;
274
275    // The value of the "java-class" property.
276    private final String pJavaClass;
277
278
279
280    // Private constructor.
281    private SchemaProviderCfgServerImpl(ServerManagedObject<? extends SchemaProviderCfg> impl) {
282      this.impl = impl;
283      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
284      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
285    }
286
287
288
289    /**
290     * {@inheritDoc}
291     */
292    public void addChangeListener(
293        ConfigurationChangeListener<SchemaProviderCfg> listener) {
294      impl.registerChangeListener(listener);
295    }
296
297
298
299    /**
300     * {@inheritDoc}
301     */
302    public void removeChangeListener(
303        ConfigurationChangeListener<SchemaProviderCfg> listener) {
304      impl.deregisterChangeListener(listener);
305    }
306
307
308
309    /**
310     * {@inheritDoc}
311     */
312    public boolean isEnabled() {
313      return pEnabled;
314    }
315
316
317
318    /**
319     * {@inheritDoc}
320     */
321    public String getJavaClass() {
322      return pJavaClass;
323    }
324
325
326
327    /**
328     * {@inheritDoc}
329     */
330    public Class<? extends SchemaProviderCfg> configurationClass() {
331      return SchemaProviderCfg.class;
332    }
333
334
335
336    /**
337     * {@inheritDoc}
338     */
339    public DN dn() {
340      return impl.getDN();
341    }
342
343  }
344}