KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > server > admin > ejb > AdminBean


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 package sync4j.server.admin.ejb;
19
20 import javax.ejb.*;
21
22 import sync4j.framework.core.*;
23 import sync4j.framework.config.ConfigurationConstants;
24 import sync4j.framework.config.LoggingConfiguration;
25
26 import sync4j.framework.server.error.*;
27
28 import sync4j.framework.engine.source.SyncSource;
29
30 import sync4j.framework.security.Sync4jPrincipal;
31
32 import sync4j.framework.server.Sync4jUser;
33 import sync4j.framework.server.Sync4jDevice;
34 import sync4j.framework.server.Sync4jModule;
35
36 import sync4j.framework.server.store.Clause;
37
38 import sync4j.server.admin.AdminManager;
39 import sync4j.server.admin.AdminException;
40
41 import sync4j.server.config.Configuration;
42
43 /**
44  * This is the session enterprise java bean that handles the administration
45  * console. It is designed to be a stateless session bean.
46  * <p>
47  * This server accepts the requests addressed to the hostname
48  * indicated by the configuration property pointed by {CONFIG_SERVER_URI} (see
49  * Sync4j.xml).
50  * <p>
51  * AdminBean uses the system property sync4j.configpath to set the base of the
52  * config path.
53  *
54  * @author Luigia Fassina @ Funambol
55  *
56  * @version $Id: AdminBean.java,v 1.9 2005/06/03 22:57:16 stefano_fornari Exp $
57  *
58  */

59 public class AdminBean
60 implements javax.ejb.SessionBean JavaDoc {
61     // ------------------------------------------------------- Private constants
62
// ------------------------------------------------------------ Private data
63

64     private SessionContext sessionContext = null;
65     private AdminManager admin = null;
66     
67     // ------------------------------------------------------------- EJB methods
68
public void ejbCreate() throws CreateException {
69         admin = new AdminManager();
70     }
71     
72     public Configuration getConfig() {
73         return admin.getConfig();
74     }
75     
76     public void ejbRemove() {
77     }
78     
79     public void ejbActivate() {
80     }
81     
82     public void ejbPassivate() {
83     }
84     
85     public void setSessionContext(SessionContext sessionContext)
86     throws EJBException {
87         this.sessionContext = sessionContext;
88     }
89     
90     /**
91      * Read the list of roles available.
92      *
93      * @return names of roles available
94      *
95      * @throws ServerException
96      * @throws AdminException
97      */

98     public String JavaDoc[] getRoles()
99     throws ServerException, AdminException {
100         return admin.getRoles();
101     }
102     
103     /**
104      * Read all users that satisfy the parameter of search.
105      *
106      * @param clause array of conditions for the query
107      *
108      * @return array of Sync4jUser
109      *
110      * @throws ServerException
111      * @throws AdminException
112      */

113     public Sync4jUser[] getUsers(Clause clause)
114     throws ServerException, AdminException {
115         return admin.getUsers(clause);
116     }
117     
118     /**
119      * Adds a new user and the assigned role to it
120      *
121      * @param user the user to add
122      *
123      * @throws ServerException
124      * @throws AdminException
125      */

126     public void addUser(Sync4jUser user)
127     throws ServerException, AdminException {
128         admin.addUser(user);
129     }
130     
131     /**
132      * Update the information of the specific user
133      *
134      * @param user the user with informations updated
135      *
136      * @throws ServerException
137      * @throws AdminException
138      */

139     public void setUser(Sync4jUser user)
140     throws ServerException, AdminException {
141         admin.setUser(user);
142     }
143     
144     /**
145      * Delete the user
146      *
147      * @param userName the name of user to delete
148      *
149      * @throws ServerException
150      * @throws AdminException
151      */

152     public void deleteUser(String JavaDoc userName)
153     throws ServerException, AdminException {
154         admin.deleteUser(userName);
155     }
156     
157     /**
158      * Count the number of users that satisfy the specif clauses.
159      *
160      * @param clause the conditions of the search
161      *
162      * @return number of users
163      *
164      * @throws ServerException
165      * @throws AdminException
166      */

167     public int countUsers(Clause clause)
168     throws ServerException, AdminException {
169         return admin.countUsers(clause);
170     }
171     
172     /**
173      * Read a list of device that satisfy the specific conditions.
174      *
175      * @param clauses the conditions foe search informations.
176      *
177      * @return array of device
178      *
179      * @throws ServerException
180      * @throws AdminException
181      */

182     public Sync4jDevice[] getDevices(Clause clauses)
183     throws ServerException, AdminException {
184         return admin.getDevices(clauses);
185     }
186     
187     /**
188      * Adds a new device.
189      *
190      * @param d the new device
191      *
192      * @return the device id
193      *
194      * @throws ServerException
195      * @throws AdminException
196      */

197     public String JavaDoc addDevice(Sync4jDevice d)
198     throws ServerException, AdminException {
199         return admin.addDevice(d);
200     }
201     
202     /**
203      * Update the information of specific device.
204      *
205      * @param d the device to update
206      *
207      * @throws ServerException
208      * @throws AdminException
209      */

210     public void setDevice(Sync4jDevice d)
211     throws ServerException, AdminException {
212         admin.setDevice(d);
213     }
214     
215     /**
216      * Delete the specific device.
217      *
218      * @param deviceId the device id that identifies the device
219      *
220      * @throws ServerException
221      * @throws AdminException
222      */

223     public void deleteDevice(String JavaDoc deviceId)
224     throws ServerException, AdminException{
225         admin.deleteDevice(deviceId);
226     }
227     
228     /**
229      * Count the number of device that satisfy the specific clauses.
230      *
231      * @param clauses the specific conditions for search device
232      *
233      * @return the number of device finds
234      *
235      * @throws ServerException
236      * @throws AdminException
237      */

238     public int countDevices(Clause clauses)
239     throws ServerException, AdminException {
240         return admin.countDevices(clauses);
241     }
242     
243     /**
244      * Read all principal that satisfy the clauses.
245      *
246      * @param clauses the specific conditions for search principal
247      *
248      * @return array of principal
249      *
250      * @throws ServerException
251      * @throws AdminException
252      */

253     public Sync4jPrincipal[] getPrincipals(Clause clauses)
254     throws ServerException, AdminException {
255         return admin.getPrincipals(clauses);
256     }
257     
258     /**
259      * Adds a new principal.
260      *
261      * @param p the new principal
262      *
263      * @return the principal id
264      *
265      * @throws ServerException
266      * @throws AdminException
267      */

268     public String JavaDoc addPrincipal(Sync4jPrincipal p)
269     throws ServerException, AdminException {
270         return admin.addPrincipal(p);
271     }
272     
273     /**
274      * Delete the specific principal.
275      *
276      * @param principalId the principal id that identifies the principal
277      *
278      * @throws ServerException
279      * @throws AdminException
280      */

281     public void deletePrincipal(String JavaDoc principalId)
282     throws ServerException, AdminException {
283         admin.deletePrincipal(principalId);
284     }
285     
286     /**
287      * Count the number of principal that satisfy the specific clauses.
288      *
289      * @param clauses the specific conditions for search principal
290      *
291      * @return the number of principal finds
292      *
293      * @throws ServerException
294      * @throws AdminException
295      */

296     public int countPrincipals(Clause clauses)
297     throws ServerException, AdminException {
298         return admin.countPrincipals(clauses);
299     }
300     
301     /**
302      * Read all modules information
303      *
304      * @return an array with the modules information (empty if no objects are found)
305      *
306      * @throws ServerException
307      * @throws AdminException
308      */

309     public Sync4jModule[] getModulesName()
310     throws ServerException, AdminException {
311         return admin.getModulesName();
312     }
313     
314     /**
315      * Read the information of the specific module
316      *
317      * @param moduleId the module id that identifies the module to search
318      *
319      * @return the relative information to the module
320      *
321      * @throws ServerException
322      * @throws AdminException
323      */

324     public Sync4jModule getModule(String JavaDoc moduleId)
325     throws ServerException, AdminException {
326         return admin.getModule(moduleId);
327     }
328     
329     /**
330      * Adds a new source into datastore and create a relative file xml with configuration.
331      * The source must have a defined source type.
332      * The source type must refer to a connector.
333      * The connector must refer to a module.
334      *
335      * @param moduleId the module id
336      * @param connectorId the connector id
337      * @param sourceTypeId the source type id
338      * @param source the information of the new source
339      *
340      * @throws ServerException
341      * @throws AdminException
342      */

343     public void addSource(String JavaDoc moduleId, String JavaDoc connectorId, String JavaDoc sourceTypeId, SyncSource source)
344     throws ServerException, AdminException {
345         admin.addSource(moduleId, connectorId, sourceTypeId, source);
346     }
347     
348     /**
349      * Update a specific source into datastore and create a relative file xml with configuration.
350      * The source must have a defined source type.
351      * The source type must refer to a connector.
352      * The connector must refer to a module.
353      *
354      * @param moduleId the module id
355      * @param connectorId the connector id
356      * @param sourceTypeId the source type id
357      * @param source the information of the new source
358      *
359      * @throws ServerException
360      * @throws AdminException
361      */

362     public void setSource(String JavaDoc moduleId, String JavaDoc connectorId, String JavaDoc sourceTypeId, SyncSource source)
363     throws ServerException, AdminException{
364         admin.setSource(moduleId, connectorId, sourceTypeId, source);
365     }
366     
367     /**
368      * Delete a specific source and the relative file of configuration.
369      *
370      * @param sourceUri the uri that identifies the source
371      *
372      * @throws ServerException
373      * @throws AdminException
374      */

375     public void deleteSource(String JavaDoc sourceUri)
376     throws ServerException, AdminException{
377         admin.deleteSource(sourceUri);
378     }
379             
380     /**
381      * NOTE: do not use this method as it will be replaced by
382      * getServerConfiguration() in Sync4j 2.5
383      */

384     public LoggingConfiguration getLoggingConfiguration()
385     throws ServerException, AdminException {
386         return admin.getLoggingConfiguration();
387     }
388     
389     /**
390      * Returns the server bean with the given name. If the bean does not exist,
391      * am AdminException is thrown.
392      *
393      * @param bean the server bean
394      *
395      * @throws ServerException, AdminException
396      */

397     public Object JavaDoc getServerBean(String JavaDoc bean)
398     throws ServerException, AdminException {
399         return admin.getServerBean(bean);
400     }
401     
402     /**
403      * Sets the server bean with the given name.
404      *
405      * @param bean the server bean
406      * @param obj the bean instance
407      *
408      * @throws ServerException, AdminException
409      */

410     public void setServerBean(String JavaDoc bean, Object JavaDoc obj)
411     throws ServerException, AdminException {
412         admin.setServerBean(bean, obj);
413     }
414 }
415
416
Popular Tags