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