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 java.util.Collection;
021import java.util.SortedSet;
022import org.forgerock.opendj.config.AdministratorAction;
023import org.forgerock.opendj.config.BooleanPropertyDefinition;
024import org.forgerock.opendj.config.ClassPropertyDefinition;
025import org.forgerock.opendj.config.client.ConcurrentModificationException;
026import org.forgerock.opendj.config.client.ManagedObject;
027import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
028import org.forgerock.opendj.config.client.OperationRejectedException;
029import org.forgerock.opendj.config.DefaultBehaviorProvider;
030import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
031import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
032import org.forgerock.opendj.config.ManagedObjectDefinition;
033import org.forgerock.opendj.config.PropertyOption;
034import org.forgerock.opendj.config.PropertyProvider;
035import org.forgerock.opendj.config.server.ConfigurationChangeListener;
036import org.forgerock.opendj.config.server.ServerManagedObject;
037import org.forgerock.opendj.config.StringPropertyDefinition;
038import org.forgerock.opendj.ldap.DN;
039import org.forgerock.opendj.ldap.LdapException;
040import org.forgerock.opendj.server.config.client.CoreSchemaCfgClient;
041import org.forgerock.opendj.server.config.server.CoreSchemaCfg;
042import org.forgerock.opendj.server.config.server.SchemaProviderCfg;
043
044
045
046/**
047 * An interface for querying the Core Schema managed object definition
048 * meta information.
049 * <p>
050 * Core Schema define the core schema elements to load.
051 */
052public final class CoreSchemaCfgDefn extends ManagedObjectDefinition<CoreSchemaCfgClient, CoreSchemaCfg> {
053
054  /** The singleton configuration definition instance. */
055  private static final CoreSchemaCfgDefn INSTANCE = new CoreSchemaCfgDefn();
056
057
058
059  /** The "allow-zero-length-values-directory-string" property definition. */
060  private static final BooleanPropertyDefinition PD_ALLOW_ZERO_LENGTH_VALUES_DIRECTORY_STRING;
061
062
063
064  /** The "disabled-matching-rule" property definition. */
065  private static final StringPropertyDefinition PD_DISABLED_MATCHING_RULE;
066
067
068
069  /** The "disabled-syntax" property definition. */
070  private static final StringPropertyDefinition PD_DISABLED_SYNTAX;
071
072
073
074  /** The "java-class" property definition. */
075  private static final ClassPropertyDefinition PD_JAVA_CLASS;
076
077
078
079  /** The "strict-format-country-string" property definition. */
080  private static final BooleanPropertyDefinition PD_STRICT_FORMAT_COUNTRY_STRING;
081
082
083
084  /** The "strip-syntax-min-upper-bound-attribute-type-description" property definition. */
085  private static final BooleanPropertyDefinition PD_STRIP_SYNTAX_MIN_UPPER_BOUND_ATTRIBUTE_TYPE_DESCRIPTION;
086
087
088
089  /** Build the "allow-zero-length-values-directory-string" property definition. */
090  static {
091      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "allow-zero-length-values-directory-string");
092      builder.setOption(PropertyOption.ADVANCED);
093      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "allow-zero-length-values-directory-string"));
094      DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false");
095      builder.setDefaultBehaviorProvider(provider);
096      PD_ALLOW_ZERO_LENGTH_VALUES_DIRECTORY_STRING = builder.getInstance();
097      INSTANCE.registerPropertyDefinition(PD_ALLOW_ZERO_LENGTH_VALUES_DIRECTORY_STRING);
098  }
099
100
101
102  /** Build the "disabled-matching-rule" property definition. */
103  static {
104      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "disabled-matching-rule");
105      builder.setOption(PropertyOption.MULTI_VALUED);
106      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "disabled-matching-rule"));
107      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("NONE");
108      builder.setDefaultBehaviorProvider(provider);
109      builder.setPattern("^([0-9.]+\\d|NONE)$", "OID");
110      PD_DISABLED_MATCHING_RULE = builder.getInstance();
111      INSTANCE.registerPropertyDefinition(PD_DISABLED_MATCHING_RULE);
112  }
113
114
115
116  /** Build the "disabled-syntax" property definition. */
117  static {
118      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "disabled-syntax");
119      builder.setOption(PropertyOption.MULTI_VALUED);
120      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "disabled-syntax"));
121      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("NONE");
122      builder.setDefaultBehaviorProvider(provider);
123      builder.setPattern("^([0-9.]+\\d|NONE)$", "OID");
124      PD_DISABLED_SYNTAX = builder.getInstance();
125      INSTANCE.registerPropertyDefinition(PD_DISABLED_SYNTAX);
126  }
127
128
129
130  /** Build the "java-class" property definition. */
131  static {
132      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
133      builder.setOption(PropertyOption.MANDATORY);
134      builder.setOption(PropertyOption.ADVANCED);
135      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
136      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.schema.CoreSchemaProvider");
137      builder.setDefaultBehaviorProvider(provider);
138      builder.addInstanceOf("org.opends.server.schema.SchemaProvider");
139      PD_JAVA_CLASS = builder.getInstance();
140      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
141  }
142
143
144
145  /** Build the "strict-format-country-string" property definition. */
146  static {
147      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "strict-format-country-string");
148      builder.setOption(PropertyOption.ADVANCED);
149      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "strict-format-country-string"));
150      DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("true");
151      builder.setDefaultBehaviorProvider(provider);
152      PD_STRICT_FORMAT_COUNTRY_STRING = builder.getInstance();
153      INSTANCE.registerPropertyDefinition(PD_STRICT_FORMAT_COUNTRY_STRING);
154  }
155
156
157
158  /** Build the "strip-syntax-min-upper-bound-attribute-type-description" property definition. */
159  static {
160      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "strip-syntax-min-upper-bound-attribute-type-description");
161      builder.setOption(PropertyOption.ADVANCED);
162      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "strip-syntax-min-upper-bound-attribute-type-description"));
163      DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false");
164      builder.setDefaultBehaviorProvider(provider);
165      PD_STRIP_SYNTAX_MIN_UPPER_BOUND_ATTRIBUTE_TYPE_DESCRIPTION = builder.getInstance();
166      INSTANCE.registerPropertyDefinition(PD_STRIP_SYNTAX_MIN_UPPER_BOUND_ATTRIBUTE_TYPE_DESCRIPTION);
167  }
168
169
170
171  /**
172   * Get the Core Schema configuration definition singleton.
173   *
174   * @return Returns the Core Schema configuration definition
175   *         singleton.
176   */
177  public static CoreSchemaCfgDefn getInstance() {
178    return INSTANCE;
179  }
180
181
182
183  /**
184   * Private constructor.
185   */
186  private CoreSchemaCfgDefn() {
187    super("core-schema", SchemaProviderCfgDefn.getInstance());
188  }
189
190
191
192  /** {@inheritDoc} */
193  public CoreSchemaCfgClient createClientConfiguration(
194      ManagedObject<? extends CoreSchemaCfgClient> impl) {
195    return new CoreSchemaCfgClientImpl(impl);
196  }
197
198
199
200  /** {@inheritDoc} */
201  public CoreSchemaCfg createServerConfiguration(
202      ServerManagedObject<? extends CoreSchemaCfg> impl) {
203    return new CoreSchemaCfgServerImpl(impl);
204  }
205
206
207
208  /** {@inheritDoc} */
209  public Class<CoreSchemaCfg> getServerConfigurationClass() {
210    return CoreSchemaCfg.class;
211  }
212
213
214
215  /**
216   * Get the "allow-zero-length-values-directory-string" property definition.
217   * <p>
218   * Indicates whether zero-length (that is, an empty string) values
219   * are allowed for directory string.
220   * <p>
221   * This is technically not allowed by the revised LDAPv3
222   * specification, but some environments may require it for backward
223   * compatibility with servers that do allow it.
224   *
225   * @return Returns the "allow-zero-length-values-directory-string" property definition.
226   */
227  public BooleanPropertyDefinition getAllowZeroLengthValuesDirectoryStringPropertyDefinition() {
228    return PD_ALLOW_ZERO_LENGTH_VALUES_DIRECTORY_STRING;
229  }
230
231
232
233  /**
234   * Get the "disabled-matching-rule" property definition.
235   * <p>
236   * The set of disabled matching rules.
237   * <p>
238   * Matching rules must be specified using the syntax: OID, or use
239   * the default value 'NONE' to specify no value.
240   *
241   * @return Returns the "disabled-matching-rule" property definition.
242   */
243  public StringPropertyDefinition getDisabledMatchingRulePropertyDefinition() {
244    return PD_DISABLED_MATCHING_RULE;
245  }
246
247
248
249  /**
250   * Get the "disabled-syntax" property definition.
251   * <p>
252   * The set of disabled syntaxes.
253   * <p>
254   * Syntaxes must be specified using the syntax: OID, or use the
255   * default value 'NONE' to specify no value.
256   *
257   * @return Returns the "disabled-syntax" property definition.
258   */
259  public StringPropertyDefinition getDisabledSyntaxPropertyDefinition() {
260    return PD_DISABLED_SYNTAX;
261  }
262
263
264
265  /**
266   * Get the "enabled" property definition.
267   * <p>
268   * Indicates whether the Core Schema is enabled for use.
269   *
270   * @return Returns the "enabled" property definition.
271   */
272  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
273    return SchemaProviderCfgDefn.getInstance().getEnabledPropertyDefinition();
274  }
275
276
277
278  /**
279   * Get the "java-class" property definition.
280   * <p>
281   * Specifies the fully-qualified name of the Java class that
282   * provides the Core Schema implementation.
283   *
284   * @return Returns the "java-class" property definition.
285   */
286  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
287    return PD_JAVA_CLASS;
288  }
289
290
291
292  /**
293   * Get the "strict-format-country-string" property definition.
294   * <p>
295   * Indicates whether country code values are required to strictly
296   * comply with the standard definition for this syntax.
297   * <p>
298   * When set to false, country codes will not be validated and, as a
299   * result any string containing 2 characters will be acceptable.
300   *
301   * @return Returns the "strict-format-country-string" property definition.
302   */
303  public BooleanPropertyDefinition getStrictFormatCountryStringPropertyDefinition() {
304    return PD_STRICT_FORMAT_COUNTRY_STRING;
305  }
306
307
308
309  /**
310   * Get the "strip-syntax-min-upper-bound-attribute-type-description" property definition.
311   * <p>
312   * Indicates whether the suggested minimum upper bound appended to
313   * an attribute's syntax OID in it's schema definition Attribute Type
314   * Description is stripped off.
315   * <p>
316   * When retrieving the server's schema, some APIs (JNDI) fail in
317   * their syntax lookup methods, because they do not parse this value
318   * correctly. This configuration option allows the server to be
319   * configured to provide schema definitions these APIs can parse
320   * correctly.
321   *
322   * @return Returns the "strip-syntax-min-upper-bound-attribute-type-description" property definition.
323   */
324  public BooleanPropertyDefinition getStripSyntaxMinUpperBoundAttributeTypeDescriptionPropertyDefinition() {
325    return PD_STRIP_SYNTAX_MIN_UPPER_BOUND_ATTRIBUTE_TYPE_DESCRIPTION;
326  }
327
328
329
330  /**
331   * Managed object client implementation.
332   */
333  private static class CoreSchemaCfgClientImpl implements
334    CoreSchemaCfgClient {
335
336    /** Private implementation. */
337    private ManagedObject<? extends CoreSchemaCfgClient> impl;
338
339
340
341    /** Private constructor. */
342    private CoreSchemaCfgClientImpl(
343        ManagedObject<? extends CoreSchemaCfgClient> impl) {
344      this.impl = impl;
345    }
346
347
348
349    /** {@inheritDoc} */
350    public boolean isAllowZeroLengthValuesDirectoryString() {
351      return impl.getPropertyValue(INSTANCE.getAllowZeroLengthValuesDirectoryStringPropertyDefinition());
352    }
353
354
355
356    /** {@inheritDoc} */
357    public void setAllowZeroLengthValuesDirectoryString(Boolean value) {
358      impl.setPropertyValue(INSTANCE.getAllowZeroLengthValuesDirectoryStringPropertyDefinition(), value);
359    }
360
361
362
363    /** {@inheritDoc} */
364    public SortedSet<String> getDisabledMatchingRule() {
365      return impl.getPropertyValues(INSTANCE.getDisabledMatchingRulePropertyDefinition());
366    }
367
368
369
370    /** {@inheritDoc} */
371    public void setDisabledMatchingRule(Collection<String> values) {
372      impl.setPropertyValues(INSTANCE.getDisabledMatchingRulePropertyDefinition(), values);
373    }
374
375
376
377    /** {@inheritDoc} */
378    public SortedSet<String> getDisabledSyntax() {
379      return impl.getPropertyValues(INSTANCE.getDisabledSyntaxPropertyDefinition());
380    }
381
382
383
384    /** {@inheritDoc} */
385    public void setDisabledSyntax(Collection<String> values) {
386      impl.setPropertyValues(INSTANCE.getDisabledSyntaxPropertyDefinition(), values);
387    }
388
389
390
391    /** {@inheritDoc} */
392    public Boolean isEnabled() {
393      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
394    }
395
396
397
398    /** {@inheritDoc} */
399    public void setEnabled(boolean value) {
400      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
401    }
402
403
404
405    /** {@inheritDoc} */
406    public String getJavaClass() {
407      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
408    }
409
410
411
412    /** {@inheritDoc} */
413    public void setJavaClass(String value) {
414      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
415    }
416
417
418
419    /** {@inheritDoc} */
420    public boolean isStrictFormatCountryString() {
421      return impl.getPropertyValue(INSTANCE.getStrictFormatCountryStringPropertyDefinition());
422    }
423
424
425
426    /** {@inheritDoc} */
427    public void setStrictFormatCountryString(Boolean value) {
428      impl.setPropertyValue(INSTANCE.getStrictFormatCountryStringPropertyDefinition(), value);
429    }
430
431
432
433    /** {@inheritDoc} */
434    public boolean isStripSyntaxMinUpperBoundAttributeTypeDescription() {
435      return impl.getPropertyValue(INSTANCE.getStripSyntaxMinUpperBoundAttributeTypeDescriptionPropertyDefinition());
436    }
437
438
439
440    /** {@inheritDoc} */
441    public void setStripSyntaxMinUpperBoundAttributeTypeDescription(Boolean value) {
442      impl.setPropertyValue(INSTANCE.getStripSyntaxMinUpperBoundAttributeTypeDescriptionPropertyDefinition(), value);
443    }
444
445
446
447    /** {@inheritDoc} */
448    public ManagedObjectDefinition<? extends CoreSchemaCfgClient, ? extends CoreSchemaCfg> definition() {
449      return INSTANCE;
450    }
451
452
453
454    /** {@inheritDoc} */
455    public PropertyProvider properties() {
456      return impl;
457    }
458
459
460
461    /** {@inheritDoc} */
462    public void commit() throws ManagedObjectAlreadyExistsException,
463        MissingMandatoryPropertiesException, ConcurrentModificationException,
464        OperationRejectedException, LdapException {
465      impl.commit();
466    }
467
468
469
470    /** {@inheritDoc} */
471    public String toString() {
472      return impl.toString();
473    }
474  }
475
476
477
478  /**
479   * Managed object server implementation.
480   */
481  private static class CoreSchemaCfgServerImpl implements
482    CoreSchemaCfg {
483
484    /** Private implementation. */
485    private ServerManagedObject<? extends CoreSchemaCfg> impl;
486
487    /** The value of the "allow-zero-length-values-directory-string" property. */
488    private final boolean pAllowZeroLengthValuesDirectoryString;
489
490    /** The value of the "disabled-matching-rule" property. */
491    private final SortedSet<String> pDisabledMatchingRule;
492
493    /** The value of the "disabled-syntax" property. */
494    private final SortedSet<String> pDisabledSyntax;
495
496    /** The value of the "enabled" property. */
497    private final boolean pEnabled;
498
499    /** The value of the "java-class" property. */
500    private final String pJavaClass;
501
502    /** The value of the "strict-format-country-string" property. */
503    private final boolean pStrictFormatCountryString;
504
505    /** The value of the "strip-syntax-min-upper-bound-attribute-type-description" property. */
506    private final boolean pStripSyntaxMinUpperBoundAttributeTypeDescription;
507
508
509
510    /** Private constructor. */
511    private CoreSchemaCfgServerImpl(ServerManagedObject<? extends CoreSchemaCfg> impl) {
512      this.impl = impl;
513      this.pAllowZeroLengthValuesDirectoryString = impl.getPropertyValue(INSTANCE.getAllowZeroLengthValuesDirectoryStringPropertyDefinition());
514      this.pDisabledMatchingRule = impl.getPropertyValues(INSTANCE.getDisabledMatchingRulePropertyDefinition());
515      this.pDisabledSyntax = impl.getPropertyValues(INSTANCE.getDisabledSyntaxPropertyDefinition());
516      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
517      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
518      this.pStrictFormatCountryString = impl.getPropertyValue(INSTANCE.getStrictFormatCountryStringPropertyDefinition());
519      this.pStripSyntaxMinUpperBoundAttributeTypeDescription = impl.getPropertyValue(INSTANCE.getStripSyntaxMinUpperBoundAttributeTypeDescriptionPropertyDefinition());
520    }
521
522
523
524    /** {@inheritDoc} */
525    public void addCoreSchemaChangeListener(
526        ConfigurationChangeListener<CoreSchemaCfg> listener) {
527      impl.registerChangeListener(listener);
528    }
529
530
531
532    /** {@inheritDoc} */
533    public void removeCoreSchemaChangeListener(
534        ConfigurationChangeListener<CoreSchemaCfg> listener) {
535      impl.deregisterChangeListener(listener);
536    }
537    /** {@inheritDoc} */
538    public void addChangeListener(
539        ConfigurationChangeListener<SchemaProviderCfg> listener) {
540      impl.registerChangeListener(listener);
541    }
542
543
544
545    /** {@inheritDoc} */
546    public void removeChangeListener(
547        ConfigurationChangeListener<SchemaProviderCfg> listener) {
548      impl.deregisterChangeListener(listener);
549    }
550
551
552
553    /** {@inheritDoc} */
554    public boolean isAllowZeroLengthValuesDirectoryString() {
555      return pAllowZeroLengthValuesDirectoryString;
556    }
557
558
559
560    /** {@inheritDoc} */
561    public SortedSet<String> getDisabledMatchingRule() {
562      return pDisabledMatchingRule;
563    }
564
565
566
567    /** {@inheritDoc} */
568    public SortedSet<String> getDisabledSyntax() {
569      return pDisabledSyntax;
570    }
571
572
573
574    /** {@inheritDoc} */
575    public boolean isEnabled() {
576      return pEnabled;
577    }
578
579
580
581    /** {@inheritDoc} */
582    public String getJavaClass() {
583      return pJavaClass;
584    }
585
586
587
588    /** {@inheritDoc} */
589    public boolean isStrictFormatCountryString() {
590      return pStrictFormatCountryString;
591    }
592
593
594
595    /** {@inheritDoc} */
596    public boolean isStripSyntaxMinUpperBoundAttributeTypeDescription() {
597      return pStripSyntaxMinUpperBoundAttributeTypeDescription;
598    }
599
600
601
602    /** {@inheritDoc} */
603    public Class<? extends CoreSchemaCfg> configurationClass() {
604      return CoreSchemaCfg.class;
605    }
606
607
608
609    /** {@inheritDoc} */
610    public DN dn() {
611      return impl.getDN();
612    }
613
614
615
616    /** {@inheritDoc} */
617    public String toString() {
618      return impl.toString();
619    }
620  }
621}