KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ws > deployment > lib > wrapper > MappingFileManagerWrapper


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

25 package org.objectweb.jonas_ws.deployment.lib.wrapper;
26
27 import java.io.File JavaDoc;
28 import java.io.InputStream JavaDoc;
29 import java.lang.reflect.InvocationTargetException JavaDoc;
30 import java.lang.reflect.Method JavaDoc;
31
32 import org.objectweb.jonas_ws.deployment.api.MappingFile;
33 import org.objectweb.jonas_ws.deployment.api.WSDeploymentDescException;
34
35 import org.objectweb.jonas.server.LoaderManager;
36
37
38 /**
39  * Wrap the MappingFileManager to solve ClassLoader problems linked to
40  * Digester.
41  *
42  * @author Guillaume Sauthier
43  */

44 public class MappingFileManagerWrapper {
45
46     /**
47      * MappingFileManager fully qualified classname
48      */

49     private static final String JavaDoc MAPPINGFILEMANAGER_CLASSNAME = "org.objectweb.jonas_ws.deployment.lib.MappingFileManager";
50
51     /**
52      * Private Empty Constructor for utility class
53      */

54     private MappingFileManagerWrapper() { }
55
56     /**
57      * Wrap MappingFileManager.getInstance(module, filename) call.
58      *
59      * @param module directory where mapping file can be found
60      * @param filename mapping file filename
61      *
62      * @return the MappingFile
63      *
64      * @throws WSDeploymentDescException When MappingFile cannot be instanciated
65      */

66     public static MappingFile getMappingFile(File JavaDoc module, String JavaDoc filename)
67     throws WSDeploymentDescException {
68         LoaderManager lm = LoaderManager.getInstance();
69         MappingFile mf = null;
70
71         try {
72             ClassLoader JavaDoc tools = lm.getToolsLoader();
73             Class JavaDoc manager = tools.loadClass(MAPPINGFILEMANAGER_CLASSNAME);
74             Method JavaDoc m = manager.getDeclaredMethod("getInstance", new Class JavaDoc[] {File JavaDoc.class, String JavaDoc.class});
75             mf = (MappingFile) m.invoke(null, new Object JavaDoc[] {module, filename});
76         } catch (InvocationTargetException JavaDoc ite) {
77             Throwable JavaDoc t = ite.getTargetException();
78             if (WSDeploymentDescException.class.isInstance(t)) {
79                 throw (WSDeploymentDescException) ite.getTargetException();
80             } else {
81                 throw new WSDeploymentDescException("MappingFileManager.getInstance fails", t);
82             }
83         } catch (Exception JavaDoc e) {
84             // TODO add i18n here
85
throw new WSDeploymentDescException("Problems when using reflection on MappingFileManager", e);
86         }
87
88         return mf;
89     }
90
91     /**
92      * Wrap MappingFileManager.getInstance(module, filename) call.
93      *
94      * @param is InputStream of the MappingFile
95      * @param filename mapping file filename
96      *
97      * @return the MappingFile
98      *
99      * @throws WSDeploymentDescException When MappingFile cannot be instanciated
100      */

101     public static MappingFile getMappingFile(InputStream JavaDoc is, String JavaDoc filename)
102     throws WSDeploymentDescException {
103         LoaderManager lm = LoaderManager.getInstance();
104         MappingFile mf = null;
105
106         try {
107             ClassLoader JavaDoc tools = lm.getToolsLoader();
108             Class JavaDoc manager = tools.loadClass(MAPPINGFILEMANAGER_CLASSNAME);
109             Method JavaDoc m = manager.getDeclaredMethod("getInstance", new Class JavaDoc[] {InputStream JavaDoc.class, String JavaDoc.class});
110             mf = (MappingFile) m.invoke(null, new Object JavaDoc[] {is, filename});
111         } catch (InvocationTargetException JavaDoc ite) {
112             Throwable JavaDoc t = ite.getTargetException();
113             if (WSDeploymentDescException.class.isInstance(t)) {
114                 throw (WSDeploymentDescException) ite.getTargetException();
115             } else {
116                 throw new WSDeploymentDescException("MappingFileManager.getInstance fails", t);
117             }
118         } catch (Exception JavaDoc e) {
119             // TODO add i18n here
120
throw new WSDeploymentDescException("Problems when using reflection on MappingFileManager", e);
121         }
122
123         return mf;
124     }
125 }
126
Popular Tags