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