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  /**
138   * {@inheritDoc}
139   */
140  public CountryStringAttributeSyntaxCfgClient createClientConfiguration(
141      ManagedObject<? extends CountryStringAttributeSyntaxCfgClient> impl) {
142    return new CountryStringAttributeSyntaxCfgClientImpl(impl);
143  }
144
145
146
147  /**
148   * {@inheritDoc}
149   */
150  public CountryStringAttributeSyntaxCfg createServerConfiguration(
151      ServerManagedObject<? extends CountryStringAttributeSyntaxCfg> impl) {
152    return new CountryStringAttributeSyntaxCfgServerImpl(impl);
153  }
154
155
156
157  /**
158   * {@inheritDoc}
159   */
160  public Class<CountryStringAttributeSyntaxCfg> getServerConfigurationClass() {
161    return CountryStringAttributeSyntaxCfg.class;
162  }
163
164
165
166  /**
167   * Get the "enabled" property definition.
168   * <p>
169   * Indicates whether the Country String Attribute Syntax is enabled.
170   *
171   * @return Returns the "enabled" property definition.
172   */
173  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
174    return AttributeSyntaxCfgDefn.getInstance().getEnabledPropertyDefinition();
175  }
176
177
178
179  /**
180   * Get the "java-class" property definition.
181   * <p>
182   * Specifies the fully-qualified name of the Java class that
183   * provides the Country String Attribute Syntax implementation.
184   *
185   * @return Returns the "java-class" property definition.
186   */
187  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
188    return PD_JAVA_CLASS;
189  }
190
191
192
193  /**
194   * Get the "strict-format" property definition.
195   * <p>
196   * Indicates whether or not country code values are required to
197   * strictly comply with the standard definition for this syntax.
198   * <p>
199   * When set to false, country codes will not be validated and, as a
200   * result any string containing 2 characters will be acceptable.
201   *
202   * @return Returns the "strict-format" property definition.
203   */
204  public BooleanPropertyDefinition getStrictFormatPropertyDefinition() {
205    return PD_STRICT_FORMAT;
206  }
207
208
209
210  /**
211   * Managed object client implementation.
212   */
213  private static class CountryStringAttributeSyntaxCfgClientImpl implements
214    CountryStringAttributeSyntaxCfgClient {
215
216    // Private implementation.
217    private ManagedObject<? extends CountryStringAttributeSyntaxCfgClient> impl;
218
219
220
221    // Private constructor.
222    private CountryStringAttributeSyntaxCfgClientImpl(
223        ManagedObject<? extends CountryStringAttributeSyntaxCfgClient> impl) {
224      this.impl = impl;
225    }
226
227
228
229    /**
230     * {@inheritDoc}
231     */
232    public Boolean isEnabled() {
233      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
234    }
235
236
237
238    /**
239     * {@inheritDoc}
240     */
241    public void setEnabled(boolean value) {
242      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
243    }
244
245
246
247    /**
248     * {@inheritDoc}
249     */
250    public String getJavaClass() {
251      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
252    }
253
254
255
256    /**
257     * {@inheritDoc}
258     */
259    public void setJavaClass(String value) throws PropertyException {
260      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
261    }
262
263
264
265    /**
266     * {@inheritDoc}
267     */
268    public boolean isStrictFormat() {
269      return impl.getPropertyValue(INSTANCE.getStrictFormatPropertyDefinition());
270    }
271
272
273
274    /**
275     * {@inheritDoc}
276     */
277    public void setStrictFormat(Boolean value) {
278      impl.setPropertyValue(INSTANCE.getStrictFormatPropertyDefinition(), value);
279    }
280
281
282
283    /**
284     * {@inheritDoc}
285     */
286    public ManagedObjectDefinition<? extends CountryStringAttributeSyntaxCfgClient, ? extends CountryStringAttributeSyntaxCfg> definition() {
287      return INSTANCE;
288    }
289
290
291
292    /**
293     * {@inheritDoc}
294     */
295    public PropertyProvider properties() {
296      return impl;
297    }
298
299
300
301    /**
302     * {@inheritDoc}
303     */
304    public void commit() throws ManagedObjectAlreadyExistsException,
305        MissingMandatoryPropertiesException, ConcurrentModificationException,
306        OperationRejectedException, LdapException {
307      impl.commit();
308    }
309
310  }
311
312
313
314  /**
315   * Managed object server implementation.
316   */
317  private static class CountryStringAttributeSyntaxCfgServerImpl implements
318    CountryStringAttributeSyntaxCfg {
319
320    // Private implementation.
321    private ServerManagedObject<? extends CountryStringAttributeSyntaxCfg> impl;
322
323    // The value of the "enabled" property.
324    private final boolean pEnabled;
325
326    // The value of the "java-class" property.
327    private final String pJavaClass;
328
329    // The value of the "strict-format" property.
330    private final boolean pStrictFormat;
331
332
333
334    // Private constructor.
335    private CountryStringAttributeSyntaxCfgServerImpl(ServerManagedObject<? extends CountryStringAttributeSyntaxCfg> impl) {
336      this.impl = impl;
337      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
338      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
339      this.pStrictFormat = impl.getPropertyValue(INSTANCE.getStrictFormatPropertyDefinition());
340    }
341
342
343
344    /**
345     * {@inheritDoc}
346     */
347    public void addCountryStringChangeListener(
348        ConfigurationChangeListener<CountryStringAttributeSyntaxCfg> listener) {
349      impl.registerChangeListener(listener);
350    }
351
352
353
354    /**
355     * {@inheritDoc}
356     */
357    public void removeCountryStringChangeListener(
358        ConfigurationChangeListener<CountryStringAttributeSyntaxCfg> listener) {
359      impl.deregisterChangeListener(listener);
360    }
361    /**
362     * {@inheritDoc}
363     */
364    public void addChangeListener(
365        ConfigurationChangeListener<AttributeSyntaxCfg> listener) {
366      impl.registerChangeListener(listener);
367    }
368
369
370
371    /**
372     * {@inheritDoc}
373     */
374    public void removeChangeListener(
375        ConfigurationChangeListener<AttributeSyntaxCfg> listener) {
376      impl.deregisterChangeListener(listener);
377    }
378
379
380
381    /**
382     * {@inheritDoc}
383     */
384    public boolean isEnabled() {
385      return pEnabled;
386    }
387
388
389
390    /**
391     * {@inheritDoc}
392     */
393    public String getJavaClass() {
394      return pJavaClass;
395    }
396
397
398
399    /**
400     * {@inheritDoc}
401     */
402    public boolean isStrictFormat() {
403      return pStrictFormat;
404    }
405
406
407
408    /**
409     * {@inheritDoc}
410     */
411    public Class<? extends CountryStringAttributeSyntaxCfg> configurationClass() {
412      return CountryStringAttributeSyntaxCfg.class;
413    }
414
415
416
417    /**
418     * {@inheritDoc}
419     */
420    public DN dn() {
421      return impl.getDN();
422    }
423
424  }
425}