KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > util > BonitaConfigService


1 package hero.util;
2
3 /**
4 *
5 * Bonita
6 * Copyright (C) 1999 Bull S.A.
7 * Bull 68 route de versailles 78434 Louveciennes Cedex France
8 * Further information: bonita@objectweb.org
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 *
26 --------------------------------------------------------------------------
27 * $Id: BonitaConfigService.java,v 1.2 2004/11/29 12:29:48 mvaldes Exp $
28 *
29 --------------------------------------------------------------------------
30 */

31
32 import hero.interfaces.BnProjectLocal;
33 import hero.interfaces.BnProjectLocalHome;
34 import hero.interfaces.BnProjectConfigLocal;
35
36 import java.util.Collection JavaDoc;
37 import java.util.Iterator JavaDoc;
38
39 import javax.ejb.FinderException JavaDoc;
40 import javax.management.MBeanServer JavaDoc;
41 import javax.management.ObjectName JavaDoc;
42 import javax.management.InstanceAlreadyExistsException JavaDoc;
43 import javax.management.MBeanRegistrationException JavaDoc;
44 import javax.management.NotCompliantMBeanException JavaDoc;
45 import javax.management.MalformedObjectNameException JavaDoc;
46 import javax.naming.Context JavaDoc;
47 import org.objectweb.jonas.service.ServiceException;
48
49 //import objectweb
50
import org.objectweb.jonas.jmx.JmxService;
51 import org.objectweb.jonas.service.AbsServiceImpl;
52 import org.objectweb.jonas.service.ServiceManager;
53
54 public class BonitaConfigService extends AbsServiceImpl implements BonitaConfigServiceMBean{
55
56     private MBeanServer JavaDoc mbeanServer = null;
57     public final static String JavaDoc SERVICE_NAME = "jonas:type=service,name=BonitaConfigService";
58
59     public void doInit(Context JavaDoc ctx) throws ServiceException {
60         // Get the JMX Server via JMX Service
61
try {
62                JmxService jmx = (JmxService) ServiceManager.getInstance().getJmxService();
63                mbeanServer = jmx.getJmxServer();
64            } catch (Exception JavaDoc e) {
65             //the JMX service may not be started
66
throw new ServiceException("JMX Server is not started...");
67            }
68     }
69     
70     public void doStart() throws ServiceException {
71         try {
72             mbeanServer.registerMBean(this,new ObjectName JavaDoc(SERVICE_NAME));
73             System.out.println("BonitaConfigService :: Start Service");
74         } catch (InstanceAlreadyExistsException JavaDoc iae) {
75             throw new ServiceException("Cannot start the BonitaConfigService (Already Exists)" , iae);
76         } catch (MBeanRegistrationException JavaDoc mbre) {
77             throw new ServiceException("Cannot start the BonitaConfigService (MBean registration error)" , mbre);
78         } catch (NotCompliantMBeanException JavaDoc ncmbe) {
79             throw new ServiceException("Cannot start the BonitaConfigService (MBean Not compliant error)" , ncmbe);
80         } catch (MalformedObjectNameException JavaDoc mone) {
81             throw new ServiceException("Cannot start the BonitaConfigService (ObjectName Malformed)" , mone);
82         }
83     }
84     
85     public void doStop() throws ServiceException {
86         if (mbeanServer != null) {
87             try {
88                 mbeanServer.unregisterMBean(new ObjectName JavaDoc(SERVICE_NAME));
89             } catch (Exception JavaDoc e) {
90                 throw new ServiceException("Cannot stop the BonitaConfigService (JMX).", e);
91             }
92         }
93         System.out.println("BonitaConfigService :: Stop Service");
94     }
95     
96     public boolean getProcessJMS(String JavaDoc projectName) throws ServiceException {
97         BnProjectConfigLocal pc = this.getProjectConfig(projectName);
98         return(pc.getJMS());
99     }
100     
101     public boolean getProcessLog(String JavaDoc projectName) throws ServiceException {
102         BnProjectConfigLocal pc = this.getProjectConfig(projectName);
103         return(pc.getLog());
104         
105     }
106     
107     public boolean getProcessTrace(String JavaDoc projectName) throws ServiceException {
108         BnProjectConfigLocal pc = this.getProjectConfig(projectName);
109         return(pc.getTrace());
110     }
111     
112     public String JavaDoc getProcessLogLevel(String JavaDoc projectName) throws ServiceException {
113         BnProjectConfigLocal pc = this.getProjectConfig(projectName);
114         return(pc.getLogLevel());
115     }
116     
117     public String JavaDoc getProcessTraceLevel(String JavaDoc projectName) throws ServiceException {
118         BnProjectConfigLocal pc = this.getProjectConfig(projectName);
119         return(pc.getTraceLevel());
120     }
121     
122     public String JavaDoc getProcessHistoric(String JavaDoc projectName) throws ServiceException {
123         BnProjectConfigLocal pc = this.getProjectConfig(projectName);
124         return(pc.getHistoric());
125     }
126     
127     public void setProcessJMS(String JavaDoc projectName, boolean value) throws ServiceException {
128         BnProjectConfigLocal pc = this.getProjectConfig(projectName);
129         pc.setJMS(value);
130     }
131     
132     public void setProcessLog(String JavaDoc projectName, boolean value) throws ServiceException {
133         BnProjectConfigLocal pc = this.getProjectConfig(projectName);
134         pc.setLog(value);
135     }
136     
137     public void setProcessTrace(String JavaDoc projectName, boolean value) throws ServiceException {
138         BnProjectConfigLocal pc = this.getProjectConfig(projectName);
139         pc.setTrace(value);
140     }
141     
142     public void setProcessTraceLevel(String JavaDoc projectName, String JavaDoc value) throws ServiceException {
143         BnProjectConfigLocal pc = this.getProjectConfig(projectName);
144         pc.setTraceLevel(value);
145     }
146     
147     public void setProcessLogLevel(String JavaDoc projectName, String JavaDoc value) throws ServiceException {
148         BnProjectConfigLocal pc = this.getProjectConfig(projectName);
149         pc.setLogLevel(value);
150     }
151     
152     public void setProcessHistoric(String JavaDoc projectName, String JavaDoc value) throws ServiceException {
153         BnProjectConfigLocal pc = this.getProjectConfig(projectName);
154         pc.setHistoric(value);
155     }
156     
157     public void updateJMS(boolean value) throws ServiceException {
158         Collection JavaDoc projects = this.getProjects();
159         Iterator JavaDoc prjs = projects.iterator();
160         while (prjs.hasNext()) {
161             BnProjectLocal pj = (BnProjectLocal) prjs.next();
162             BnProjectConfigLocal pc = pj.getBnProjectConfig();
163             pc.setJMS(value);
164         }
165     }
166
167     public void updateLog(boolean value) throws ServiceException {
168         Collection JavaDoc projects = this.getProjects();
169         Iterator JavaDoc prjs = projects.iterator();
170         while (prjs.hasNext()) {
171             BnProjectLocal pj = (BnProjectLocal) prjs.next();
172             BnProjectConfigLocal pc = pj.getBnProjectConfig();
173             pc.setLog(value);
174         }
175
176     }
177
178     public void updateTrace(boolean value) throws ServiceException {
179         Collection JavaDoc projects = this.getProjects();
180         Iterator JavaDoc prjs = projects.iterator();
181         while (prjs.hasNext()) {
182             BnProjectLocal pj = (BnProjectLocal) prjs.next();
183             BnProjectConfigLocal pc = pj.getBnProjectConfig();
184             pc.setTrace(value);
185         }
186
187     }
188
189     public void updateLogLevel(String JavaDoc value) throws ServiceException {
190         Collection JavaDoc projects = this.getProjects();
191         Iterator JavaDoc prjs = projects.iterator();
192         while (prjs.hasNext()) {
193             BnProjectLocal pj = (BnProjectLocal) prjs.next();
194             BnProjectConfigLocal pc = pj.getBnProjectConfig();
195             pc.setLogLevel(value);
196         }
197     }
198
199     public void updateTraceLevel(String JavaDoc value) throws ServiceException {
200         Collection JavaDoc projects = this.getProjects();
201         Iterator JavaDoc prjs = projects.iterator();
202         while (prjs.hasNext()) {
203             BnProjectLocal pj = (BnProjectLocal) prjs.next();
204             BnProjectConfigLocal pc = pj.getBnProjectConfig();
205             pc.setTraceLevel(value);
206         }
207     }
208
209     public void updateHistoric(String JavaDoc value) throws ServiceException {
210         Collection JavaDoc projects = this.getProjects();
211         Iterator JavaDoc prjs = projects.iterator();
212         while (prjs.hasNext()) {
213             BnProjectLocal pj = (BnProjectLocal) prjs.next();
214             BnProjectConfigLocal pc = pj.getBnProjectConfig();
215             pc.setHistoric(value);
216         }
217     }
218         
219     private BnProjectConfigLocal getProjectConfig(String JavaDoc projectName) throws ServiceException{
220         BnProjectLocalHome phome = null;
221         BnProjectLocal plocal = null;
222         try {
223              phome = hero.interfaces.BnProjectUtil.getLocalHome();
224              plocal = phome.findByName(projectName);
225              return(plocal.getBnProjectConfig());
226          } catch (javax.naming.NamingException JavaDoc ne) {
227              throw new ServiceException(ne.getMessage());
228          } catch (FinderException JavaDoc fie) {
229              throw new ServiceException(fie.getMessage());
230          }
231     }
232     
233     private Collection JavaDoc getProjects() throws ServiceException{
234         BnProjectLocalHome phome = null;
235         BnProjectLocal plocal = null;
236         try {
237             phome = hero.interfaces.BnProjectUtil.getLocalHome();
238             Collection JavaDoc projects = phome.findAll();
239             return projects;
240         } catch (javax.naming.NamingException JavaDoc ne) {
241             throw new ServiceException(ne.getMessage());
242         } catch (FinderException JavaDoc fie) {
243             throw new ServiceException(fie.getMessage());
244         }
245     }
246 }
247
Popular Tags