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