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.AliasDefaultBehaviorProvider;
035    import org.opends.server.admin.BooleanPropertyDefinition;
036    import org.opends.server.admin.ClassPropertyDefinition;
037    import org.opends.server.admin.client.AuthorizationException;
038    import org.opends.server.admin.client.CommunicationException;
039    import org.opends.server.admin.client.ConcurrentModificationException;
040    import org.opends.server.admin.client.ManagedObject;
041    import org.opends.server.admin.client.MissingMandatoryPropertiesException;
042    import org.opends.server.admin.client.OperationRejectedException;
043    import org.opends.server.admin.DefaultBehaviorProvider;
044    import org.opends.server.admin.DefinedDefaultBehaviorProvider;
045    import org.opends.server.admin.DNPropertyDefinition;
046    import org.opends.server.admin.DurationPropertyDefinition;
047    import org.opends.server.admin.EnumPropertyDefinition;
048    import org.opends.server.admin.ManagedObjectAlreadyExistsException;
049    import org.opends.server.admin.ManagedObjectDefinition;
050    import org.opends.server.admin.ManagedObjectOption;
051    import org.opends.server.admin.PropertyIsReadOnlyException;
052    import org.opends.server.admin.PropertyOption;
053    import org.opends.server.admin.PropertyProvider;
054    import org.opends.server.admin.server.ConfigurationChangeListener;
055    import org.opends.server.admin.server.ServerManagedObject;
056    import org.opends.server.admin.std.client.TaskBackendCfgClient;
057    import org.opends.server.admin.std.meta.BackendCfgDefn.WritabilityMode;
058    import org.opends.server.admin.std.server.BackendCfg;
059    import org.opends.server.admin.std.server.TaskBackendCfg;
060    import org.opends.server.admin.StringPropertyDefinition;
061    import org.opends.server.admin.Tag;
062    import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
063    import org.opends.server.types.DN;
064    
065    
066    
067    /**
068     * An interface for querying the Task Backend managed object
069     * definition meta information.
070     * <p>
071     * The Task Backend provides a mechanism for scheduling tasks in the
072     * OpenDS Directory Server. Tasks are intended to provide access to
073     * certain types of administrative functions in the server that may not
074     * be convenient to perform remotely.
075     */
076    public final class TaskBackendCfgDefn extends ManagedObjectDefinition<TaskBackendCfgClient, TaskBackendCfg> {
077    
078      // The singleton configuration definition instance.
079      private static final TaskBackendCfgDefn INSTANCE = new TaskBackendCfgDefn();
080    
081    
082    
083      // The "java-class" property definition.
084      private static final ClassPropertyDefinition PD_JAVA_CLASS;
085    
086    
087    
088      // The "notification-sender-address" property definition.
089      private static final StringPropertyDefinition PD_NOTIFICATION_SENDER_ADDRESS;
090    
091    
092    
093      // The "task-backing-file" property definition.
094      private static final StringPropertyDefinition PD_TASK_BACKING_FILE;
095    
096    
097    
098      // The "task-retention-time" property definition.
099      private static final DurationPropertyDefinition PD_TASK_RETENTION_TIME;
100    
101    
102    
103      // The "writability-mode" property definition.
104      private static final EnumPropertyDefinition<WritabilityMode> PD_WRITABILITY_MODE;
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.task.TaskBackend");
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 "notification-sender-address" property definition.
124      static {
125          StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "notification-sender-address");
126          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "notification-sender-address"));
127          builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "notification-sender-address"));
128          PD_NOTIFICATION_SENDER_ADDRESS = builder.getInstance();
129          INSTANCE.registerPropertyDefinition(PD_NOTIFICATION_SENDER_ADDRESS);
130      }
131    
132    
133    
134      // Build the "task-backing-file" property definition.
135      static {
136          StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "task-backing-file");
137          builder.setOption(PropertyOption.MANDATORY);
138          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "task-backing-file"));
139          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
140          PD_TASK_BACKING_FILE = builder.getInstance();
141          INSTANCE.registerPropertyDefinition(PD_TASK_BACKING_FILE);
142      }
143    
144    
145    
146      // Build the "task-retention-time" property definition.
147      static {
148          DurationPropertyDefinition.Builder builder = DurationPropertyDefinition.createBuilder(INSTANCE, "task-retention-time");
149          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "task-retention-time"));
150          DefaultBehaviorProvider<Long> provider = new DefinedDefaultBehaviorProvider<Long>("24 hours");
151          builder.setDefaultBehaviorProvider(provider);
152          PD_TASK_RETENTION_TIME = builder.getInstance();
153          INSTANCE.registerPropertyDefinition(PD_TASK_RETENTION_TIME);
154      }
155    
156    
157    
158      // Build the "writability-mode" property definition.
159      static {
160          EnumPropertyDefinition.Builder<WritabilityMode> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "writability-mode");
161          builder.setOption(PropertyOption.MANDATORY);
162          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "writability-mode"));
163          DefaultBehaviorProvider<WritabilityMode> provider = new DefinedDefaultBehaviorProvider<WritabilityMode>("enabled");
164          builder.setDefaultBehaviorProvider(provider);
165          builder.setEnumClass(WritabilityMode.class);
166          PD_WRITABILITY_MODE = builder.getInstance();
167          INSTANCE.registerPropertyDefinition(PD_WRITABILITY_MODE);
168      }
169    
170    
171    
172      // Register the options associated with this managed object definition.
173      static {
174        INSTANCE.registerOption(ManagedObjectOption.ADVANCED);
175      }
176    
177    
178    
179      // Register the tags associated with this managed object definition.
180      static {
181        INSTANCE.registerTag(Tag.valueOf("database"));
182      }
183    
184    
185    
186      /**
187       * Get the Task Backend configuration definition singleton.
188       *
189       * @return Returns the Task Backend configuration definition
190       *         singleton.
191       */
192      public static TaskBackendCfgDefn getInstance() {
193        return INSTANCE;
194      }
195    
196    
197    
198      /**
199       * Private constructor.
200       */
201      private TaskBackendCfgDefn() {
202        super("task-backend", BackendCfgDefn.getInstance());
203      }
204    
205    
206    
207      /**
208       * {@inheritDoc}
209       */
210      public TaskBackendCfgClient createClientConfiguration(
211          ManagedObject<? extends TaskBackendCfgClient> impl) {
212        return new TaskBackendCfgClientImpl(impl);
213      }
214    
215    
216    
217      /**
218       * {@inheritDoc}
219       */
220      public TaskBackendCfg createServerConfiguration(
221          ServerManagedObject<? extends TaskBackendCfg> impl) {
222        return new TaskBackendCfgServerImpl(impl);
223      }
224    
225    
226    
227      /**
228       * {@inheritDoc}
229       */
230      public Class<TaskBackendCfg> getServerConfigurationClass() {
231        return TaskBackendCfg.class;
232      }
233    
234    
235    
236      /**
237       * Get the "backend-id" property definition.
238       * <p>
239       * Specifies a name to identify the associated backend.
240       * <p>
241       * The name must be unique among all backends in the server. The
242       * backend ID may not be altered after the backend is created in the
243       * server.
244       *
245       * @return Returns the "backend-id" property definition.
246       */
247      public StringPropertyDefinition getBackendIdPropertyDefinition() {
248        return BackendCfgDefn.getInstance().getBackendIdPropertyDefinition();
249      }
250    
251    
252    
253      /**
254       * Get the "base-dn" property definition.
255       * <p>
256       * Specifies the base DN(s) for the data that the backend handles.
257       * <p>
258       * A single backend may be responsible for one or more base DNs.
259       * Note that no two backends may have the same base DN although one
260       * backend may have a base DN that is below a base DN provided by
261       * another backend (similar to the use of sub-suffixes in the Sun
262       * Java System Directory Server). If any of the base DNs is
263       * subordinate to a base DN for another backend, then all base DNs
264       * for that backend must be subordinate to that same base DN.
265       *
266       * @return Returns the "base-dn" property definition.
267       */
268      public DNPropertyDefinition getBaseDNPropertyDefinition() {
269        return BackendCfgDefn.getInstance().getBaseDNPropertyDefinition();
270      }
271    
272    
273    
274      /**
275       * Get the "enabled" property definition.
276       * <p>
277       * Indicates whether the backend is enabled in the server.
278       * <p>
279       * If a backend is not enabled, then its contents are not accessible
280       * when processing operations.
281       *
282       * @return Returns the "enabled" property definition.
283       */
284      public BooleanPropertyDefinition getEnabledPropertyDefinition() {
285        return BackendCfgDefn.getInstance().getEnabledPropertyDefinition();
286      }
287    
288    
289    
290      /**
291       * Get the "java-class" property definition.
292       * <p>
293       * Specifies the fully-qualified name of the Java class that
294       * provides the backend implementation.
295       *
296       * @return Returns the "java-class" property definition.
297       */
298      public ClassPropertyDefinition getJavaClassPropertyDefinition() {
299        return PD_JAVA_CLASS;
300      }
301    
302    
303    
304      /**
305       * Get the "notification-sender-address" property definition.
306       * <p>
307       * Specifies the email address to use as the sender (that is, the
308       * "From:" address) address for notification mail messages generated
309       * when a task completes execution.
310       *
311       * @return Returns the "notification-sender-address" property definition.
312       */
313      public StringPropertyDefinition getNotificationSenderAddressPropertyDefinition() {
314        return PD_NOTIFICATION_SENDER_ADDRESS;
315      }
316    
317    
318    
319      /**
320       * Get the "task-backing-file" property definition.
321       * <p>
322       * Specifies the path to the backing file for storing information
323       * about the tasks configured in the server.
324       * <p>
325       * It may be either an absolute path or a relative path to the base
326       * of the OpenDS Directory Server instance.
327       *
328       * @return Returns the "task-backing-file" property definition.
329       */
330      public StringPropertyDefinition getTaskBackingFilePropertyDefinition() {
331        return PD_TASK_BACKING_FILE;
332      }
333    
334    
335    
336      /**
337       * Get the "task-retention-time" property definition.
338       * <p>
339       * Specifies the length of time that task entries should be retained
340       * after processing on the associated task has been completed.
341       *
342       * @return Returns the "task-retention-time" property definition.
343       */
344      public DurationPropertyDefinition getTaskRetentionTimePropertyDefinition() {
345        return PD_TASK_RETENTION_TIME;
346      }
347    
348    
349    
350      /**
351       * Get the "writability-mode" property definition.
352       * <p>
353       * Specifies the behavior that the backend should use when
354       * processing write operations.
355       *
356       * @return Returns the "writability-mode" property definition.
357       */
358      public EnumPropertyDefinition<WritabilityMode> getWritabilityModePropertyDefinition() {
359        return PD_WRITABILITY_MODE;
360      }
361    
362    
363    
364      /**
365       * Managed object client implementation.
366       */
367      private static class TaskBackendCfgClientImpl implements
368        TaskBackendCfgClient {
369    
370        // Private implementation.
371        private ManagedObject<? extends TaskBackendCfgClient> impl;
372    
373    
374    
375        // Private constructor.
376        private TaskBackendCfgClientImpl(
377            ManagedObject<? extends TaskBackendCfgClient> impl) {
378          this.impl = impl;
379        }
380    
381    
382    
383        /**
384         * {@inheritDoc}
385         */
386        public String getBackendId() {
387          return impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition());
388        }
389    
390    
391    
392        /**
393         * {@inheritDoc}
394         */
395        public void setBackendId(String value) throws PropertyIsReadOnlyException {
396          impl.setPropertyValue(INSTANCE.getBackendIdPropertyDefinition(), value);
397        }
398    
399    
400    
401        /**
402         * {@inheritDoc}
403         */
404        public SortedSet<DN> getBaseDN() {
405          return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
406        }
407    
408    
409    
410        /**
411         * {@inheritDoc}
412         */
413        public void setBaseDN(Collection<DN> values) {
414          impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values);
415        }
416    
417    
418    
419        /**
420         * {@inheritDoc}
421         */
422        public Boolean isEnabled() {
423          return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
424        }
425    
426    
427    
428        /**
429         * {@inheritDoc}
430         */
431        public void setEnabled(boolean value) {
432          impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
433        }
434    
435    
436    
437        /**
438         * {@inheritDoc}
439         */
440        public String getJavaClass() {
441          return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
442        }
443    
444    
445    
446        /**
447         * {@inheritDoc}
448         */
449        public void setJavaClass(String value) {
450          impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
451        }
452    
453    
454    
455        /**
456         * {@inheritDoc}
457         */
458        public String getNotificationSenderAddress() {
459          return impl.getPropertyValue(INSTANCE.getNotificationSenderAddressPropertyDefinition());
460        }
461    
462    
463    
464        /**
465         * {@inheritDoc}
466         */
467        public void setNotificationSenderAddress(String value) {
468          impl.setPropertyValue(INSTANCE.getNotificationSenderAddressPropertyDefinition(), value);
469        }
470    
471    
472    
473        /**
474         * {@inheritDoc}
475         */
476        public String getTaskBackingFile() {
477          return impl.getPropertyValue(INSTANCE.getTaskBackingFilePropertyDefinition());
478        }
479    
480    
481    
482        /**
483         * {@inheritDoc}
484         */
485        public void setTaskBackingFile(String value) {
486          impl.setPropertyValue(INSTANCE.getTaskBackingFilePropertyDefinition(), value);
487        }
488    
489    
490    
491        /**
492         * {@inheritDoc}
493         */
494        public long getTaskRetentionTime() {
495          return impl.getPropertyValue(INSTANCE.getTaskRetentionTimePropertyDefinition());
496        }
497    
498    
499    
500        /**
501         * {@inheritDoc}
502         */
503        public void setTaskRetentionTime(Long value) {
504          impl.setPropertyValue(INSTANCE.getTaskRetentionTimePropertyDefinition(), value);
505        }
506    
507    
508    
509        /**
510         * {@inheritDoc}
511         */
512        public WritabilityMode getWritabilityMode() {
513          return impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition());
514        }
515    
516    
517    
518        /**
519         * {@inheritDoc}
520         */
521        public void setWritabilityMode(WritabilityMode value) {
522          impl.setPropertyValue(INSTANCE.getWritabilityModePropertyDefinition(), value);
523        }
524    
525    
526    
527        /**
528         * {@inheritDoc}
529         */
530        public ManagedObjectDefinition<? extends TaskBackendCfgClient, ? extends TaskBackendCfg> definition() {
531          return INSTANCE;
532        }
533    
534    
535    
536        /**
537         * {@inheritDoc}
538         */
539        public PropertyProvider properties() {
540          return impl;
541        }
542    
543    
544    
545        /**
546         * {@inheritDoc}
547         */
548        public void commit() throws ManagedObjectAlreadyExistsException,
549            MissingMandatoryPropertiesException, ConcurrentModificationException,
550            OperationRejectedException, AuthorizationException,
551            CommunicationException {
552          impl.commit();
553        }
554    
555      }
556    
557    
558    
559      /**
560       * Managed object server implementation.
561       */
562      private static class TaskBackendCfgServerImpl implements
563        TaskBackendCfg {
564    
565        // Private implementation.
566        private ServerManagedObject<? extends TaskBackendCfg> impl;
567    
568        // The value of the "backend-id" property.
569        private final String pBackendId;
570    
571        // The value of the "base-dn" property.
572        private final SortedSet<DN> pBaseDN;
573    
574        // The value of the "enabled" property.
575        private final boolean pEnabled;
576    
577        // The value of the "java-class" property.
578        private final String pJavaClass;
579    
580        // The value of the "notification-sender-address" property.
581        private final String pNotificationSenderAddress;
582    
583        // The value of the "task-backing-file" property.
584        private final String pTaskBackingFile;
585    
586        // The value of the "task-retention-time" property.
587        private final long pTaskRetentionTime;
588    
589        // The value of the "writability-mode" property.
590        private final WritabilityMode pWritabilityMode;
591    
592    
593    
594        // Private constructor.
595        private TaskBackendCfgServerImpl(ServerManagedObject<? extends TaskBackendCfg> impl) {
596          this.impl = impl;
597          this.pBackendId = impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition());
598          this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
599          this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
600          this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
601          this.pNotificationSenderAddress = impl.getPropertyValue(INSTANCE.getNotificationSenderAddressPropertyDefinition());
602          this.pTaskBackingFile = impl.getPropertyValue(INSTANCE.getTaskBackingFilePropertyDefinition());
603          this.pTaskRetentionTime = impl.getPropertyValue(INSTANCE.getTaskRetentionTimePropertyDefinition());
604          this.pWritabilityMode = impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition());
605        }
606    
607    
608    
609        /**
610         * {@inheritDoc}
611         */
612        public void addTaskChangeListener(
613            ConfigurationChangeListener<TaskBackendCfg> listener) {
614          impl.registerChangeListener(listener);
615        }
616    
617    
618    
619        /**
620         * {@inheritDoc}
621         */
622        public void removeTaskChangeListener(
623            ConfigurationChangeListener<TaskBackendCfg> listener) {
624          impl.deregisterChangeListener(listener);
625        }
626        /**
627         * {@inheritDoc}
628         */
629        public void addChangeListener(
630            ConfigurationChangeListener<BackendCfg> listener) {
631          impl.registerChangeListener(listener);
632        }
633    
634    
635    
636        /**
637         * {@inheritDoc}
638         */
639        public void removeChangeListener(
640            ConfigurationChangeListener<BackendCfg> listener) {
641          impl.deregisterChangeListener(listener);
642        }
643    
644    
645    
646        /**
647         * {@inheritDoc}
648         */
649        public String getBackendId() {
650          return pBackendId;
651        }
652    
653    
654    
655        /**
656         * {@inheritDoc}
657         */
658        public SortedSet<DN> getBaseDN() {
659          return pBaseDN;
660        }
661    
662    
663    
664        /**
665         * {@inheritDoc}
666         */
667        public boolean isEnabled() {
668          return pEnabled;
669        }
670    
671    
672    
673        /**
674         * {@inheritDoc}
675         */
676        public String getJavaClass() {
677          return pJavaClass;
678        }
679    
680    
681    
682        /**
683         * {@inheritDoc}
684         */
685        public String getNotificationSenderAddress() {
686          return pNotificationSenderAddress;
687        }
688    
689    
690    
691        /**
692         * {@inheritDoc}
693         */
694        public String getTaskBackingFile() {
695          return pTaskBackingFile;
696        }
697    
698    
699    
700        /**
701         * {@inheritDoc}
702         */
703        public long getTaskRetentionTime() {
704          return pTaskRetentionTime;
705        }
706    
707    
708    
709        /**
710         * {@inheritDoc}
711         */
712        public WritabilityMode getWritabilityMode() {
713          return pWritabilityMode;
714        }
715    
716    
717    
718        /**
719         * {@inheritDoc}
720         */
721        public Class<? extends TaskBackendCfg> configurationClass() {
722          return TaskBackendCfg.class;
723        }
724    
725    
726    
727        /**
728         * {@inheritDoc}
729         */
730        public DN dn() {
731          return impl.getDN();
732        }
733    
734      }
735    }