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: MappingFileManagerWrapper.java 4799 2004-05-25 14:26:36Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ws.deployment.lib.wrapper;
025:
026: import java.io.File;
027: import java.io.InputStream;
028: import java.lang.reflect.InvocationTargetException;
029: import java.lang.reflect.Method;
030:
031: import org.objectweb.jonas_ws.deployment.api.MappingFile;
032: import org.objectweb.jonas_ws.deployment.api.WSDeploymentDescException;
033:
034: import org.objectweb.jonas.server.LoaderManager;
035:
036: /**
037: * Wrap the MappingFileManager to solve ClassLoader problems linked to
038: * Digester.
039: *
040: * @author Guillaume Sauthier
041: */
042: public class MappingFileManagerWrapper {
043:
044: /**
045: * MappingFileManager fully qualified classname
046: */
047: private static final String MAPPINGFILEMANAGER_CLASSNAME = "org.objectweb.jonas_ws.deployment.lib.MappingFileManager";
048:
049: /**
050: * Private Empty Constructor for utility class
051: */
052: private MappingFileManagerWrapper() {
053: }
054:
055: /**
056: * Wrap MappingFileManager.getInstance(module, filename) call.
057: *
058: * @param module directory where mapping file can be found
059: * @param filename mapping file filename
060: *
061: * @return the MappingFile
062: *
063: * @throws WSDeploymentDescException When MappingFile cannot be instanciated
064: */
065: public static MappingFile getMappingFile(File module,
066: String filename) throws WSDeploymentDescException {
067: LoaderManager lm = LoaderManager.getInstance();
068: MappingFile mf = null;
069:
070: try {
071: ClassLoader tools = lm.getToolsLoader();
072: Class manager = tools
073: .loadClass(MAPPINGFILEMANAGER_CLASSNAME);
074: Method m = manager.getDeclaredMethod("getInstance",
075: new Class[] { File.class, String.class });
076: mf = (MappingFile) m.invoke(null, new Object[] { module,
077: filename });
078: } catch (InvocationTargetException ite) {
079: Throwable t = ite.getTargetException();
080: if (WSDeploymentDescException.class.isInstance(t)) {
081: throw (WSDeploymentDescException) ite
082: .getTargetException();
083: } else {
084: throw new WSDeploymentDescException(
085: "MappingFileManager.getInstance fails", t);
086: }
087: } catch (Exception e) {
088: // TODO add i18n here
089: throw new WSDeploymentDescException(
090: "Problems when using reflection on MappingFileManager",
091: e);
092: }
093:
094: return mf;
095: }
096:
097: /**
098: * Wrap MappingFileManager.getInstance(module, filename) call.
099: *
100: * @param is InputStream of the MappingFile
101: * @param filename mapping file filename
102: *
103: * @return the MappingFile
104: *
105: * @throws WSDeploymentDescException When MappingFile cannot be instanciated
106: */
107: public static MappingFile getMappingFile(InputStream is,
108: String filename) throws WSDeploymentDescException {
109: LoaderManager lm = LoaderManager.getInstance();
110: MappingFile mf = null;
111:
112: try {
113: ClassLoader tools = lm.getToolsLoader();
114: Class manager = tools
115: .loadClass(MAPPINGFILEMANAGER_CLASSNAME);
116: Method m = manager.getDeclaredMethod("getInstance",
117: new Class[] { InputStream.class, String.class });
118: mf = (MappingFile) m.invoke(null, new Object[] { is,
119: filename });
120: } catch (InvocationTargetException ite) {
121: Throwable t = ite.getTargetException();
122: if (WSDeploymentDescException.class.isInstance(t)) {
123: throw (WSDeploymentDescException) ite
124: .getTargetException();
125: } else {
126: throw new WSDeploymentDescException(
127: "MappingFileManager.getInstance fails", t);
128: }
129: } catch (Exception e) {
130: // TODO add i18n here
131: throw new WSDeploymentDescException(
132: "Problems when using reflection on MappingFileManager",
133: e);
134: }
135:
136: return mf;
137: }
138: }
|