KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > mail > factory > JavaMailResource


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or 1any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: JavaMailResource.java,v 1.3 2004/08/19 09:30:22 danesa Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.mail.factory;
27
28 import java.util.Properties JavaDoc;
29
30 import javax.management.NotificationFilter JavaDoc;
31 import javax.management.NotificationListener JavaDoc;
32
33 import org.objectweb.jonas.management.ListenerJavaBean;
34 import org.objectweb.jonas.management.ReconfiguredProp;
35 import org.objectweb.jonas.management.j2eemanagement.J2EEResource;
36 import org.objectweb.util.monolog.api.BasicLevel;
37
38 /**
39  * @author Adriana Danes
40  *
41  * JavaMail resource implementation.
42  */

43 public abstract class JavaMailResource extends J2EEResource {
44
45     JavaMail mailFactory = null;
46
47     /**
48      * JavaMail resource constructor.
49      * @param objectName MBean ObjectName
50      * @param stateManageable
51      * @param statisticsProvider
52      * @param eventProvider
53      * @param mailFactory
54      */

55     public JavaMailResource(String JavaDoc objectName, boolean stateManageable, boolean statisticsProvider, boolean eventProvider, JavaMail mailFactory) {
56         super(objectName, stateManageable, statisticsProvider, eventProvider);
57         this.mailFactory = mailFactory;
58     }
59
60     /**
61      * Get the name of the factory.
62      * @return the name of the mail factory (the resource name as defined in jonas.properties)
63      */

64     public String JavaDoc getFactoryName() {
65         return mailFactory.getFactoryName();
66     }
67     /**
68      * Get the name of the factory.
69      * @return name of the mail factory.
70      */

71     public String JavaDoc getName() {
72         return mailFactory.getName();
73     }
74     /**
75      * Set the name of the factory.
76      * @param name name of the mail factory.
77      */

78     public void setName(String JavaDoc name) {
79         mailFactory.setName(name);
80     }
81     /**
82      * Get the type of the factory.
83      * @return type of the mail factory.
84      */

85     public String JavaDoc getFactoryType() {
86         return mailFactory.getType();
87     }
88
89     /**
90      * Get the authentication properties.
91      * @return properties of the authentication.
92      */

93     public Properties JavaDoc getAuthenticationProperties() {
94         return mailFactory.getAuthenticationProperties();
95     }
96
97     /**
98      * Set the authentication properties.
99      * @param props the authentication properties.
100      */

101     public void setAuthenticationProperties(Properties JavaDoc props) {
102         mailFactory.setAuthenticationProperties(props);
103         notifyReconfiguration(props);
104     }
105
106     /**
107      * Get the session properties.
108      * @return the properties of Session.
109      */

110     public Properties JavaDoc getSessionProperties() {
111         return mailFactory.getSessionProperties();
112     }
113
114     /**
115      * Set the session properties.
116      * @param props the Session properties.
117      */

118     public void setSessionProperties(Properties JavaDoc props) {
119         mailFactory.setSessionProperties(props);
120         notifyReconfiguration(props);
121     }
122
123     /**
124      * Save updated configuration
125      */

126     public void saveConfig() {
127         sendSaveNotification(getSequenceNumber(), getFactoryName());
128     }
129
130     /**
131      * Gets the sequence number for MBeans operations
132      * @return the sequence number for MBeans operations
133      */

134     protected abstract long getSequenceNumber();
135
136     protected void notifyReconfiguration(Properties JavaDoc props) {
137         // Here we do not reconfigure a sole property, but a group of properties in props
138
ReconfiguredProp reconfiguredProp = new ReconfiguredProp("", null);
139         reconfiguredProp.setProps(props);
140         // Send a reconfiguration notification to the listner MBean
141
sendReconfigNotification(getSequenceNumber(), getFactoryName(), reconfiguredProp);
142     }
143 }
144
Popular Tags