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