01: /**
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 2004 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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: GenicServiceWrapper.java 5447 2004-09-17 08:40:04Z joaninh $
23: * --------------------------------------------------------------------------
24: */package org.objectweb.jonas_ejb.genic.wrapper;
25:
26: import java.lang.reflect.InvocationTargetException;
27: import java.lang.reflect.Method;
28:
29: import org.objectweb.jonas.server.LoaderManager;
30: import org.objectweb.jonas.service.ServiceException;
31:
32: /**
33: * GenIC wrapper
34: *
35: * @author Camilleri Jerome : Initial developer
36: */
37: public class GenicServiceWrapper {
38:
39: /**
40: * GenIC fully qualified classname
41: */
42: private static final String GENIC_CLASSNAME = "org.objectweb.jonas_ejb.genic.GenIC";
43:
44: /**
45: * Private empty constructor for utility class
46: */
47: private GenicServiceWrapper() {
48: };
49:
50: /**
51: * Wrapper around GenIC.main(String[]) method
52: * @param args GenIC args
53: * @throws ServiceException If GenIC fails or if Reflection errors occurs
54: */
55: public static void callGenic(String[] args) throws ServiceException {
56: LoaderManager lm = LoaderManager.getInstance();
57: ClassLoader old = null;
58:
59: try {
60: ClassLoader tools = lm.getToolsLoader();
61: old = Thread.currentThread().getContextClassLoader();
62: Thread.currentThread().setContextClassLoader(tools);
63:
64: Class manager = tools.loadClass(GENIC_CLASSNAME);
65: Method m = manager.getDeclaredMethod("main",
66: new Class[] { String[].class });
67: m.invoke(null, new Object[] { args });
68: } catch (InvocationTargetException e) {
69: if (e.getTargetException() instanceof Error) {
70: throw (Error) e.getTargetException();
71: } else if (e.getTargetException() instanceof ServiceException) {
72: throw (ServiceException) e.getTargetException();
73: } else {
74: throw new ServiceException(
75: "Problems when invoking main method from GenIC",
76: e.getTargetException());
77: }
78: } catch (Exception e) {
79: throw new ServiceException(
80: "Problems when invoking main method from GenIC", e);
81: } finally {
82: if (old != null) {
83: Thread.currentThread().setContextClassLoader(old);
84: }
85: }
86: }
87: }
|