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.BooleanPropertyDefinition;
024import org.forgerock.opendj.config.ClassPropertyDefinition;
025import org.forgerock.opendj.config.client.ConcurrentModificationException;
026import org.forgerock.opendj.config.client.ManagedObject;
027import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
028import org.forgerock.opendj.config.client.OperationRejectedException;
029import org.forgerock.opendj.config.DefaultBehaviorProvider;
030import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
031import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
032import org.forgerock.opendj.config.ManagedObjectDefinition;
033import org.forgerock.opendj.config.PropertyOption;
034import org.forgerock.opendj.config.PropertyProvider;
035import org.forgerock.opendj.config.server.ConfigurationChangeListener;
036import org.forgerock.opendj.config.server.ServerManagedObject;
037import org.forgerock.opendj.config.StringPropertyDefinition;
038import org.forgerock.opendj.config.Tag;
039import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
040import org.forgerock.opendj.ldap.DN;
041import org.forgerock.opendj.ldap.LdapException;
042import org.forgerock.opendj.server.config.client.SMTPAlertHandlerCfgClient;
043import org.forgerock.opendj.server.config.server.AlertHandlerCfg;
044import org.forgerock.opendj.server.config.server.SMTPAlertHandlerCfg;
045
046
047
048/**
049 * An interface for querying the SMTP Alert Handler managed object
050 * definition meta information.
051 * <p>
052 * The SMTP Alert Handler may be used to send e-mail messages to
053 * notify administrators of significant events that occur within the
054 * server.
055 */
056public final class SMTPAlertHandlerCfgDefn extends ManagedObjectDefinition<SMTPAlertHandlerCfgClient, SMTPAlertHandlerCfg> {
057
058  /** The singleton configuration definition instance. */
059  private static final SMTPAlertHandlerCfgDefn INSTANCE = new SMTPAlertHandlerCfgDefn();
060
061
062
063  /** The "java-class" property definition. */
064  private static final ClassPropertyDefinition PD_JAVA_CLASS;
065
066
067
068  /** The "message-body" property definition. */
069  private static final StringPropertyDefinition PD_MESSAGE_BODY;
070
071
072
073  /** The "message-subject" property definition. */
074  private static final StringPropertyDefinition PD_MESSAGE_SUBJECT;
075
076
077
078  /** The "recipient-address" property definition. */
079  private static final StringPropertyDefinition PD_RECIPIENT_ADDRESS;
080
081
082
083  /** The "sender-address" property definition. */
084  private static final StringPropertyDefinition PD_SENDER_ADDRESS;
085
086
087
088  /** Build the "java-class" property definition. */
089  static {
090      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
091      builder.setOption(PropertyOption.MANDATORY);
092      builder.setOption(PropertyOption.ADVANCED);
093      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
094      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.SMTPAlertHandler");
095      builder.setDefaultBehaviorProvider(provider);
096      builder.addInstanceOf("org.opends.server.api.AlertHandler");
097      PD_JAVA_CLASS = builder.getInstance();
098      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
099  }
100
101
102
103  /** Build the "message-body" property definition. */
104  static {
105      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "message-body");
106      builder.setOption(PropertyOption.MANDATORY);
107      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "message-body"));
108      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
109      PD_MESSAGE_BODY = builder.getInstance();
110      INSTANCE.registerPropertyDefinition(PD_MESSAGE_BODY);
111  }
112
113
114
115  /** Build the "message-subject" property definition. */
116  static {
117      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "message-subject");
118      builder.setOption(PropertyOption.MANDATORY);
119      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "message-subject"));
120      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
121      PD_MESSAGE_SUBJECT = builder.getInstance();
122      INSTANCE.registerPropertyDefinition(PD_MESSAGE_SUBJECT);
123  }
124
125
126
127  /** Build the "recipient-address" property definition. */
128  static {
129      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "recipient-address");
130      builder.setOption(PropertyOption.MULTI_VALUED);
131      builder.setOption(PropertyOption.MANDATORY);
132      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "recipient-address"));
133      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
134      PD_RECIPIENT_ADDRESS = builder.getInstance();
135      INSTANCE.registerPropertyDefinition(PD_RECIPIENT_ADDRESS);
136  }
137
138
139
140  /** Build the "sender-address" property definition. */
141  static {
142      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "sender-address");
143      builder.setOption(PropertyOption.MANDATORY);
144      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "sender-address"));
145      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
146      PD_SENDER_ADDRESS = builder.getInstance();
147      INSTANCE.registerPropertyDefinition(PD_SENDER_ADDRESS);
148  }
149
150
151
152  // Register the tags associated with this managed object definition.
153  static {
154    INSTANCE.registerTag(Tag.valueOf("core-server"));
155  }
156
157
158
159  /**
160   * Get the SMTP Alert Handler configuration definition singleton.
161   *
162   * @return Returns the SMTP Alert Handler configuration definition
163   *         singleton.
164   */
165  public static SMTPAlertHandlerCfgDefn getInstance() {
166    return INSTANCE;
167  }
168
169
170
171  /**
172   * Private constructor.
173   */
174  private SMTPAlertHandlerCfgDefn() {
175    super("smtp-alert-handler", AlertHandlerCfgDefn.getInstance());
176  }
177
178
179
180  /** {@inheritDoc} */
181  public SMTPAlertHandlerCfgClient createClientConfiguration(
182      ManagedObject<? extends SMTPAlertHandlerCfgClient> impl) {
183    return new SMTPAlertHandlerCfgClientImpl(impl);
184  }
185
186
187
188  /** {@inheritDoc} */
189  public SMTPAlertHandlerCfg createServerConfiguration(
190      ServerManagedObject<? extends SMTPAlertHandlerCfg> impl) {
191    return new SMTPAlertHandlerCfgServerImpl(impl);
192  }
193
194
195
196  /** {@inheritDoc} */
197  public Class<SMTPAlertHandlerCfg> getServerConfigurationClass() {
198    return SMTPAlertHandlerCfg.class;
199  }
200
201
202
203  /**
204   * Get the "disabled-alert-type" property definition.
205   * <p>
206   * Specifies the names of the alert types that are disabled for this
207   * alert handler.
208   * <p>
209   * If there are any values for this attribute, then no alerts with
210   * any of the specified types are allowed. If there are no values for
211   * this attribute, then only alerts with a type included in the set
212   * of enabled alert types are allowed, or if there are no values for
213   * the enabled alert types option, then all alert types are allowed.
214   *
215   * @return Returns the "disabled-alert-type" property definition.
216   */
217  public StringPropertyDefinition getDisabledAlertTypePropertyDefinition() {
218    return AlertHandlerCfgDefn.getInstance().getDisabledAlertTypePropertyDefinition();
219  }
220
221
222
223  /**
224   * Get the "enabled" property definition.
225   * <p>
226   * Indicates whether the SMTP Alert Handler is enabled.
227   *
228   * @return Returns the "enabled" property definition.
229   */
230  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
231    return AlertHandlerCfgDefn.getInstance().getEnabledPropertyDefinition();
232  }
233
234
235
236  /**
237   * Get the "enabled-alert-type" property definition.
238   * <p>
239   * Specifies the names of the alert types that are enabled for this
240   * alert handler.
241   * <p>
242   * If there are any values for this attribute, then only alerts with
243   * one of the specified types are allowed (unless they are also
244   * included in the disabled alert types). If there are no values for
245   * this attribute, then any alert with a type not included in the
246   * list of disabled alert types is allowed.
247   *
248   * @return Returns the "enabled-alert-type" property definition.
249   */
250  public StringPropertyDefinition getEnabledAlertTypePropertyDefinition() {
251    return AlertHandlerCfgDefn.getInstance().getEnabledAlertTypePropertyDefinition();
252  }
253
254
255
256  /**
257   * Get the "java-class" property definition.
258   * <p>
259   * Specifies the fully-qualified name of the Java class that
260   * provides the SMTP Alert Handler implementation.
261   *
262   * @return Returns the "java-class" property definition.
263   */
264  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
265    return PD_JAVA_CLASS;
266  }
267
268
269
270  /**
271   * Get the "message-body" property definition.
272   * <p>
273   * Specifies the body that should be used for email messages
274   * generated by this alert handler.
275   * <p>
276   * The token "%%%%alert-type%%%%" is dynamically replaced with the
277   * alert type string. The token "%%%%alert-id%%%%" is dynamically
278   * replaced with the alert ID value. The token
279   * "%%%%alert-message%%%%" is dynamically replaced with the alert
280   * message. The token "\\n" is replaced with an end-of-line marker.
281   *
282   * @return Returns the "message-body" property definition.
283   */
284  public StringPropertyDefinition getMessageBodyPropertyDefinition() {
285    return PD_MESSAGE_BODY;
286  }
287
288
289
290  /**
291   * Get the "message-subject" property definition.
292   * <p>
293   * Specifies the subject that should be used for email messages
294   * generated by this alert handler.
295   * <p>
296   * The token "%%%%alert-type%%%%" is dynamically replaced with the
297   * alert type string. The token "%%%%alert-id%%%%" is dynamically
298   * replaced with the alert ID value. The token
299   * "%%%%alert-message%%%%" is dynamically replaced with the alert
300   * message. The token "\\n" is replaced with an end-of-line marker.
301   *
302   * @return Returns the "message-subject" property definition.
303   */
304  public StringPropertyDefinition getMessageSubjectPropertyDefinition() {
305    return PD_MESSAGE_SUBJECT;
306  }
307
308
309
310  /**
311   * Get the "recipient-address" property definition.
312   * <p>
313   * Specifies an email address to which the messages should be sent.
314   * <p>
315   * Multiple values may be provided if there should be more than one
316   * recipient.
317   *
318   * @return Returns the "recipient-address" property definition.
319   */
320  public StringPropertyDefinition getRecipientAddressPropertyDefinition() {
321    return PD_RECIPIENT_ADDRESS;
322  }
323
324
325
326  /**
327   * Get the "sender-address" property definition.
328   * <p>
329   * Specifies the email address to use as the sender for messages
330   * generated by this alert handler.
331   *
332   * @return Returns the "sender-address" property definition.
333   */
334  public StringPropertyDefinition getSenderAddressPropertyDefinition() {
335    return PD_SENDER_ADDRESS;
336  }
337
338
339
340  /**
341   * Managed object client implementation.
342   */
343  private static class SMTPAlertHandlerCfgClientImpl implements
344    SMTPAlertHandlerCfgClient {
345
346    /** Private implementation. */
347    private ManagedObject<? extends SMTPAlertHandlerCfgClient> impl;
348
349
350
351    /** Private constructor. */
352    private SMTPAlertHandlerCfgClientImpl(
353        ManagedObject<? extends SMTPAlertHandlerCfgClient> impl) {
354      this.impl = impl;
355    }
356
357
358
359    /** {@inheritDoc} */
360    public SortedSet<String> getDisabledAlertType() {
361      return impl.getPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition());
362    }
363
364
365
366    /** {@inheritDoc} */
367    public void setDisabledAlertType(Collection<String> values) {
368      impl.setPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition(), values);
369    }
370
371
372
373    /** {@inheritDoc} */
374    public Boolean isEnabled() {
375      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
376    }
377
378
379
380    /** {@inheritDoc} */
381    public void setEnabled(boolean value) {
382      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
383    }
384
385
386
387    /** {@inheritDoc} */
388    public SortedSet<String> getEnabledAlertType() {
389      return impl.getPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition());
390    }
391
392
393
394    /** {@inheritDoc} */
395    public void setEnabledAlertType(Collection<String> values) {
396      impl.setPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition(), values);
397    }
398
399
400
401    /** {@inheritDoc} */
402    public String getJavaClass() {
403      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
404    }
405
406
407
408    /** {@inheritDoc} */
409    public void setJavaClass(String value) {
410      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
411    }
412
413
414
415    /** {@inheritDoc} */
416    public String getMessageBody() {
417      return impl.getPropertyValue(INSTANCE.getMessageBodyPropertyDefinition());
418    }
419
420
421
422    /** {@inheritDoc} */
423    public void setMessageBody(String value) {
424      impl.setPropertyValue(INSTANCE.getMessageBodyPropertyDefinition(), value);
425    }
426
427
428
429    /** {@inheritDoc} */
430    public String getMessageSubject() {
431      return impl.getPropertyValue(INSTANCE.getMessageSubjectPropertyDefinition());
432    }
433
434
435
436    /** {@inheritDoc} */
437    public void setMessageSubject(String value) {
438      impl.setPropertyValue(INSTANCE.getMessageSubjectPropertyDefinition(), value);
439    }
440
441
442
443    /** {@inheritDoc} */
444    public SortedSet<String> getRecipientAddress() {
445      return impl.getPropertyValues(INSTANCE.getRecipientAddressPropertyDefinition());
446    }
447
448
449
450    /** {@inheritDoc} */
451    public void setRecipientAddress(Collection<String> values) {
452      impl.setPropertyValues(INSTANCE.getRecipientAddressPropertyDefinition(), values);
453    }
454
455
456
457    /** {@inheritDoc} */
458    public String getSenderAddress() {
459      return impl.getPropertyValue(INSTANCE.getSenderAddressPropertyDefinition());
460    }
461
462
463
464    /** {@inheritDoc} */
465    public void setSenderAddress(String value) {
466      impl.setPropertyValue(INSTANCE.getSenderAddressPropertyDefinition(), value);
467    }
468
469
470
471    /** {@inheritDoc} */
472    public ManagedObjectDefinition<? extends SMTPAlertHandlerCfgClient, ? extends SMTPAlertHandlerCfg> definition() {
473      return INSTANCE;
474    }
475
476
477
478    /** {@inheritDoc} */
479    public PropertyProvider properties() {
480      return impl;
481    }
482
483
484
485    /** {@inheritDoc} */
486    public void commit() throws ManagedObjectAlreadyExistsException,
487        MissingMandatoryPropertiesException, ConcurrentModificationException,
488        OperationRejectedException, LdapException {
489      impl.commit();
490    }
491
492
493
494    /** {@inheritDoc} */
495    public String toString() {
496      return impl.toString();
497    }
498  }
499
500
501
502  /**
503   * Managed object server implementation.
504   */
505  private static class SMTPAlertHandlerCfgServerImpl implements
506    SMTPAlertHandlerCfg {
507
508    /** Private implementation. */
509    private ServerManagedObject<? extends SMTPAlertHandlerCfg> impl;
510
511    /** The value of the "disabled-alert-type" property. */
512    private final SortedSet<String> pDisabledAlertType;
513
514    /** The value of the "enabled" property. */
515    private final boolean pEnabled;
516
517    /** The value of the "enabled-alert-type" property. */
518    private final SortedSet<String> pEnabledAlertType;
519
520    /** The value of the "java-class" property. */
521    private final String pJavaClass;
522
523    /** The value of the "message-body" property. */
524    private final String pMessageBody;
525
526    /** The value of the "message-subject" property. */
527    private final String pMessageSubject;
528
529    /** The value of the "recipient-address" property. */
530    private final SortedSet<String> pRecipientAddress;
531
532    /** The value of the "sender-address" property. */
533    private final String pSenderAddress;
534
535
536
537    /** Private constructor. */
538    private SMTPAlertHandlerCfgServerImpl(ServerManagedObject<? extends SMTPAlertHandlerCfg> impl) {
539      this.impl = impl;
540      this.pDisabledAlertType = impl.getPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition());
541      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
542      this.pEnabledAlertType = impl.getPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition());
543      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
544      this.pMessageBody = impl.getPropertyValue(INSTANCE.getMessageBodyPropertyDefinition());
545      this.pMessageSubject = impl.getPropertyValue(INSTANCE.getMessageSubjectPropertyDefinition());
546      this.pRecipientAddress = impl.getPropertyValues(INSTANCE.getRecipientAddressPropertyDefinition());
547      this.pSenderAddress = impl.getPropertyValue(INSTANCE.getSenderAddressPropertyDefinition());
548    }
549
550
551
552    /** {@inheritDoc} */
553    public void addSMTPChangeListener(
554        ConfigurationChangeListener<SMTPAlertHandlerCfg> listener) {
555      impl.registerChangeListener(listener);
556    }
557
558
559
560    /** {@inheritDoc} */
561    public void removeSMTPChangeListener(
562        ConfigurationChangeListener<SMTPAlertHandlerCfg> listener) {
563      impl.deregisterChangeListener(listener);
564    }
565    /** {@inheritDoc} */
566    public void addChangeListener(
567        ConfigurationChangeListener<AlertHandlerCfg> listener) {
568      impl.registerChangeListener(listener);
569    }
570
571
572
573    /** {@inheritDoc} */
574    public void removeChangeListener(
575        ConfigurationChangeListener<AlertHandlerCfg> listener) {
576      impl.deregisterChangeListener(listener);
577    }
578
579
580
581    /** {@inheritDoc} */
582    public SortedSet<String> getDisabledAlertType() {
583      return pDisabledAlertType;
584    }
585
586
587
588    /** {@inheritDoc} */
589    public boolean isEnabled() {
590      return pEnabled;
591    }
592
593
594
595    /** {@inheritDoc} */
596    public SortedSet<String> getEnabledAlertType() {
597      return pEnabledAlertType;
598    }
599
600
601
602    /** {@inheritDoc} */
603    public String getJavaClass() {
604      return pJavaClass;
605    }
606
607
608
609    /** {@inheritDoc} */
610    public String getMessageBody() {
611      return pMessageBody;
612    }
613
614
615
616    /** {@inheritDoc} */
617    public String getMessageSubject() {
618      return pMessageSubject;
619    }
620
621
622
623    /** {@inheritDoc} */
624    public SortedSet<String> getRecipientAddress() {
625      return pRecipientAddress;
626    }
627
628
629
630    /** {@inheritDoc} */
631    public String getSenderAddress() {
632      return pSenderAddress;
633    }
634
635
636
637    /** {@inheritDoc} */
638    public Class<? extends SMTPAlertHandlerCfg> configurationClass() {
639      return SMTPAlertHandlerCfg.class;
640    }
641
642
643
644    /** {@inheritDoc} */
645    public DN dn() {
646      return impl.getDN();
647    }
648
649
650
651    /** {@inheritDoc} */
652    public String toString() {
653      return impl.toString();
654    }
655  }
656}