KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > deployment > lib > wrapper > EjbManagerWrapper


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: EjbManagerWrapper.java,v 1.1 2004/05/25 14:26:34 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.jonas_ejb.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 import java.net.URLClassLoader JavaDoc;
31
32 import org.objectweb.jonas_ejb.deployment.api.DeploymentDesc;
33
34 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
35
36 import org.objectweb.jonas.common.Log;
37 import org.objectweb.jonas.server.LoaderManager;
38
39 import org.objectweb.util.monolog.api.BasicLevel;
40 import org.objectweb.util.monolog.api.Logger;
41
42
43 /**
44  * Wrap the EjbDeploymentDescManager to solve ClassLoader problems linked to Digester.
45  *
46  * @author Guillaume Sauthier
47  */

48 public class EjbManagerWrapper {
49
50     /**
51      * EjbDeploymentDescManager fully qualified classname
52      */

53     private static final String JavaDoc EJB_MANAGER_CLASSNAME = "org.objectweb.jonas_ejb.deployment.lib.EjbDeploymentDescManager";
54
55     /**
56      * logger
57      */

58     private static Logger logger = Log.getLogger(Log.JONAS_EAR_PREFIX);
59
60     /**
61      * Private empty constructor for utility class
62      */

63     private EjbManagerWrapper() { }
64
65     /**
66      * Wrap EjbDeploymentDescManager.getInstance().getDeploymentDesc()
67      *
68      * @param url EjbJar URL
69      * @param moduleCL EjbJar ClassLoader
70      * @param earCL Application ClassLoader
71      *
72      * @return the EjbJar DeploymentDesc of the given EjbJar
73      *
74      * @throws DeploymentDescException When DeploymentDesc cannot be instanciated
75      */

76     public static DeploymentDesc getDeploymentDesc(URL JavaDoc url, ClassLoader JavaDoc moduleCL, ClassLoader JavaDoc earCL)
77     throws DeploymentDescException {
78         LoaderManager lm = LoaderManager.getInstance();
79         DeploymentDesc dd = null;
80
81         try {
82             ClassLoader JavaDoc tools = lm.getToolsLoader();
83             Class JavaDoc manager = tools.loadClass(EJB_MANAGER_CLASSNAME);
84             Method JavaDoc m = manager.getDeclaredMethod("getInstance", new Class JavaDoc[] {});
85             Object JavaDoc instance = m.invoke(null, new Object JavaDoc[] {});
86             m = manager.getDeclaredMethod("getDeploymentDesc", new Class JavaDoc[] {URL JavaDoc.class, ClassLoader JavaDoc.class, ClassLoader JavaDoc.class});
87             dd = (DeploymentDesc) m.invoke(instance, new Object JavaDoc[] {url, moduleCL, earCL});
88         } catch (InvocationTargetException JavaDoc ite) {
89             Throwable JavaDoc t = ite.getTargetException();
90             if (DeploymentDescException.class.isInstance(t)) {
91                 throw (DeploymentDescException) ite.getTargetException();
92             } else {
93                 throw new DeploymentDescException("EjbDeploymentDescManager.getDeploymentDesc fails", t);
94             }
95         } catch (Exception JavaDoc e) {
96             // TODO add i18n here
97
throw new DeploymentDescException("Problems when using reflection on EjbDeploymentDescManager", e);
98         }
99
100         return dd;
101     }
102
103     /**
104      * Wrap EjbDeploymentDescManager.getInstance().setAvailableEjbJarsAndAltDDs()
105      *
106      * @param earClassLoader Application ClassLoader
107      * @param jarUrls Array of EjbJar URLs
108      * @param ejbsAltDDs Array of alternatives EjbJar Descriptor URLs
109      */

110     public static void setAvailableEjbJarsAndAltDDs(URLClassLoader JavaDoc earClassLoader, URL JavaDoc[] jarUrls, URL JavaDoc[] ejbsAltDDs) {
111         LoaderManager lm = LoaderManager.getInstance();
112         try {
113             ClassLoader JavaDoc tools = lm.getToolsLoader();
114             Class JavaDoc manager = tools.loadClass(EJB_MANAGER_CLASSNAME);
115             Method JavaDoc m = manager.getDeclaredMethod("getInstance", new Class JavaDoc[] {});
116             Object JavaDoc instance = m.invoke(null, new Object JavaDoc[] {});
117             m = manager.getDeclaredMethod("setAvailableEjbJarsAndAltDDs", new Class JavaDoc[] {ClassLoader JavaDoc.class, URL JavaDoc[].class, URL JavaDoc[].class});
118             m.invoke(instance, new Object JavaDoc[] {earClassLoader, jarUrls, ejbsAltDDs});
119         } catch (Exception JavaDoc e) {
120             // Should never occurs
121
logger.log(BasicLevel.ERROR, e);
122         }
123     }
124
125     /**
126      * Wrap EjbDeploymentDescManager.setParsingWithValidation()
127      *
128      * @param b true/false
129      */

130     public static void setParsingWithValidation(boolean b) {
131         LoaderManager lm = LoaderManager.getInstance();
132         try {
133             ClassLoader JavaDoc tools = lm.getToolsLoader();
134             Class JavaDoc manager = tools.loadClass(EJB_MANAGER_CLASSNAME);
135             Method JavaDoc m = manager.getDeclaredMethod("setParsingWithValidation", new Class JavaDoc[] {boolean.class});
136             m.invoke(null, new Object JavaDoc[] {new Boolean JavaDoc(b)});
137         } catch (Exception JavaDoc e) {
138             // Should never occurs
139
logger.log(BasicLevel.ERROR, e);
140         }
141     }
142
143     /**
144      * Wrap EjbDeploymentDescManager.getInstance().removeCache()
145      *
146      * @param classLoader EjbJar Classloader
147      */

148     public static void removeCache(ClassLoader JavaDoc classLoader) {
149         LoaderManager lm = LoaderManager.getInstance();
150         try {
151             ClassLoader JavaDoc tools = lm.getToolsLoader();
152             Class JavaDoc manager = tools.loadClass(EJB_MANAGER_CLASSNAME);
153             Method JavaDoc m = manager.getDeclaredMethod("getInstance", new Class JavaDoc[] {});
154             Object JavaDoc instance = m.invoke(null, new Object JavaDoc[] {});
155             m = manager.getDeclaredMethod("removeCache", new Class JavaDoc[] {ClassLoader JavaDoc.class});
156             m.invoke(instance, new Object JavaDoc[] {classLoader});
157         } catch (Exception JavaDoc e) {
158             // Should never occurs
159
logger.log(BasicLevel.ERROR, e);
160         }
161     }
162
163 }
164
Popular Tags