KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ws > deployment > lib > wrapper > WSManagerWrapper


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 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: WSManagerWrapper.java,v 1.3 2004/07/06 12:59:10 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.jonas_ws.deployment.lib.wrapper;
26
27 import java.lang.reflect.InvocationTargetException JavaDoc;
28 import java.lang.reflect.Method JavaDoc;
29 import java.net.URL JavaDoc;
30
31 import org.objectweb.jonas_ws.deployment.api.WSDeploymentDesc;
32 import org.objectweb.jonas_ws.deployment.api.WSDeploymentDescException;
33
34 import org.objectweb.jonas.common.Log;
35 import org.objectweb.jonas.server.LoaderManager;
36
37 import org.objectweb.util.monolog.api.BasicLevel;
38 import org.objectweb.util.monolog.api.Logger;
39
40
41 /**
42  * Wrap the WSDeploymentDescManager to solve ClassLoader problems linked to
43  * Digester.
44  *
45  * @author Guillaume Sauthier
46  */

47 public class WSManagerWrapper {
48
49     /**
50      * WSDeploymentDescManager fully qualified classname
51      */

52     private static final String JavaDoc WS_MANAGER_CLASSNAME = "org.objectweb.jonas_ws.deployment.lib.WSDeploymentDescManager";
53
54     /**
55      * logger
56      */

57     private static Logger logger = Log.getLogger(Log.JONAS_EAR_PREFIX);
58
59     /**
60      * Private Empty Constructor for utility class
61      */

62     private WSManagerWrapper() { }
63
64     /**
65      * Wrap the WSDeploymentDescManager.getInstance().getDeploymentDesc(url, moduleCL, earCL) call.
66      *
67      * @param url module URL
68      * @param moduleCL module ClassLoader
69      * @param earCL Application ClassLoader
70      *
71      * @return the WSDeploymentDesc of the given module
72      *
73      * @throws WSDeploymentDescException When WSDeploymentDesc cannot be instanciated.
74      */

75     public static WSDeploymentDesc getDeploymentDesc(URL JavaDoc url, ClassLoader JavaDoc moduleCL, ClassLoader JavaDoc earCL)
76     throws WSDeploymentDescException {
77         LoaderManager lm = LoaderManager.getInstance();
78         WSDeploymentDesc wsDD = null;
79
80         try {
81             ClassLoader JavaDoc tools = lm.getToolsLoader();
82             Class JavaDoc manager = tools.loadClass(WS_MANAGER_CLASSNAME);
83             Method JavaDoc m = manager.getDeclaredMethod("getInstance", new Class JavaDoc[] {});
84             Object JavaDoc instance = m.invoke(null, new Object JavaDoc[] {});
85             m = manager.getDeclaredMethod("getDeploymentDesc", new Class JavaDoc[] {URL JavaDoc.class, ClassLoader JavaDoc.class,
86                     ClassLoader JavaDoc.class});
87             wsDD = (WSDeploymentDesc) m.invoke(instance, new Object JavaDoc[] {url, moduleCL, earCL});
88         } catch (InvocationTargetException JavaDoc ite) {
89             Throwable JavaDoc t = ite.getTargetException();
90             if (WSDeploymentDescException.class.isInstance(t)) {
91                 throw (WSDeploymentDescException) ite.getTargetException();
92             } else {
93                 throw new WSDeploymentDescException("WSDeploymentDescManager.getDeploymentDesc fails", t);
94             }
95         } catch (Exception JavaDoc e) {
96             // TODO add i18n here
97
throw new WSDeploymentDescException("Problems when using reflection on WSDeploymentDescManager", e);
98         }
99
100         return wsDD;
101     }
102
103     /**
104      * Wrap the WSDeploymentDescManager.getInstance().getDeploymentDesc(url, url, moduleCL, earCL) call.
105      *
106      * @param url module URL
107      * @param unpackedURL unpacked URL of the module (may be null)
108      * @param moduleCL module ClassLoader
109      * @param earCL Application ClassLoader
110      *
111      * @return the WSDeploymentDesc of the given module
112      *
113      * @throws WSDeploymentDescException When WSDeploymentDesc cannot be instanciated.
114      */

115     public static WSDeploymentDesc getDeploymentDesc(URL JavaDoc url, URL JavaDoc unpackedURL, ClassLoader JavaDoc moduleCL, ClassLoader JavaDoc earCL)
116     throws WSDeploymentDescException {
117         LoaderManager lm = LoaderManager.getInstance();
118         WSDeploymentDesc wsDD = null;
119
120         try {
121             ClassLoader JavaDoc tools = lm.getToolsLoader();
122             Class JavaDoc manager = tools.loadClass(WS_MANAGER_CLASSNAME);
123             Method JavaDoc m = manager.getDeclaredMethod("getInstance", new Class JavaDoc[] {});
124             Object JavaDoc instance = m.invoke(null, new Object JavaDoc[] {});
125             m = manager.getDeclaredMethod("getDeploymentDesc", new Class JavaDoc[] {URL JavaDoc.class, URL JavaDoc.class, ClassLoader JavaDoc.class,
126                     ClassLoader JavaDoc.class});
127             wsDD = (WSDeploymentDesc) m.invoke(instance, new Object JavaDoc[] {url, unpackedURL, moduleCL, earCL});
128         } catch (InvocationTargetException JavaDoc ite) {
129             Throwable JavaDoc t = ite.getTargetException();
130             if (WSDeploymentDescException.class.isInstance(t)) {
131                 throw (WSDeploymentDescException) ite.getTargetException();
132             } else {
133                 throw new WSDeploymentDescException("WSDeploymentDescManager.getDeploymentDesc fails", t);
134             }
135         } catch (Exception JavaDoc e) {
136             // TODO add i18n here
137
throw new WSDeploymentDescException("Problems when using reflection on WSDeploymentDescManager", e);
138         }
139
140         return wsDD;
141     }
142
143     /**
144      * Wrap the WSDeploymentDescManager.setParsingWithValidation() call.
145      *
146      * @param b true/false
147      */

148     public static void setParsingWithValidation(boolean b) {
149         LoaderManager lm = LoaderManager.getInstance();
150
151         try {
152             ClassLoader JavaDoc tools = lm.getToolsLoader();
153             Class JavaDoc manager = tools.loadClass(WS_MANAGER_CLASSNAME);
154             Method JavaDoc m = manager.getDeclaredMethod("setParsingWithValidation", new Class JavaDoc[] {boolean.class});
155             m.invoke(null, new Object JavaDoc[] {new Boolean JavaDoc(b)});
156         } catch (Exception JavaDoc e) {
157             // Should never occurs
158
logger.log(BasicLevel.ERROR, e);
159         }
160     }
161
162     /**
163      * Wrap the WSDeploymentDescManager.getInstance().removeCache() call.
164      *
165      * @param cl WebApp ClassLoader
166      */

167     public static void removeCache(ClassLoader JavaDoc cl) {
168         LoaderManager lm = LoaderManager.getInstance();
169
170         try {
171             ClassLoader JavaDoc tools = lm.getToolsLoader();
172             Class JavaDoc manager = tools.loadClass(WS_MANAGER_CLASSNAME);
173             Method JavaDoc m = manager.getDeclaredMethod("getInstance", new Class JavaDoc[] {});
174             Object JavaDoc instance = m.invoke(null, new Object JavaDoc[] {});
175             m = manager.getDeclaredMethod("removeCache", new Class JavaDoc[] {ClassLoader JavaDoc.class});
176             m.invoke(instance, new Object JavaDoc[] {cl});
177         } catch (Exception JavaDoc e) {
178             // Should never occurs
179
logger.log(BasicLevel.ERROR, e);
180         }
181     }
182
183 }
184
Popular Tags