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