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