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