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