KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_rar > deployment > lib > wrapper > RarManagerWrapper


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

25 package org.objectweb.jonas_rar.deployment.lib.wrapper;
26
27 import java.lang.reflect.InvocationTargetException JavaDoc;
28 import java.lang.reflect.Method JavaDoc;
29
30 import javax.naming.Context JavaDoc;
31
32 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
33
34 import org.objectweb.jonas_rar.deployment.api.RarDeploymentDesc;
35 import org.objectweb.jonas_rar.deployment.api.RarDeploymentDescException;
36
37 import org.objectweb.jonas.common.Log;
38 import org.objectweb.jonas.server.LoaderManager;
39
40 import org.objectweb.util.monolog.api.BasicLevel;
41 import org.objectweb.util.monolog.api.Logger;
42
43
44 /**
45  * Wrap the RarDeploymentDescManager in this class to solve the ClassLoader problem of Digester.
46  *
47  * @author Guillaume Sauthier
48  */

49 public class RarManagerWrapper {
50
51     /**
52      * RarDeploymentDescManager fully qualified classname
53      */

54     private static final String JavaDoc RAR_MANAGER_CLASSNAME = "org.objectweb.jonas_rar.deployment.lib.RarDeploymentDescManager";
55
56     /**
57      * logger
58      */

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

64     private RarManagerWrapper() {
65     }
66
67     /**
68      * Returns the RarDeploymentDesc corresponding to the Rar filename.
69      *
70      * @param rar Rar filename
71      * @param cl ClassLoader to use
72      *
73      * @return the RarDeploymentDesc corresponding to the Rar filename
74      *
75      * @throws DeploymentDescException when Rar deployment fails
76      */

77     public static RarDeploymentDesc getRarDeploymentDesc(String JavaDoc rar, ClassLoader JavaDoc cl)
78     throws DeploymentDescException {
79         LoaderManager lm = LoaderManager.getInstance();
80         RarDeploymentDesc rarDD = null;
81         try {
82             ClassLoader JavaDoc tools = lm.getToolsLoader();
83             Class JavaDoc manager = tools.loadClass(RAR_MANAGER_CLASSNAME);
84             Method JavaDoc m = manager.getDeclaredMethod("getInstance", new Class JavaDoc[] {java.lang.String JavaDoc.class, java.lang.ClassLoader JavaDoc.class});
85             rarDD = (RarDeploymentDesc) m.invoke(null, new Object JavaDoc[] {rar, cl});
86         } catch (InvocationTargetException JavaDoc ite) {
87             Throwable JavaDoc t = ite.getTargetException();
88             if (RarDeploymentDescException.class.isInstance(t)) {
89                 throw (RarDeploymentDescException) ite.getTargetException();
90             } else {
91                 throw new RarDeploymentDescException("RarDeploymentDescManager.getInstance fails", t);
92             }
93         } catch (Exception JavaDoc e) {
94             // TODO add i18n here
95
throw new RarDeploymentDescException("Problems when using reflection on RarDeploymentDescManager", e);
96         }
97         return rarDD;
98     }
99
100     /**
101      * Wrap the RarDeploymentDescManager.setParsingWithValidation(boolean)
102      *
103      * @param b boolean
104      */

105     public static void setParsingWithValidation(boolean b) {
106         LoaderManager lm = LoaderManager.getInstance();
107
108         try {
109             ClassLoader JavaDoc tools = lm.getToolsLoader();
110             Class JavaDoc manager = tools.loadClass(RAR_MANAGER_CLASSNAME);
111             Method JavaDoc m = manager.getDeclaredMethod("setParsingWithValidation", new Class JavaDoc[] {boolean.class});
112             m.invoke(null, new Object JavaDoc[] {new Boolean JavaDoc(b)});
113         } catch (Exception JavaDoc e) {
114             // Should never occurs
115
logger.log(BasicLevel.ERROR, e);
116         }
117     }
118
119     /**
120      * Wrap the RarDeploymentDescManager.getInstance(Context).
121      *
122      * @param ctx Context
123      *
124      * @return RarDeploymentDesc
125      *
126      * @throws DeploymentDescException When init fails
127      */

128     public static RarDeploymentDesc getInstance(Context JavaDoc ctx) throws DeploymentDescException {
129         LoaderManager lm = LoaderManager.getInstance();
130         RarDeploymentDesc rarDD = null;
131
132         try {
133             ClassLoader JavaDoc tools = lm.getToolsLoader();
134             Class JavaDoc manager = tools.loadClass(RAR_MANAGER_CLASSNAME);
135             Method JavaDoc m = manager.getDeclaredMethod("getInstance", new Class JavaDoc[] {javax.naming.Context JavaDoc.class});
136             rarDD = (RarDeploymentDesc) m.invoke(null, new Object JavaDoc[] {ctx});
137         } catch (InvocationTargetException JavaDoc ite) {
138             Throwable JavaDoc t = ite.getTargetException();
139             if (RarDeploymentDescException.class.isInstance(t)) {
140                 throw (RarDeploymentDescException) ite.getTargetException();
141             } else {
142                 throw new RarDeploymentDescException("RarDeploymentDescManager.getInstance fails", t);
143             }
144         } catch (Exception JavaDoc e) {
145             // TODO add i18n here
146
throw new RarDeploymentDescException("Problems when using reflection on RarDeploymentDescManager", e);
147         }
148
149         return rarDD;
150     }
151
152 }
153
Popular Tags