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