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.opends.server.admin.std.meta;
027
028
029
030import java.util.Collection;
031import java.util.SortedSet;
032import org.opends.server.admin.AdministratorAction;
033import org.opends.server.admin.BooleanPropertyDefinition;
034import org.opends.server.admin.ClassPropertyDefinition;
035import org.opends.server.admin.client.AuthorizationException;
036import org.opends.server.admin.client.CommunicationException;
037import org.opends.server.admin.client.ConcurrentModificationException;
038import org.opends.server.admin.client.ManagedObject;
039import org.opends.server.admin.client.MissingMandatoryPropertiesException;
040import org.opends.server.admin.client.OperationRejectedException;
041import org.opends.server.admin.DefaultBehaviorProvider;
042import org.opends.server.admin.DefinedDefaultBehaviorProvider;
043import org.opends.server.admin.DNPropertyDefinition;
044import org.opends.server.admin.EnumPropertyDefinition;
045import org.opends.server.admin.ManagedObjectAlreadyExistsException;
046import org.opends.server.admin.ManagedObjectDefinition;
047import org.opends.server.admin.PropertyException;
048import org.opends.server.admin.PropertyOption;
049import org.opends.server.admin.PropertyProvider;
050import org.opends.server.admin.server.ConfigurationChangeListener;
051import org.opends.server.admin.server.ServerManagedObject;
052import org.opends.server.admin.std.client.MemoryBackendCfgClient;
053import org.opends.server.admin.std.meta.BackendCfgDefn.WritabilityMode;
054import org.opends.server.admin.std.server.BackendCfg;
055import org.opends.server.admin.std.server.MemoryBackendCfg;
056import org.opends.server.admin.StringPropertyDefinition;
057import org.opends.server.admin.Tag;
058import org.opends.server.types.DN;
059
060
061
062/**
063 * An interface for querying the Memory Backend managed object
064 * definition meta information.
065 * <p>
066 * The Memory Backend provides a directory server backend
067 * implementation that stores entries in memory.
068 */
069public final class MemoryBackendCfgDefn extends ManagedObjectDefinition<MemoryBackendCfgClient, MemoryBackendCfg> {
070
071  // The singleton configuration definition instance.
072  private static final MemoryBackendCfgDefn INSTANCE = new MemoryBackendCfgDefn();
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.MemoryBackend");
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 tags associated with this managed object definition.
116  static {
117    INSTANCE.registerTag(Tag.valueOf("database"));
118  }
119
120
121
122  /**
123   * Get the Memory Backend configuration definition singleton.
124   *
125   * @return Returns the Memory Backend configuration definition
126   *         singleton.
127   */
128  public static MemoryBackendCfgDefn getInstance() {
129    return INSTANCE;
130  }
131
132
133
134  /**
135   * Private constructor.
136   */
137  private MemoryBackendCfgDefn() {
138    super("memory-backend", BackendCfgDefn.getInstance());
139  }
140
141
142
143  /**
144   * {@inheritDoc}
145   */
146  public MemoryBackendCfgClient createClientConfiguration(
147      ManagedObject<? extends MemoryBackendCfgClient> impl) {
148    return new MemoryBackendCfgClientImpl(impl);
149  }
150
151
152
153  /**
154   * {@inheritDoc}
155   */
156  public MemoryBackendCfg createServerConfiguration(
157      ServerManagedObject<? extends MemoryBackendCfg> impl) {
158    return new MemoryBackendCfgServerImpl(impl);
159  }
160
161
162
163  /**
164   * {@inheritDoc}
165   */
166  public Class<MemoryBackendCfg> getServerConfigurationClass() {
167    return MemoryBackendCfg.class;
168  }
169
170
171
172  /**
173   * Get the "backend-id" property definition.
174   * <p>
175   * Specifies a name to identify the associated backend.
176   * <p>
177   * The name must be unique among all backends in the server. The
178   * backend ID may not be altered after the backend is created in the
179   * server.
180   *
181   * @return Returns the "backend-id" property definition.
182   */
183  public StringPropertyDefinition getBackendIdPropertyDefinition() {
184    return BackendCfgDefn.getInstance().getBackendIdPropertyDefinition();
185  }
186
187
188
189  /**
190   * Get the "base-dn" property definition.
191   * <p>
192   * Specifies the base DN(s) for the data that the backend handles.
193   * <p>
194   * A single backend may be responsible for one or more base DNs.
195   * Note that no two backends may have the same base DN although one
196   * backend may have a base DN that is below a base DN provided by
197   * another backend (similar to the use of sub-suffixes in the Sun
198   * Java System Directory Server). If any of the base DNs is
199   * subordinate to a base DN for another backend, then all base DNs
200   * for that backend must be subordinate to that same base DN.
201   *
202   * @return Returns the "base-dn" property definition.
203   */
204  public DNPropertyDefinition getBaseDNPropertyDefinition() {
205    return BackendCfgDefn.getInstance().getBaseDNPropertyDefinition();
206  }
207
208
209
210  /**
211   * Get the "enabled" property definition.
212   * <p>
213   * Indicates whether the backend is enabled in the server.
214   * <p>
215   * If a backend is not enabled, then its contents are not accessible
216   * when processing operations.
217   *
218   * @return Returns the "enabled" property definition.
219   */
220  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
221    return BackendCfgDefn.getInstance().getEnabledPropertyDefinition();
222  }
223
224
225
226  /**
227   * Get the "java-class" property definition.
228   * <p>
229   * Specifies the fully-qualified name of the Java class that
230   * provides the backend implementation.
231   *
232   * @return Returns the "java-class" property definition.
233   */
234  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
235    return PD_JAVA_CLASS;
236  }
237
238
239
240  /**
241   * Get the "writability-mode" property definition.
242   * <p>
243   * Specifies the behavior that the backend should use when
244   * processing write operations.
245   *
246   * @return Returns the "writability-mode" property definition.
247   */
248  public EnumPropertyDefinition<WritabilityMode> getWritabilityModePropertyDefinition() {
249    return PD_WRITABILITY_MODE;
250  }
251
252
253
254  /**
255   * Managed object client implementation.
256   */
257  private static class MemoryBackendCfgClientImpl implements
258    MemoryBackendCfgClient {
259
260    // Private implementation.
261    private ManagedObject<? extends MemoryBackendCfgClient> impl;
262
263
264
265    // Private constructor.
266    private MemoryBackendCfgClientImpl(
267        ManagedObject<? extends MemoryBackendCfgClient> impl) {
268      this.impl = impl;
269    }
270
271
272
273    /**
274     * {@inheritDoc}
275     */
276    public String getBackendId() {
277      return impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition());
278    }
279
280
281
282    /**
283     * {@inheritDoc}
284     */
285    public void setBackendId(String value) throws PropertyException {
286      impl.setPropertyValue(INSTANCE.getBackendIdPropertyDefinition(), value);
287    }
288
289
290
291    /**
292     * {@inheritDoc}
293     */
294    public SortedSet<DN> getBaseDN() {
295      return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
296    }
297
298
299
300    /**
301     * {@inheritDoc}
302     */
303    public void setBaseDN(Collection<DN> values) {
304      impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values);
305    }
306
307
308
309    /**
310     * {@inheritDoc}
311     */
312    public Boolean isEnabled() {
313      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
314    }
315
316
317
318    /**
319     * {@inheritDoc}
320     */
321    public void setEnabled(boolean value) {
322      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
323    }
324
325
326
327    /**
328     * {@inheritDoc}
329     */
330    public String getJavaClass() {
331      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
332    }
333
334
335
336    /**
337     * {@inheritDoc}
338     */
339    public void setJavaClass(String value) {
340      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
341    }
342
343
344
345    /**
346     * {@inheritDoc}
347     */
348    public WritabilityMode getWritabilityMode() {
349      return impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition());
350    }
351
352
353
354    /**
355     * {@inheritDoc}
356     */
357    public void setWritabilityMode(WritabilityMode value) {
358      impl.setPropertyValue(INSTANCE.getWritabilityModePropertyDefinition(), value);
359    }
360
361
362
363    /**
364     * {@inheritDoc}
365     */
366    public ManagedObjectDefinition<? extends MemoryBackendCfgClient, ? extends MemoryBackendCfg> definition() {
367      return INSTANCE;
368    }
369
370
371
372    /**
373     * {@inheritDoc}
374     */
375    public PropertyProvider properties() {
376      return impl;
377    }
378
379
380
381    /**
382     * {@inheritDoc}
383     */
384    public void commit() throws ManagedObjectAlreadyExistsException,
385        MissingMandatoryPropertiesException, ConcurrentModificationException,
386        OperationRejectedException, AuthorizationException,
387        CommunicationException {
388      impl.commit();
389    }
390
391
392
393    /** {@inheritDoc} */
394    public String toString() {
395      return impl.toString();
396    }
397  }
398
399
400
401  /**
402   * Managed object server implementation.
403   */
404  private static class MemoryBackendCfgServerImpl implements
405    MemoryBackendCfg {
406
407    // Private implementation.
408    private ServerManagedObject<? extends MemoryBackendCfg> 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 MemoryBackendCfgServerImpl(ServerManagedObject<? extends MemoryBackendCfg> 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 addMemoryChangeListener(
443        ConfigurationChangeListener<MemoryBackendCfg> listener) {
444      impl.registerChangeListener(listener);
445    }
446
447
448
449    /**
450     * {@inheritDoc}
451     */
452    public void removeMemoryChangeListener(
453        ConfigurationChangeListener<MemoryBackendCfg> 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 MemoryBackendCfg> configurationClass() {
525      return MemoryBackendCfg.class;
526    }
527
528
529
530    /**
531     * {@inheritDoc}
532     */
533    public DN dn() {
534      return impl.getDN();
535    }
536
537
538
539    /** {@inheritDoc} */
540    public String toString() {
541      return impl.toString();
542    }
543  }
544}