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