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: * --------------------------------------------------------------------------
022: * $Id: RarManagerWrapper.java 4799 2004-05-25 14:26:36Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_rar.deployment.lib.wrapper;
025:
026: import java.lang.reflect.InvocationTargetException;
027: import java.lang.reflect.Method;
028:
029: import javax.naming.Context;
030:
031: import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
032:
033: import org.objectweb.jonas_rar.deployment.api.RarDeploymentDesc;
034: import org.objectweb.jonas_rar.deployment.api.RarDeploymentDescException;
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 RarDeploymentDescManager in this class to solve the ClassLoader problem of Digester.
044: *
045: * @author Guillaume Sauthier
046: */
047: public class RarManagerWrapper {
048:
049: /**
050: * RarDeploymentDescManager fully qualified classname
051: */
052: private static final String RAR_MANAGER_CLASSNAME = "org.objectweb.jonas_rar.deployment.lib.RarDeploymentDescManager";
053:
054: /**
055: * logger
056: */
057: private static Logger logger = Log.getLogger(Log.JONAS_EAR_PREFIX);
058:
059: /**
060: * Empty private constructor for utility class
061: */
062: private RarManagerWrapper() {
063: }
064:
065: /**
066: * Returns the RarDeploymentDesc corresponding to the Rar filename.
067: *
068: * @param rar Rar filename
069: * @param cl ClassLoader to use
070: *
071: * @return the RarDeploymentDesc corresponding to the Rar filename
072: *
073: * @throws DeploymentDescException when Rar deployment fails
074: */
075: public static RarDeploymentDesc getRarDeploymentDesc(String rar,
076: ClassLoader cl) throws DeploymentDescException {
077: LoaderManager lm = LoaderManager.getInstance();
078: RarDeploymentDesc rarDD = null;
079: try {
080: ClassLoader tools = lm.getToolsLoader();
081: Class manager = tools.loadClass(RAR_MANAGER_CLASSNAME);
082: Method m = manager.getDeclaredMethod("getInstance",
083: new Class[] { java.lang.String.class,
084: java.lang.ClassLoader.class });
085: rarDD = (RarDeploymentDesc) m.invoke(null, new Object[] {
086: rar, cl });
087: } catch (InvocationTargetException ite) {
088: Throwable t = ite.getTargetException();
089: if (RarDeploymentDescException.class.isInstance(t)) {
090: throw (RarDeploymentDescException) ite
091: .getTargetException();
092: } else {
093: throw new RarDeploymentDescException(
094: "RarDeploymentDescManager.getInstance fails", t);
095: }
096: } catch (Exception e) {
097: // TODO add i18n here
098: throw new RarDeploymentDescException(
099: "Problems when using reflection on RarDeploymentDescManager",
100: e);
101: }
102: return rarDD;
103: }
104:
105: /**
106: * Wrap the RarDeploymentDescManager.setParsingWithValidation(boolean)
107: *
108: * @param b boolean
109: */
110: public static void setParsingWithValidation(boolean b) {
111: LoaderManager lm = LoaderManager.getInstance();
112:
113: try {
114: ClassLoader tools = lm.getToolsLoader();
115: Class manager = tools.loadClass(RAR_MANAGER_CLASSNAME);
116: Method m = manager.getDeclaredMethod(
117: "setParsingWithValidation",
118: new Class[] { boolean.class });
119: m.invoke(null, new Object[] { new Boolean(b) });
120: } catch (Exception e) {
121: // Should never occurs
122: logger.log(BasicLevel.ERROR, e);
123: }
124: }
125:
126: /**
127: * Wrap the RarDeploymentDescManager.getInstance(Context).
128: *
129: * @param ctx Context
130: *
131: * @return RarDeploymentDesc
132: *
133: * @throws DeploymentDescException When init fails
134: */
135: public static RarDeploymentDesc getInstance(Context ctx)
136: throws DeploymentDescException {
137: LoaderManager lm = LoaderManager.getInstance();
138: RarDeploymentDesc rarDD = null;
139:
140: try {
141: ClassLoader tools = lm.getToolsLoader();
142: Class manager = tools.loadClass(RAR_MANAGER_CLASSNAME);
143: Method m = manager.getDeclaredMethod("getInstance",
144: new Class[] { javax.naming.Context.class });
145: rarDD = (RarDeploymentDesc) m.invoke(null,
146: new Object[] { ctx });
147: } catch (InvocationTargetException ite) {
148: Throwable t = ite.getTargetException();
149: if (RarDeploymentDescException.class.isInstance(t)) {
150: throw (RarDeploymentDescException) ite
151: .getTargetException();
152: } else {
153: throw new RarDeploymentDescException(
154: "RarDeploymentDescManager.getInstance fails", t);
155: }
156: } catch (Exception e) {
157: // TODO add i18n here
158: throw new RarDeploymentDescException(
159: "Problems when using reflection on RarDeploymentDescManager",
160: e);
161: }
162:
163: return rarDD;
164: }
165:
166: }
|