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