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