KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_client > deployment > lib > wrapper > ClientManagerWrapper


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  * Initial Developer : Guillaume Sauthier
22  *
23  * --------------------------------------------------------------------------
24  * $Id: ClientManagerWrapper.java,v 1.2 2004/06/16 15:57:47 benoitf Exp $
25  * --------------------------------------------------------------------------
26  */

27 package org.objectweb.jonas_client.deployment.lib.wrapper;
28
29 import java.lang.reflect.InvocationTargetException JavaDoc;
30 import java.lang.reflect.Method JavaDoc;
31 import java.net.URL JavaDoc;
32 import java.net.URLClassLoader JavaDoc;
33
34 import org.objectweb.jonas_client.deployment.api.ClientContainerDeploymentDesc;
35 import org.objectweb.jonas_client.deployment.api.ClientContainerDeploymentDescException;
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  * Wrap the call to ClientDeploymentDescManager during JOnAS runtime to solve
45  * classloader problem with Digester.
46  *
47  * @author Guillaume Sauthier
48  */

49 public class ClientManagerWrapper {
50
51     /**
52      * logger
53      */

54     private static Logger logger = Log.getLogger(Log.JONAS_CLIENT_PREFIX);
55
56     /**
57      * Private Empty constructor for utility class.
58      */

59     private ClientManagerWrapper() { }
60
61     /**
62      * Wrap the ClientDeploymentDescManager.getDeploymentDesc(URL, ClassLoader,
63      * ClassLoader).
64      *
65      * @param url URL of the client to deploy
66      * @param moduleCL ClassLoader of the Client
67      * @param earCL ClassLoader of the application wrapping the client.
68      *
69      * @return the ClientContainerDeploymentDesc found at the given URL.
70      * @throws ClientContainerDeploymentDescException When deployment fails.
71      */

72     public static ClientContainerDeploymentDesc getDeploymentDesc(URL JavaDoc url, ClassLoader JavaDoc moduleCL, ClassLoader JavaDoc earCL)
73             throws ClientContainerDeploymentDescException {
74         LoaderManager lm = LoaderManager.getInstance();
75         ClientContainerDeploymentDesc ccDD = null;
76
77         try {
78             ClassLoader JavaDoc tools = lm.getToolsLoader();
79             Class JavaDoc manager = tools.loadClass("org.objectweb.jonas_client.deployment.lib.ClientDeploymentDescManager");
80             Method JavaDoc m = manager.getDeclaredMethod("getInstance", new Class JavaDoc[] {});
81             Object JavaDoc instance = m.invoke(null, new Object JavaDoc[] {});
82             m = manager.getDeclaredMethod("getDeploymentDesc", new Class JavaDoc[] {URL JavaDoc.class, ClassLoader JavaDoc.class,
83                     ClassLoader JavaDoc.class});
84             ccDD = (ClientContainerDeploymentDesc) m.invoke(instance, new Object JavaDoc[] {url, moduleCL, earCL});
85         } catch (InvocationTargetException JavaDoc ite) {
86             Throwable JavaDoc t = ite.getTargetException();
87             if (ClientContainerDeploymentDescException.class.isInstance(t)) {
88                 throw (ClientContainerDeploymentDescException) ite.getTargetException();
89             } else {
90                 throw new ClientContainerDeploymentDescException("ClientDeploymentDescManager.getDeploymentDesc fails", t);
91             }
92         } catch (Exception JavaDoc e) {
93             e.printStackTrace();
94             // TODO add i18n here
95
throw new ClientContainerDeploymentDescException("Problems when using reflection on ClientDeploymentDescManager", e);
96         }
97
98         return ccDD;
99     }
100
101     /**
102      * Wrap the ClientDeploymentDescManager.getInstance().setAltDD(ClassLoader, URL[], URL[])
103      *
104      * @param earClassLoader ClassLoader of the Application wrapping the Client
105      * @param clientUrls Array of ClientApplication URL
106      * @param clientsAltDDs Array of Client Alternative Deployment Desc URL
107      */

108     public static void setAltDD(URLClassLoader JavaDoc earClassLoader, URL JavaDoc[] clientUrls, URL JavaDoc[] clientsAltDDs) {
109         LoaderManager lm = LoaderManager.getInstance();
110         try {
111             ClassLoader JavaDoc tools = lm.getToolsLoader();
112             Class JavaDoc manager = tools.loadClass("org.objectweb.jonas_client.deployment.lib.ClientDeploymentDescManager");
113             Method JavaDoc m = manager.getDeclaredMethod("getInstance", new Class JavaDoc[] {});
114             Object JavaDoc instance = m.invoke(null, new Object JavaDoc[] {});
115             m = manager.getDeclaredMethod("setAltDD", new Class JavaDoc[] {ClassLoader JavaDoc.class, URL JavaDoc[].class, URL JavaDoc[].class});
116             m.invoke(instance, new Object JavaDoc[] {earClassLoader, clientUrls, clientsAltDDs});
117         } catch (Exception JavaDoc e) {
118             // Should never occurs
119
logger.log(BasicLevel.ERROR, e);
120         }
121     }
122
123 }
Popular Tags