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