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.DefaultBehaviorProvider;
028import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
029import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
030import org.forgerock.opendj.config.ManagedObjectDefinition;
031import org.forgerock.opendj.config.PropertyException;
032import org.forgerock.opendj.config.PropertyOption;
033import org.forgerock.opendj.config.PropertyProvider;
034import org.forgerock.opendj.config.server.ConfigurationChangeListener;
035import org.forgerock.opendj.config.server.ServerManagedObject;
036import org.forgerock.opendj.config.Tag;
037import org.forgerock.opendj.ldap.DN;
038import org.forgerock.opendj.ldap.LdapException;
039import org.forgerock.opendj.server.config.client.CountryStringAttributeSyntaxCfgClient;
040import org.forgerock.opendj.server.config.server.AttributeSyntaxCfg;
041import org.forgerock.opendj.server.config.server.CountryStringAttributeSyntaxCfg;
042
043
044
045/**
046 * An interface for querying the Country String Attribute Syntax
047 * managed object definition meta information.
048 * <p>
049 * Country String Attribute Syntaxes define an attribute syntax for
050 * storing country codes.
051 */
052public final class CountryStringAttributeSyntaxCfgDefn extends ManagedObjectDefinition<CountryStringAttributeSyntaxCfgClient, CountryStringAttributeSyntaxCfg> {
053
054  /** The singleton configuration definition instance. */
055  private static final CountryStringAttributeSyntaxCfgDefn INSTANCE = new CountryStringAttributeSyntaxCfgDefn();
056
057
058
059  /** The "java-class" property definition. */
060  private static final ClassPropertyDefinition PD_JAVA_CLASS;
061
062
063
064  /** The "strict-format" property definition. */
065  private static final BooleanPropertyDefinition PD_STRICT_FORMAT;
066
067
068
069  /** Build the "java-class" property definition. */
070  static {
071      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
072      builder.setOption(PropertyOption.READ_ONLY);
073      builder.setOption(PropertyOption.MANDATORY);
074      builder.setOption(PropertyOption.ADVANCED);
075      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
076      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.schema.CountryStringSyntax");
077      builder.setDefaultBehaviorProvider(provider);
078      builder.addInstanceOf("org.opends.server.api.AttributeSyntax");
079      PD_JAVA_CLASS = builder.getInstance();
080      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
081  }
082
083
084
085  /** Build the "strict-format" property definition. */
086  static {
087      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "strict-format");
088      builder.setOption(PropertyOption.ADVANCED);
089      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "strict-format"));
090      DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("true");
091      builder.setDefaultBehaviorProvider(provider);
092      PD_STRICT_FORMAT = builder.getInstance();
093      INSTANCE.registerPropertyDefinition(PD_STRICT_FORMAT);
094  }
095
096
097
098  // Register the tags associated with this managed object definition.
099  static {
100    INSTANCE.registerTag(Tag.valueOf("core-server"));
101  }
102
103
104
105  /**
106   * Get the Country String Attribute Syntax configuration definition
107   * singleton.
108   *
109   * @return Returns the Country String Attribute Syntax configuration
110   *         definition singleton.
111   */
112  public static CountryStringAttributeSyntaxCfgDefn getInstance() {
113    return INSTANCE;
114  }
115
116
117
118  /**
119   * Private constructor.
120   */
121  private CountryStringAttributeSyntaxCfgDefn() {
122    super("country-string-attribute-syntax", AttributeSyntaxCfgDefn.getInstance());
123  }
124
125
126
127  /** {@inheritDoc} */
128  public CountryStringAttributeSyntaxCfgClient createClientConfiguration(
129      ManagedObject<? extends CountryStringAttributeSyntaxCfgClient> impl) {
130    return new CountryStringAttributeSyntaxCfgClientImpl(impl);
131  }
132
133
134
135  /** {@inheritDoc} */
136  public CountryStringAttributeSyntaxCfg createServerConfiguration(
137      ServerManagedObject<? extends CountryStringAttributeSyntaxCfg> impl) {
138    return new CountryStringAttributeSyntaxCfgServerImpl(impl);
139  }
140
141
142
143  /** {@inheritDoc} */
144  public Class<CountryStringAttributeSyntaxCfg> getServerConfigurationClass() {
145    return CountryStringAttributeSyntaxCfg.class;
146  }
147
148
149
150  /**
151   * Get the "enabled" property definition.
152   * <p>
153   * Indicates whether the Country String Attribute Syntax is enabled.
154   *
155   * @return Returns the "enabled" property definition.
156   */
157  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
158    return AttributeSyntaxCfgDefn.getInstance().getEnabledPropertyDefinition();
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 Country String Attribute Syntax 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   * Get the "strict-format" property definition.
179   * <p>
180   * Indicates whether country code values are required to strictly
181   * comply with the standard definition for this syntax.
182   * <p>
183   * When set to false, country codes will not be validated and, as a
184   * result any string containing 2 characters will be acceptable.
185   *
186   * @return Returns the "strict-format" property definition.
187   */
188  public BooleanPropertyDefinition getStrictFormatPropertyDefinition() {
189    return PD_STRICT_FORMAT;
190  }
191
192
193
194  /**
195   * Managed object client implementation.
196   */
197  private static class CountryStringAttributeSyntaxCfgClientImpl implements
198    CountryStringAttributeSyntaxCfgClient {
199
200    /** Private implementation. */
201    private ManagedObject<? extends CountryStringAttributeSyntaxCfgClient> impl;
202
203
204
205    /** Private constructor. */
206    private CountryStringAttributeSyntaxCfgClientImpl(
207        ManagedObject<? extends CountryStringAttributeSyntaxCfgClient> impl) {
208      this.impl = impl;
209    }
210
211
212
213    /** {@inheritDoc} */
214    public Boolean isEnabled() {
215      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
216    }
217
218
219
220    /** {@inheritDoc} */
221    public void setEnabled(boolean value) {
222      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
223    }
224
225
226
227    /** {@inheritDoc} */
228    public String getJavaClass() {
229      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
230    }
231
232
233
234    /** {@inheritDoc} */
235    public void setJavaClass(String value) throws PropertyException {
236      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
237    }
238
239
240
241    /** {@inheritDoc} */
242    public boolean isStrictFormat() {
243      return impl.getPropertyValue(INSTANCE.getStrictFormatPropertyDefinition());
244    }
245
246
247
248    /** {@inheritDoc} */
249    public void setStrictFormat(Boolean value) {
250      impl.setPropertyValue(INSTANCE.getStrictFormatPropertyDefinition(), value);
251    }
252
253
254
255    /** {@inheritDoc} */
256    public ManagedObjectDefinition<? extends CountryStringAttributeSyntaxCfgClient, ? extends CountryStringAttributeSyntaxCfg> definition() {
257      return INSTANCE;
258    }
259
260
261
262    /** {@inheritDoc} */
263    public PropertyProvider properties() {
264      return impl;
265    }
266
267
268
269    /** {@inheritDoc} */
270    public void commit() throws ManagedObjectAlreadyExistsException,
271        MissingMandatoryPropertiesException, ConcurrentModificationException,
272        OperationRejectedException, LdapException {
273      impl.commit();
274    }
275
276
277
278    /** {@inheritDoc} */
279    public String toString() {
280      return impl.toString();
281    }
282  }
283
284
285
286  /**
287   * Managed object server implementation.
288   */
289  private static class CountryStringAttributeSyntaxCfgServerImpl implements
290    CountryStringAttributeSyntaxCfg {
291
292    /** Private implementation. */
293    private ServerManagedObject<? extends CountryStringAttributeSyntaxCfg> impl;
294
295    /** The value of the "enabled" property. */
296    private final boolean pEnabled;
297
298    /** The value of the "java-class" property. */
299    private final String pJavaClass;
300
301    /** The value of the "strict-format" property. */
302    private final boolean pStrictFormat;
303
304
305
306    /** Private constructor. */
307    private CountryStringAttributeSyntaxCfgServerImpl(ServerManagedObject<? extends CountryStringAttributeSyntaxCfg> impl) {
308      this.impl = impl;
309      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
310      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
311      this.pStrictFormat = impl.getPropertyValue(INSTANCE.getStrictFormatPropertyDefinition());
312    }
313
314
315
316    /** {@inheritDoc} */
317    public void addCountryStringChangeListener(
318        ConfigurationChangeListener<CountryStringAttributeSyntaxCfg> listener) {
319      impl.registerChangeListener(listener);
320    }
321
322
323
324    /** {@inheritDoc} */
325    public void removeCountryStringChangeListener(
326        ConfigurationChangeListener<CountryStringAttributeSyntaxCfg> listener) {
327      impl.deregisterChangeListener(listener);
328    }
329    /** {@inheritDoc} */
330    public void addChangeListener(
331        ConfigurationChangeListener<AttributeSyntaxCfg> listener) {
332      impl.registerChangeListener(listener);
333    }
334
335
336
337    /** {@inheritDoc} */
338    public void removeChangeListener(
339        ConfigurationChangeListener<AttributeSyntaxCfg> listener) {
340      impl.deregisterChangeListener(listener);
341    }
342
343
344
345    /** {@inheritDoc} */
346    public boolean isEnabled() {
347      return pEnabled;
348    }
349
350
351
352    /** {@inheritDoc} */
353    public String getJavaClass() {
354      return pJavaClass;
355    }
356
357
358
359    /** {@inheritDoc} */
360    public boolean isStrictFormat() {
361      return pStrictFormat;
362    }
363
364
365
366    /** {@inheritDoc} */
367    public Class<? extends CountryStringAttributeSyntaxCfg> configurationClass() {
368      return CountryStringAttributeSyntaxCfg.class;
369    }
370
371
372
373    /** {@inheritDoc} */
374    public DN dn() {
375      return impl.getDN();
376    }
377
378
379
380    /** {@inheritDoc} */
381    public String toString() {
382      return impl.toString();
383    }
384  }
385}