KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > genic > wrapper > GenicServiceWrapper


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2004 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: GenicServiceWrapper.java,v 1.4 2004/09/17 08:40:04 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ejb.genic.wrapper;
27
28 import java.lang.reflect.InvocationTargetException JavaDoc;
29 import java.lang.reflect.Method JavaDoc;
30
31 import org.objectweb.jonas.server.LoaderManager;
32 import org.objectweb.jonas.service.ServiceException;
33
34 /**
35  * GenIC wrapper
36  *
37  * @author Camilleri Jerome : Initial developer
38  */

39 public class GenicServiceWrapper {
40
41
42     /**
43      * GenIC fully qualified classname
44      */

45     private static final String JavaDoc GENIC_CLASSNAME = "org.objectweb.jonas_ejb.genic.GenIC";
46
47     /**
48      * Private empty constructor for utility class
49      */

50     private GenicServiceWrapper() { };
51
52     /**
53      * Wrapper around GenIC.main(String[]) method
54      * @param args GenIC args
55      * @throws ServiceException If GenIC fails or if Reflection errors occurs
56      */

57     public static void callGenic(String JavaDoc[] args) throws ServiceException {
58         LoaderManager lm = LoaderManager.getInstance();
59         ClassLoader JavaDoc old = null;
60
61         try {
62             ClassLoader JavaDoc tools = lm.getToolsLoader();
63             old = Thread.currentThread().getContextClassLoader();
64             Thread.currentThread().setContextClassLoader(tools);
65
66             Class JavaDoc manager = tools.loadClass(GENIC_CLASSNAME);
67             Method JavaDoc m = manager.getDeclaredMethod("main", new Class JavaDoc[] {String JavaDoc[].class});
68             m.invoke(null, new Object JavaDoc[] {args});
69         } catch (InvocationTargetException JavaDoc e) {
70             if (e.getTargetException() instanceof Error JavaDoc) {
71                 throw (Error JavaDoc) e.getTargetException();
72             } else if (e.getTargetException() instanceof ServiceException) {
73                 throw (ServiceException) e.getTargetException();
74             } else {
75                 throw new ServiceException("Problems when invoking main method from GenIC", e.getTargetException());
76             }
77         } catch (Exception JavaDoc e) {
78             throw new ServiceException("Problems when invoking main method from GenIC" , e);
79         } finally {
80             if (old != null) {
81                 Thread.currentThread().setContextClassLoader(old);
82             }
83         }
84     }
85 }
86
87
Popular Tags