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