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