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.ldap.DN;
054import org.forgerock.opendj.ldap.LdapException;
055import org.forgerock.opendj.server.config.client.NullBackendCfgClient;
056import org.forgerock.opendj.server.config.meta.BackendCfgDefn.WritabilityMode;
057import org.forgerock.opendj.server.config.server.BackendCfg;
058import org.forgerock.opendj.server.config.server.NullBackendCfg;
059
060
061
062/**
063 * An interface for querying the Null Backend managed object
064 * definition meta information.
065 * <p>
066 * The Null Backend provides a directory server backend that
067 * implements a /dev/null like behavior for development and testing.
068 */
069public final class NullBackendCfgDefn extends ManagedObjectDefinition<NullBackendCfgClient, NullBackendCfg> {
070
071  // The singleton configuration definition instance.
072  private static final NullBackendCfgDefn INSTANCE = new NullBackendCfgDefn();
073
074
075
076  // The "java-class" property definition.
077  private static final ClassPropertyDefinition PD_JAVA_CLASS;
078
079
080
081  // The "writability-mode" property definition.
082  private static final EnumPropertyDefinition<WritabilityMode> PD_WRITABILITY_MODE;
083
084
085
086  // Build the "java-class" property definition.
087  static {
088      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
089      builder.setOption(PropertyOption.MANDATORY);
090      builder.setOption(PropertyOption.ADVANCED);
091      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
092      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.backends.NullBackend");
093      builder.setDefaultBehaviorProvider(provider);
094      builder.addInstanceOf("org.opends.server.api.Backend");
095      PD_JAVA_CLASS = builder.getInstance();
096      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
097  }
098
099
100
101  // Build the "writability-mode" property definition.
102  static {
103      EnumPropertyDefinition.Builder<WritabilityMode> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "writability-mode");
104      builder.setOption(PropertyOption.MANDATORY);
105      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "writability-mode"));
106      DefaultBehaviorProvider<WritabilityMode> provider = new DefinedDefaultBehaviorProvider<WritabilityMode>("enabled");
107      builder.setDefaultBehaviorProvider(provider);
108      builder.setEnumClass(WritabilityMode.class);
109      PD_WRITABILITY_MODE = builder.getInstance();
110      INSTANCE.registerPropertyDefinition(PD_WRITABILITY_MODE);
111  }
112
113
114
115  // Register the options associated with this managed object definition.
116  static {
117    INSTANCE.registerOption(ManagedObjectOption.ADVANCED);
118  }
119
120
121
122  // Register the tags associated with this managed object definition.
123  static {
124    INSTANCE.registerTag(Tag.valueOf("database"));
125  }
126
127
128
129  /**
130   * Get the Null Backend configuration definition singleton.
131   *
132   * @return Returns the Null Backend configuration definition
133   *         singleton.
134   */
135  public static NullBackendCfgDefn getInstance() {
136    return INSTANCE;
137  }
138
139
140
141  /**
142   * Private constructor.
143   */
144  private NullBackendCfgDefn() {
145    super("null-backend", BackendCfgDefn.getInstance());
146  }
147
148
149
150  /**
151   * {@inheritDoc}
152   */
153  public NullBackendCfgClient createClientConfiguration(
154      ManagedObject<? extends NullBackendCfgClient> impl) {
155    return new NullBackendCfgClientImpl(impl);
156  }
157
158
159
160  /**
161   * {@inheritDoc}
162   */
163  public NullBackendCfg createServerConfiguration(
164      ServerManagedObject<? extends NullBackendCfg> impl) {
165    return new NullBackendCfgServerImpl(impl);
166  }
167
168
169
170  /**
171   * {@inheritDoc}
172   */
173  public Class<NullBackendCfg> getServerConfigurationClass() {
174    return NullBackendCfg.class;
175  }
176
177
178
179  /**
180   * Get the "backend-id" property definition.
181   * <p>
182   * Specifies a name to identify the associated backend.
183   * <p>
184   * The name must be unique among all backends in the server. The
185   * backend ID may not be altered after the backend is created in the
186   * server.
187   *
188   * @return Returns the "backend-id" property definition.
189   */
190  public StringPropertyDefinition getBackendIdPropertyDefinition() {
191    return BackendCfgDefn.getInstance().getBackendIdPropertyDefinition();
192  }
193
194
195
196  /**
197   * Get the "base-dn" property definition.
198   * <p>
199   * Specifies the base DN(s) for the data that the backend handles.
200   * <p>
201   * A single backend may be responsible for one or more base DNs.
202   * Note that no two backends may have the same base DN although one
203   * backend may have a base DN that is below a base DN provided by
204   * another backend (similar to the use of sub-suffixes in the Sun
205   * Java System Directory Server). If any of the base DNs is
206   * subordinate to a base DN for another backend, then all base DNs
207   * for that backend must be subordinate to that same base DN.
208   *
209   * @return Returns the "base-dn" property definition.
210   */
211  public DNPropertyDefinition getBaseDNPropertyDefinition() {
212    return BackendCfgDefn.getInstance().getBaseDNPropertyDefinition();
213  }
214
215
216
217  /**
218   * Get the "enabled" property definition.
219   * <p>
220   * Indicates whether the backend is enabled in the server.
221   * <p>
222   * If a backend is not enabled, then its contents are not accessible
223   * when processing operations.
224   *
225   * @return Returns the "enabled" property definition.
226   */
227  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
228    return BackendCfgDefn.getInstance().getEnabledPropertyDefinition();
229  }
230
231
232
233  /**
234   * Get the "java-class" property definition.
235   * <p>
236   * Specifies the fully-qualified name of the Java class that
237   * provides the backend implementation.
238   *
239   * @return Returns the "java-class" property definition.
240   */
241  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
242    return PD_JAVA_CLASS;
243  }
244
245
246
247  /**
248   * Get the "writability-mode" property definition.
249   * <p>
250   * Specifies the behavior that the backend should use when
251   * processing write operations.
252   *
253   * @return Returns the "writability-mode" property definition.
254   */
255  public EnumPropertyDefinition<WritabilityMode> getWritabilityModePropertyDefinition() {
256    return PD_WRITABILITY_MODE;
257  }
258
259
260
261  /**
262   * Managed object client implementation.
263   */
264  private static class NullBackendCfgClientImpl implements
265    NullBackendCfgClient {
266
267    // Private implementation.
268    private ManagedObject<? extends NullBackendCfgClient> impl;
269
270
271
272    // Private constructor.
273    private NullBackendCfgClientImpl(
274        ManagedObject<? extends NullBackendCfgClient> impl) {
275      this.impl = impl;
276    }
277
278
279
280    /**
281     * {@inheritDoc}
282     */
283    public String getBackendId() {
284      return impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition());
285    }
286
287
288
289    /**
290     * {@inheritDoc}
291     */
292    public void setBackendId(String value) throws PropertyException {
293      impl.setPropertyValue(INSTANCE.getBackendIdPropertyDefinition(), value);
294    }
295
296
297
298    /**
299     * {@inheritDoc}
300     */
301    public SortedSet<DN> getBaseDN() {
302      return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
303    }
304
305
306
307    /**
308     * {@inheritDoc}
309     */
310    public void setBaseDN(Collection<DN> values) {
311      impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values);
312    }
313
314
315
316    /**
317     * {@inheritDoc}
318     */
319    public Boolean isEnabled() {
320      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
321    }
322
323
324
325    /**
326     * {@inheritDoc}
327     */
328    public void setEnabled(boolean value) {
329      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
330    }
331
332
333
334    /**
335     * {@inheritDoc}
336     */
337    public String getJavaClass() {
338      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
339    }
340
341
342
343    /**
344     * {@inheritDoc}
345     */
346    public void setJavaClass(String value) {
347      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
348    }
349
350
351
352    /**
353     * {@inheritDoc}
354     */
355    public WritabilityMode getWritabilityMode() {
356      return impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition());
357    }
358
359
360
361    /**
362     * {@inheritDoc}
363     */
364    public void setWritabilityMode(WritabilityMode value) {
365      impl.setPropertyValue(INSTANCE.getWritabilityModePropertyDefinition(), value);
366    }
367
368
369
370    /**
371     * {@inheritDoc}
372     */
373    public ManagedObjectDefinition<? extends NullBackendCfgClient, ? extends NullBackendCfg> definition() {
374      return INSTANCE;
375    }
376
377
378
379    /**
380     * {@inheritDoc}
381     */
382    public PropertyProvider properties() {
383      return impl;
384    }
385
386
387
388    /**
389     * {@inheritDoc}
390     */
391    public void commit() throws ManagedObjectAlreadyExistsException,
392        MissingMandatoryPropertiesException, ConcurrentModificationException,
393        OperationRejectedException, LdapException {
394      impl.commit();
395    }
396
397  }
398
399
400
401  /**
402   * Managed object server implementation.
403   */
404  private static class NullBackendCfgServerImpl implements
405    NullBackendCfg {
406
407    // Private implementation.
408    private ServerManagedObject<? extends NullBackendCfg> impl;
409
410    // The value of the "backend-id" property.
411    private final String pBackendId;
412
413    // The value of the "base-dn" property.
414    private final SortedSet<DN> pBaseDN;
415
416    // The value of the "enabled" property.
417    private final boolean pEnabled;
418
419    // The value of the "java-class" property.
420    private final String pJavaClass;
421
422    // The value of the "writability-mode" property.
423    private final WritabilityMode pWritabilityMode;
424
425
426
427    // Private constructor.
428    private NullBackendCfgServerImpl(ServerManagedObject<? extends NullBackendCfg> impl) {
429      this.impl = impl;
430      this.pBackendId = impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition());
431      this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
432      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
433      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
434      this.pWritabilityMode = impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition());
435    }
436
437
438
439    /**
440     * {@inheritDoc}
441     */
442    public void addNullChangeListener(
443        ConfigurationChangeListener<NullBackendCfg> listener) {
444      impl.registerChangeListener(listener);
445    }
446
447
448
449    /**
450     * {@inheritDoc}
451     */
452    public void removeNullChangeListener(
453        ConfigurationChangeListener<NullBackendCfg> listener) {
454      impl.deregisterChangeListener(listener);
455    }
456    /**
457     * {@inheritDoc}
458     */
459    public void addChangeListener(
460        ConfigurationChangeListener<BackendCfg> listener) {
461      impl.registerChangeListener(listener);
462    }
463
464
465
466    /**
467     * {@inheritDoc}
468     */
469    public void removeChangeListener(
470        ConfigurationChangeListener<BackendCfg> listener) {
471      impl.deregisterChangeListener(listener);
472    }
473
474
475
476    /**
477     * {@inheritDoc}
478     */
479    public String getBackendId() {
480      return pBackendId;
481    }
482
483
484
485    /**
486     * {@inheritDoc}
487     */
488    public SortedSet<DN> getBaseDN() {
489      return pBaseDN;
490    }
491
492
493
494    /**
495     * {@inheritDoc}
496     */
497    public boolean isEnabled() {
498      return pEnabled;
499    }
500
501
502
503    /**
504     * {@inheritDoc}
505     */
506    public String getJavaClass() {
507      return pJavaClass;
508    }
509
510
511
512    /**
513     * {@inheritDoc}
514     */
515    public WritabilityMode getWritabilityMode() {
516      return pWritabilityMode;
517    }
518
519
520
521    /**
522     * {@inheritDoc}
523     */
524    public Class<? extends NullBackendCfg> configurationClass() {
525      return NullBackendCfg.class;
526    }
527
528
529
530    /**
531     * {@inheritDoc}
532     */
533    public DN dn() {
534      return impl.getDN();
535    }
536
537  }
538}