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