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