001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial Developer : Guillaume Sauthier
022: *
023: * --------------------------------------------------------------------------
024: * $Id: ClientManagerWrapper.java 4960 2004-06-16 15:57:47Z benoitf $
025: * --------------------------------------------------------------------------
026: */package org.objectweb.jonas_client.deployment.lib.wrapper;
027:
028: import java.lang.reflect.InvocationTargetException;
029: import java.lang.reflect.Method;
030: import java.net.URL;
031: import java.net.URLClassLoader;
032:
033: import org.objectweb.jonas_client.deployment.api.ClientContainerDeploymentDesc;
034: import org.objectweb.jonas_client.deployment.api.ClientContainerDeploymentDescException;
035:
036: import org.objectweb.jonas.common.Log;
037: import org.objectweb.jonas.server.LoaderManager;
038:
039: import org.objectweb.util.monolog.api.BasicLevel;
040: import org.objectweb.util.monolog.api.Logger;
041:
042: /**
043: * Wrap the call to ClientDeploymentDescManager during JOnAS runtime to solve
044: * classloader problem with Digester.
045: *
046: * @author Guillaume Sauthier
047: */
048: public class ClientManagerWrapper {
049:
050: /**
051: * logger
052: */
053: private static Logger logger = Log
054: .getLogger(Log.JONAS_CLIENT_PREFIX);
055:
056: /**
057: * Private Empty constructor for utility class.
058: */
059: private ClientManagerWrapper() {
060: }
061:
062: /**
063: * Wrap the ClientDeploymentDescManager.getDeploymentDesc(URL, ClassLoader,
064: * ClassLoader).
065: *
066: * @param url URL of the client to deploy
067: * @param moduleCL ClassLoader of the Client
068: * @param earCL ClassLoader of the application wrapping the client.
069: *
070: * @return the ClientContainerDeploymentDesc found at the given URL.
071: * @throws ClientContainerDeploymentDescException When deployment fails.
072: */
073: public static ClientContainerDeploymentDesc getDeploymentDesc(
074: URL url, ClassLoader moduleCL, ClassLoader earCL)
075: throws ClientContainerDeploymentDescException {
076: LoaderManager lm = LoaderManager.getInstance();
077: ClientContainerDeploymentDesc ccDD = null;
078:
079: try {
080: ClassLoader tools = lm.getToolsLoader();
081: Class manager = tools
082: .loadClass("org.objectweb.jonas_client.deployment.lib.ClientDeploymentDescManager");
083: Method m = manager.getDeclaredMethod("getInstance",
084: new Class[] {});
085: Object instance = m.invoke(null, new Object[] {});
086: m = manager.getDeclaredMethod("getDeploymentDesc",
087: new Class[] { URL.class, ClassLoader.class,
088: ClassLoader.class });
089: ccDD = (ClientContainerDeploymentDesc) m.invoke(instance,
090: new Object[] { url, moduleCL, earCL });
091: } catch (InvocationTargetException ite) {
092: Throwable t = ite.getTargetException();
093: if (ClientContainerDeploymentDescException.class
094: .isInstance(t)) {
095: throw (ClientContainerDeploymentDescException) ite
096: .getTargetException();
097: } else {
098: throw new ClientContainerDeploymentDescException(
099: "ClientDeploymentDescManager.getDeploymentDesc fails",
100: t);
101: }
102: } catch (Exception e) {
103: e.printStackTrace();
104: // TODO add i18n here
105: throw new ClientContainerDeploymentDescException(
106: "Problems when using reflection on ClientDeploymentDescManager",
107: e);
108: }
109:
110: return ccDD;
111: }
112:
113: /**
114: * Wrap the ClientDeploymentDescManager.getInstance().setAltDD(ClassLoader, URL[], URL[])
115: *
116: * @param earClassLoader ClassLoader of the Application wrapping the Client
117: * @param clientUrls Array of ClientApplication URL
118: * @param clientsAltDDs Array of Client Alternative Deployment Desc URL
119: */
120: public static void setAltDD(URLClassLoader earClassLoader,
121: URL[] clientUrls, URL[] clientsAltDDs) {
122: LoaderManager lm = LoaderManager.getInstance();
123: try {
124: ClassLoader tools = lm.getToolsLoader();
125: Class manager = tools
126: .loadClass("org.objectweb.jonas_client.deployment.lib.ClientDeploymentDescManager");
127: Method m = manager.getDeclaredMethod("getInstance",
128: new Class[] {});
129: Object instance = m.invoke(null, new Object[] {});
130: m = manager.getDeclaredMethod("setAltDD", new Class[] {
131: ClassLoader.class, URL[].class, URL[].class });
132: m.invoke(instance, new Object[] { earClassLoader,
133: clientUrls, clientsAltDDs });
134: } catch (Exception e) {
135: // Should never occurs
136: logger.log(BasicLevel.ERROR, e);
137: }
138: }
139:
140: }
|