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 java.util.Collection;
031import java.util.SortedSet;
032import org.opends.server.admin.AdministratorAction;
033import org.opends.server.admin.BooleanPropertyDefinition;
034import org.opends.server.admin.ClassPropertyDefinition;
035import org.opends.server.admin.client.AuthorizationException;
036import org.opends.server.admin.client.CommunicationException;
037import org.opends.server.admin.client.ConcurrentModificationException;
038import org.opends.server.admin.client.ManagedObject;
039import org.opends.server.admin.client.MissingMandatoryPropertiesException;
040import org.opends.server.admin.client.OperationRejectedException;
041import org.opends.server.admin.DefaultBehaviorProvider;
042import org.opends.server.admin.DefinedDefaultBehaviorProvider;
043import org.opends.server.admin.DNPropertyDefinition;
044import org.opends.server.admin.EnumPropertyDefinition;
045import org.opends.server.admin.ManagedObjectAlreadyExistsException;
046import org.opends.server.admin.ManagedObjectDefinition;
047import org.opends.server.admin.ManagedObjectOption;
048import org.opends.server.admin.PropertyException;
049import org.opends.server.admin.PropertyOption;
050import org.opends.server.admin.PropertyProvider;
051import org.opends.server.admin.server.ConfigurationChangeListener;
052import org.opends.server.admin.server.ServerManagedObject;
053import org.opends.server.admin.std.client.SchemaBackendCfgClient;
054import org.opends.server.admin.std.meta.BackendCfgDefn.WritabilityMode;
055import org.opends.server.admin.std.server.BackendCfg;
056import org.opends.server.admin.std.server.SchemaBackendCfg;
057import org.opends.server.admin.StringPropertyDefinition;
058import org.opends.server.admin.Tag;
059import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
060import org.opends.server.types.DN;
061
062
063
064/**
065 * An interface for querying the Schema Backend managed object
066 * definition meta information.
067 * <p>
068 * The Schema Backend provides access to the directory server schema
069 * information, including the attribute types, object classes,
070 * attribute syntaxes, matching rules, matching rule uses, DIT content
071 * rules, and DIT structure rules that it contains.
072 */
073public final class SchemaBackendCfgDefn extends ManagedObjectDefinition<SchemaBackendCfgClient, SchemaBackendCfg> {
074
075  // The singleton configuration definition instance.
076  private static final SchemaBackendCfgDefn INSTANCE = new SchemaBackendCfgDefn();
077
078
079
080  // The "java-class" property definition.
081  private static final ClassPropertyDefinition PD_JAVA_CLASS;
082
083
084
085  // The "schema-entry-dn" property definition.
086  private static final DNPropertyDefinition PD_SCHEMA_ENTRY_DN;
087
088
089
090  // The "show-all-attributes" property definition.
091  private static final BooleanPropertyDefinition PD_SHOW_ALL_ATTRIBUTES;
092
093
094
095  // The "writability-mode" property definition.
096  private static final EnumPropertyDefinition<WritabilityMode> PD_WRITABILITY_MODE;
097
098
099
100  // Build the "java-class" property definition.
101  static {
102      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
103      builder.setOption(PropertyOption.MANDATORY);
104      builder.setOption(PropertyOption.ADVANCED);
105      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
106      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.backends.SchemaBackend");
107      builder.setDefaultBehaviorProvider(provider);
108      builder.addInstanceOf("org.opends.server.api.Backend");
109      PD_JAVA_CLASS = builder.getInstance();
110      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
111  }
112
113
114
115  // Build the "schema-entry-dn" property definition.
116  static {
117      DNPropertyDefinition.Builder builder = DNPropertyDefinition.createBuilder(INSTANCE, "schema-entry-dn");
118      builder.setOption(PropertyOption.MULTI_VALUED);
119      builder.setOption(PropertyOption.ADVANCED);
120      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "schema-entry-dn"));
121      DefaultBehaviorProvider<DN> provider = new DefinedDefaultBehaviorProvider<DN>("cn=schema");
122      builder.setDefaultBehaviorProvider(provider);
123      PD_SCHEMA_ENTRY_DN = builder.getInstance();
124      INSTANCE.registerPropertyDefinition(PD_SCHEMA_ENTRY_DN);
125  }
126
127
128
129  // Build the "show-all-attributes" property definition.
130  static {
131      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "show-all-attributes");
132      builder.setOption(PropertyOption.MANDATORY);
133      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "show-all-attributes"));
134      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
135      PD_SHOW_ALL_ATTRIBUTES = builder.getInstance();
136      INSTANCE.registerPropertyDefinition(PD_SHOW_ALL_ATTRIBUTES);
137  }
138
139
140
141  // Build the "writability-mode" property definition.
142  static {
143      EnumPropertyDefinition.Builder<WritabilityMode> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "writability-mode");
144      builder.setOption(PropertyOption.MANDATORY);
145      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "writability-mode"));
146      DefaultBehaviorProvider<WritabilityMode> provider = new DefinedDefaultBehaviorProvider<WritabilityMode>("enabled");
147      builder.setDefaultBehaviorProvider(provider);
148      builder.setEnumClass(WritabilityMode.class);
149      PD_WRITABILITY_MODE = builder.getInstance();
150      INSTANCE.registerPropertyDefinition(PD_WRITABILITY_MODE);
151  }
152
153
154
155  // Register the options associated with this managed object definition.
156  static {
157    INSTANCE.registerOption(ManagedObjectOption.ADVANCED);
158  }
159
160
161
162  // Register the tags associated with this managed object definition.
163  static {
164    INSTANCE.registerTag(Tag.valueOf("database"));
165  }
166
167
168
169  /**
170   * Get the Schema Backend configuration definition singleton.
171   *
172   * @return Returns the Schema Backend configuration definition
173   *         singleton.
174   */
175  public static SchemaBackendCfgDefn getInstance() {
176    return INSTANCE;
177  }
178
179
180
181  /**
182   * Private constructor.
183   */
184  private SchemaBackendCfgDefn() {
185    super("schema-backend", BackendCfgDefn.getInstance());
186  }
187
188
189
190  /**
191   * {@inheritDoc}
192   */
193  public SchemaBackendCfgClient createClientConfiguration(
194      ManagedObject<? extends SchemaBackendCfgClient> impl) {
195    return new SchemaBackendCfgClientImpl(impl);
196  }
197
198
199
200  /**
201   * {@inheritDoc}
202   */
203  public SchemaBackendCfg createServerConfiguration(
204      ServerManagedObject<? extends SchemaBackendCfg> impl) {
205    return new SchemaBackendCfgServerImpl(impl);
206  }
207
208
209
210  /**
211   * {@inheritDoc}
212   */
213  public Class<SchemaBackendCfg> getServerConfigurationClass() {
214    return SchemaBackendCfg.class;
215  }
216
217
218
219  /**
220   * Get the "backend-id" property definition.
221   * <p>
222   * Specifies a name to identify the associated backend.
223   * <p>
224   * The name must be unique among all backends in the server. The
225   * backend ID may not be altered after the backend is created in the
226   * server.
227   *
228   * @return Returns the "backend-id" property definition.
229   */
230  public StringPropertyDefinition getBackendIdPropertyDefinition() {
231    return BackendCfgDefn.getInstance().getBackendIdPropertyDefinition();
232  }
233
234
235
236  /**
237   * Get the "base-dn" property definition.
238   * <p>
239   * Specifies the base DN(s) for the data that the backend handles.
240   * <p>
241   * A single backend may be responsible for one or more base DNs.
242   * Note that no two backends may have the same base DN although one
243   * backend may have a base DN that is below a base DN provided by
244   * another backend (similar to the use of sub-suffixes in the Sun
245   * Java System Directory Server). If any of the base DNs is
246   * subordinate to a base DN for another backend, then all base DNs
247   * for that backend must be subordinate to that same base DN.
248   *
249   * @return Returns the "base-dn" property definition.
250   */
251  public DNPropertyDefinition getBaseDNPropertyDefinition() {
252    return BackendCfgDefn.getInstance().getBaseDNPropertyDefinition();
253  }
254
255
256
257  /**
258   * Get the "enabled" property definition.
259   * <p>
260   * Indicates whether the backend is enabled in the server.
261   * <p>
262   * If a backend is not enabled, then its contents are not accessible
263   * when processing operations.
264   *
265   * @return Returns the "enabled" property definition.
266   */
267  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
268    return BackendCfgDefn.getInstance().getEnabledPropertyDefinition();
269  }
270
271
272
273  /**
274   * Get the "java-class" property definition.
275   * <p>
276   * Specifies the fully-qualified name of the Java class that
277   * provides the backend implementation.
278   *
279   * @return Returns the "java-class" property definition.
280   */
281  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
282    return PD_JAVA_CLASS;
283  }
284
285
286
287  /**
288   * Get the "schema-entry-dn" property definition.
289   * <p>
290   * Defines the base DNs of the subtrees in which the schema
291   * information is published in addition to the value included in the
292   * base-dn property.
293   * <p>
294   * The value provided in the base-dn property is the only one that
295   * appears in the subschemaSubentry operational attribute of the
296   * server's root DSE (which is necessary because that is a
297   * single-valued attribute) and as a virtual attribute in other
298   * entries. The schema-entry-dn attribute may be used to make the
299   * schema information available in other locations to accommodate
300   * certain client applications that have been hard-coded to expect
301   * the schema to reside in a specific location.
302   *
303   * @return Returns the "schema-entry-dn" property definition.
304   */
305  public DNPropertyDefinition getSchemaEntryDNPropertyDefinition() {
306    return PD_SCHEMA_ENTRY_DN;
307  }
308
309
310
311  /**
312   * Get the "show-all-attributes" property definition.
313   * <p>
314   * Indicates whether to treat all attributes in the schema entry as
315   * if they were user attributes regardless of their configuration.
316   * <p>
317   * This may provide compatibility with some applications that expect
318   * schema attributes like attributeTypes and objectClasses to be
319   * included by default even if they are not requested. Note that the
320   * ldapSyntaxes attribute is always treated as operational in order
321   * to avoid problems with attempts to modify the schema over
322   * protocol.
323   *
324   * @return Returns the "show-all-attributes" property definition.
325   */
326  public BooleanPropertyDefinition getShowAllAttributesPropertyDefinition() {
327    return PD_SHOW_ALL_ATTRIBUTES;
328  }
329
330
331
332  /**
333   * Get the "writability-mode" property definition.
334   * <p>
335   * Specifies the behavior that the backend should use when
336   * processing write operations.
337   *
338   * @return Returns the "writability-mode" property definition.
339   */
340  public EnumPropertyDefinition<WritabilityMode> getWritabilityModePropertyDefinition() {
341    return PD_WRITABILITY_MODE;
342  }
343
344
345
346  /**
347   * Managed object client implementation.
348   */
349  private static class SchemaBackendCfgClientImpl implements
350    SchemaBackendCfgClient {
351
352    // Private implementation.
353    private ManagedObject<? extends SchemaBackendCfgClient> impl;
354
355
356
357    // Private constructor.
358    private SchemaBackendCfgClientImpl(
359        ManagedObject<? extends SchemaBackendCfgClient> impl) {
360      this.impl = impl;
361    }
362
363
364
365    /**
366     * {@inheritDoc}
367     */
368    public String getBackendId() {
369      return impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition());
370    }
371
372
373
374    /**
375     * {@inheritDoc}
376     */
377    public void setBackendId(String value) throws PropertyException {
378      impl.setPropertyValue(INSTANCE.getBackendIdPropertyDefinition(), value);
379    }
380
381
382
383    /**
384     * {@inheritDoc}
385     */
386    public SortedSet<DN> getBaseDN() {
387      return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
388    }
389
390
391
392    /**
393     * {@inheritDoc}
394     */
395    public void setBaseDN(Collection<DN> values) {
396      impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values);
397    }
398
399
400
401    /**
402     * {@inheritDoc}
403     */
404    public Boolean isEnabled() {
405      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
406    }
407
408
409
410    /**
411     * {@inheritDoc}
412     */
413    public void setEnabled(boolean value) {
414      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
415    }
416
417
418
419    /**
420     * {@inheritDoc}
421     */
422    public String getJavaClass() {
423      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
424    }
425
426
427
428    /**
429     * {@inheritDoc}
430     */
431    public void setJavaClass(String value) {
432      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
433    }
434
435
436
437    /**
438     * {@inheritDoc}
439     */
440    public SortedSet<DN> getSchemaEntryDN() {
441      return impl.getPropertyValues(INSTANCE.getSchemaEntryDNPropertyDefinition());
442    }
443
444
445
446    /**
447     * {@inheritDoc}
448     */
449    public void setSchemaEntryDN(Collection<DN> values) {
450      impl.setPropertyValues(INSTANCE.getSchemaEntryDNPropertyDefinition(), values);
451    }
452
453
454
455    /**
456     * {@inheritDoc}
457     */
458    public Boolean isShowAllAttributes() {
459      return impl.getPropertyValue(INSTANCE.getShowAllAttributesPropertyDefinition());
460    }
461
462
463
464    /**
465     * {@inheritDoc}
466     */
467    public void setShowAllAttributes(boolean value) {
468      impl.setPropertyValue(INSTANCE.getShowAllAttributesPropertyDefinition(), value);
469    }
470
471
472
473    /**
474     * {@inheritDoc}
475     */
476    public WritabilityMode getWritabilityMode() {
477      return impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition());
478    }
479
480
481
482    /**
483     * {@inheritDoc}
484     */
485    public void setWritabilityMode(WritabilityMode value) {
486      impl.setPropertyValue(INSTANCE.getWritabilityModePropertyDefinition(), value);
487    }
488
489
490
491    /**
492     * {@inheritDoc}
493     */
494    public ManagedObjectDefinition<? extends SchemaBackendCfgClient, ? extends SchemaBackendCfg> 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, AuthorizationException,
515        CommunicationException {
516      impl.commit();
517    }
518
519
520
521    /** {@inheritDoc} */
522    public String toString() {
523      return impl.toString();
524    }
525  }
526
527
528
529  /**
530   * Managed object server implementation.
531   */
532  private static class SchemaBackendCfgServerImpl implements
533    SchemaBackendCfg {
534
535    // Private implementation.
536    private ServerManagedObject<? extends SchemaBackendCfg> impl;
537
538    // The value of the "backend-id" property.
539    private final String pBackendId;
540
541    // The value of the "base-dn" property.
542    private final SortedSet<DN> pBaseDN;
543
544    // The value of the "enabled" property.
545    private final boolean pEnabled;
546
547    // The value of the "java-class" property.
548    private final String pJavaClass;
549
550    // The value of the "schema-entry-dn" property.
551    private final SortedSet<DN> pSchemaEntryDN;
552
553    // The value of the "show-all-attributes" property.
554    private final boolean pShowAllAttributes;
555
556    // The value of the "writability-mode" property.
557    private final WritabilityMode pWritabilityMode;
558
559
560
561    // Private constructor.
562    private SchemaBackendCfgServerImpl(ServerManagedObject<? extends SchemaBackendCfg> impl) {
563      this.impl = impl;
564      this.pBackendId = impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition());
565      this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
566      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
567      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
568      this.pSchemaEntryDN = impl.getPropertyValues(INSTANCE.getSchemaEntryDNPropertyDefinition());
569      this.pShowAllAttributes = impl.getPropertyValue(INSTANCE.getShowAllAttributesPropertyDefinition());
570      this.pWritabilityMode = impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition());
571    }
572
573
574
575    /**
576     * {@inheritDoc}
577     */
578    public void addSchemaChangeListener(
579        ConfigurationChangeListener<SchemaBackendCfg> listener) {
580      impl.registerChangeListener(listener);
581    }
582
583
584
585    /**
586     * {@inheritDoc}
587     */
588    public void removeSchemaChangeListener(
589        ConfigurationChangeListener<SchemaBackendCfg> listener) {
590      impl.deregisterChangeListener(listener);
591    }
592    /**
593     * {@inheritDoc}
594     */
595    public void addChangeListener(
596        ConfigurationChangeListener<BackendCfg> listener) {
597      impl.registerChangeListener(listener);
598    }
599
600
601
602    /**
603     * {@inheritDoc}
604     */
605    public void removeChangeListener(
606        ConfigurationChangeListener<BackendCfg> listener) {
607      impl.deregisterChangeListener(listener);
608    }
609
610
611
612    /**
613     * {@inheritDoc}
614     */
615    public String getBackendId() {
616      return pBackendId;
617    }
618
619
620
621    /**
622     * {@inheritDoc}
623     */
624    public SortedSet<DN> getBaseDN() {
625      return pBaseDN;
626    }
627
628
629
630    /**
631     * {@inheritDoc}
632     */
633    public boolean isEnabled() {
634      return pEnabled;
635    }
636
637
638
639    /**
640     * {@inheritDoc}
641     */
642    public String getJavaClass() {
643      return pJavaClass;
644    }
645
646
647
648    /**
649     * {@inheritDoc}
650     */
651    public SortedSet<DN> getSchemaEntryDN() {
652      return pSchemaEntryDN;
653    }
654
655
656
657    /**
658     * {@inheritDoc}
659     */
660    public boolean isShowAllAttributes() {
661      return pShowAllAttributes;
662    }
663
664
665
666    /**
667     * {@inheritDoc}
668     */
669    public WritabilityMode getWritabilityMode() {
670      return pWritabilityMode;
671    }
672
673
674
675    /**
676     * {@inheritDoc}
677     */
678    public Class<? extends SchemaBackendCfg> configurationClass() {
679      return SchemaBackendCfg.class;
680    }
681
682
683
684    /**
685     * {@inheritDoc}
686     */
687    public DN dn() {
688      return impl.getDN();
689    }
690
691
692
693    /** {@inheritDoc} */
694    public String toString() {
695      return impl.toString();
696    }
697  }
698}