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