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