KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > server > engine > dm > ejb > ManagementBean


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.server.engine.dm.ejb;
20
21 import java.util.logging.Logger JavaDoc;
22
23 import javax.ejb.CreateException JavaDoc;
24 import javax.ejb.EJBException JavaDoc;
25 import javax.ejb.SessionContext JavaDoc;
26 import javax.naming.InitialContext JavaDoc;
27 import javax.rmi.PortableRemoteObject JavaDoc;
28
29 import sync4j.framework.config.Configuration;
30 import sync4j.framework.engine.dm.ManagementException;
31 import sync4j.framework.logging.Sync4jLogger;
32 import sync4j.framework.logging.Sync4jLoggerName;
33 import sync4j.framework.notification.NotificationException;
34 import sync4j.framework.notification.NotificationConstants;
35
36
37 import sync4j.server.admin.ejb.AdminHomeRemote;
38 import sync4j.server.admin.ejb.AdminRemote;
39 import sync4j.server.engine.dm.ManagementEngine;
40
41 /**
42  * @author Stefano Nichele @ Funambol
43  *
44  * @version $Id: ManagementBean.java,v 1.1 2005/05/16 17:32:56 nichele Exp $
45  *
46  */

47 public class ManagementBean implements javax.ejb.SessionBean JavaDoc {
48
49     // ------------------------------------------------------- Private constants
50

51     private static final String JavaDoc ENV_ADMIN_NAME
52         = "java:comp/env/ejb/AdminBean";
53
54     // ------------------------------------------------------------ Private data
55
private transient Logger JavaDoc log = null;
56     private SessionContext JavaDoc sessionContext = null;
57
58
59     // ------------------------------------------------------------- EJB methods
60

61     public void ejbCreate() {
62         log = Sync4jLogger.getLogger(Sync4jLoggerName.SERVER_DM_NOTIFICATION);
63     }
64
65     public void ejbRemove() {
66     }
67
68     public void ejbActivate() {
69         log = Sync4jLogger.getLogger(Sync4jLoggerName.SERVER_DM_NOTIFICATION);
70     }
71
72     public void ejbPassivate() {
73         log = null;
74     }
75
76     public void setSessionContext(SessionContext JavaDoc sessionContext) throws EJBException JavaDoc {
77         this.sessionContext = sessionContext;
78     }
79
80     /**
81      * Performs a bootstrap with the given parameter
82      * @param messageType the type of the bootstrap message as define in <code>NotificationConstants<code>
83      * @param transportType the type of the transport as define in <code>NotificationConstants<code>
84      * @param deviceUri the device id
85      * @param phoneNumber the phone number of the device
86      * @param username the user name with which the device will do the next device management
87      * @param password the password with which the device will do the next device management
88      * @param info application specific info
89      * @throws ManagementException if a error occurs in the management engine,
90      * NotificationException if an error occurs in the notification process
91      */

92     public void bootstrap(int messageType, int transportType, String JavaDoc deviceUri, String JavaDoc phoneNumber, String JavaDoc
93                             username, String JavaDoc password, String JavaDoc info)
94     throws ManagementException, NotificationException {
95
96         Configuration conf = loadConfiguration();
97
98         ManagementEngine mngtEngine = new ManagementEngine(conf);
99
100
101         mngtEngine.bootstrap(messageType, transportType, deviceUri, phoneNumber, username, password, info, false);
102     }
103
104     /**
105      * Sends a notification message to the device with the given phoneNumber
106      * @param messageType the type of the notification message as define in <code>NotificationConstants<code>
107      * @param transportType the type of the transport as define in <code>NotificationConstants<code>
108      * @param phoneNumber the phone number
109      * @param operation application specific operation to be performed
110      * @param info application specific detail information
111      *
112      * @throws ManagementException if a error occurs in the management engine,
113      * NotificationException if an error occurs in the notification process
114      */

115     public void sendNotification( int messageType ,
116                                   int transportType,
117                                   String JavaDoc phoneNumber ,
118                                   String JavaDoc operation ,
119                                   String JavaDoc info )
120     throws ManagementException, NotificationException {
121
122         Configuration conf = loadConfiguration();
123
124         ManagementEngine mngtEngine = new ManagementEngine(conf);
125
126         mngtEngine.sendNotification(
127             messageType,
128             transportType,
129             phoneNumber,
130             operation,
131             info
132         );
133     }
134
135     /**
136      * Executes the management sequence identified by the given operation name.
137      *
138      * @param phoneNumber the phone number
139      * @param operation the management operation name
140      * @param info application specific detail information
141      *
142      * @throws ManagementException if a error occurs in the management engine,
143      * NotificationException if an error occurs in the notification process
144      */

145     public void executeManagementOperation( String JavaDoc phoneNumber ,
146                                             String JavaDoc operation ,
147                                             String JavaDoc info )
148     throws ManagementException, NotificationException {
149
150         sendNotification(
151             NotificationConstants.MESSAGE_TYPE_NOTIFICATION_GENERIC,
152             NotificationConstants.TRANSPORT_TYPE_WAP,
153             phoneNumber,
154             operation,
155             info
156         );
157     }
158
159
160
161     // --------------------------------------------------------- Private methods
162

163     /**
164      * Load the configuration through the management bean
165      * @throws NotificationException if a error occurs
166      * @return Configuration
167      */

168     private Configuration loadConfiguration()
169     throws ManagementException {
170
171         Configuration c = null;
172         try {
173
174             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
175
176             Object JavaDoc obj = ctx.lookup(ENV_ADMIN_NAME);
177             AdminHomeRemote h = (AdminHomeRemote)PortableRemoteObject.narrow(obj,
178                 AdminHomeRemote.class);
179
180             AdminRemote m = h.create();
181
182             c = m.getConfig();
183
184             m.remove();
185
186         } catch (Exception JavaDoc e) {
187             log.throwing("ManagementBean", "loadConfiguration", e);
188             throw new ManagementException("Error reading the configuration", e);
189         }
190         return c;
191     }
192
193
194
195 }
196
Popular Tags