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