KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > web > catalina55 > WebModuleProxy


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2003-2005 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 any 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: WebModuleProxy.java,v 1.2 2005/05/05 16:09:14 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.web.catalina55;
27
28 import javax.management.InstanceNotFoundException JavaDoc;
29 import javax.management.MBeanException JavaDoc;
30 import javax.management.MBeanServer JavaDoc;
31 import javax.management.MalformedObjectNameException JavaDoc;
32 import javax.management.ObjectName JavaDoc;
33 import javax.management.ReflectionException JavaDoc;
34
35 import org.objectweb.jonas.server.LoaderManager;
36
37 /**
38  * @author Adriana Danes
39  *
40  * This is a proxy class which uses the Catalina WebModule MBean to
41  * invoke start/stop/reload operations.
42  */

43 public class WebModuleProxy implements WebModuleProxyMBean {
44     /**
45      * The reference of the MBeanServer in which are registered both
46      * Catalina's WebModule and JOnAS's WebModuleProxy MBeans
47      */

48     private MBeanServer JavaDoc myServer = null;
49
50     /**
51      * Start Web module
52      * @param webModuleName WebModule MBean's ObjectName
53      */

54     public void start(String JavaDoc webModuleName) {
55         try {
56             ObjectName JavaDoc onWebModule = ObjectName.getInstance(webModuleName);
57             // Set Catalina class loader before making the invoke
58
ClassLoader JavaDoc old = Thread.currentThread().getContextClassLoader();
59             Thread.currentThread().setContextClassLoader(LoaderManager.getInstance().getCatalinaLoader());
60             myServer.invoke(onWebModule, "start", null, null);
61             // Restore the class loader
62
Thread.currentThread().setContextClassLoader(old);
63         } catch (MalformedObjectNameException JavaDoc e) {
64             // TODO Auto-generated catch block
65
e.printStackTrace();
66         } catch (InstanceNotFoundException JavaDoc e) {
67             // TODO Auto-generated catch block
68
e.printStackTrace();
69         } catch (MBeanException JavaDoc e) {
70             // TODO Auto-generated catch block
71
e.printStackTrace();
72         } catch (ReflectionException JavaDoc e) {
73             // TODO Auto-generated catch block
74
e.printStackTrace();
75         } catch (Exception JavaDoc e) {
76             // TODO Auto-generated catch block
77
e.printStackTrace();
78         }
79     }
80
81     /**
82      * Stop Web module
83      * @param webModuleName WebModule MBean's ObjectName
84      */

85     public void stop(String JavaDoc webModuleName) {
86         try {
87             ObjectName JavaDoc onWebModule = ObjectName.getInstance(webModuleName);
88             // Set Catalina class loader before making the invoke
89
ClassLoader JavaDoc old = Thread.currentThread().getContextClassLoader();
90             Thread.currentThread().setContextClassLoader(LoaderManager.getInstance().getCatalinaLoader());
91             myServer.invoke(onWebModule, "stop", null, null);
92             // Restore the class loader
93
Thread.currentThread().setContextClassLoader(old);
94         } catch (MalformedObjectNameException JavaDoc e) {
95             // TODO Auto-generated catch block
96
e.printStackTrace();
97         } catch (InstanceNotFoundException JavaDoc e) {
98             // TODO Auto-generated catch block
99
e.printStackTrace();
100         } catch (MBeanException JavaDoc e) {
101             // TODO Auto-generated catch block
102
e.printStackTrace();
103         } catch (ReflectionException JavaDoc e) {
104             // TODO Auto-generated catch block
105
e.printStackTrace();
106         } catch (Exception JavaDoc e) {
107             // TODO Auto-generated catch block
108
e.printStackTrace();
109         }
110     }
111
112     /**
113      * Reload Web module
114      * @param webModuleName WebModule MBean's ObjectName
115      */

116     public void reload(String JavaDoc webModuleName) {
117         try {
118             ObjectName JavaDoc onWebModule = ObjectName.getInstance(webModuleName);
119             // Set Catalina class loader before making the invoke
120
ClassLoader JavaDoc old = Thread.currentThread().getContextClassLoader();
121             Thread.currentThread().setContextClassLoader(LoaderManager.getInstance().getCatalinaLoader());
122             myServer.invoke(onWebModule, "reload", null, null);
123             // Restore the class loader
124
Thread.currentThread().setContextClassLoader(old);
125         } catch (MalformedObjectNameException JavaDoc e) {
126             // TODO Auto-generated catch block
127
e.printStackTrace();
128         } catch (InstanceNotFoundException JavaDoc e) {
129             // TODO Auto-generated catch block
130
e.printStackTrace();
131         } catch (MBeanException JavaDoc e) {
132             // TODO Auto-generated catch block
133
e.printStackTrace();
134         } catch (ReflectionException JavaDoc e) {
135             // TODO Auto-generated catch block
136
e.printStackTrace();
137         } catch (Exception JavaDoc e) {
138             // TODO Auto-generated catch block
139
e.printStackTrace();
140         }
141     }
142     /**
143      * @param myServer The myServer to set.
144      */

145     protected void setMyServer(MBeanServer JavaDoc myServer) {
146         this.myServer = myServer;
147     }
148 }
149
Popular Tags