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