GenicServiceWrapper.java

00001 
00026 package org.objectweb.jonas_ejb.genic.wrapper;
00027 
00028 import java.lang.reflect.InvocationTargetException;
00029 import java.lang.reflect.Method;
00030 
00031 import org.objectweb.jonas.server.LoaderManager;
00032 import org.objectweb.jonas.service.ServiceException;
00033 
00039 public class GenicServiceWrapper {
00040 
00041 
00045     private static final String GENIC_CLASSNAME = "org.objectweb.jonas_ejb.genic.GenIC";
00046 
00050     private GenicServiceWrapper() { };
00051 
00057     public static void callGenic(String[] args) throws ServiceException {
00058         LoaderManager lm = LoaderManager.getInstance();
00059         ClassLoader old = null;
00060 
00061         try {
00062             ClassLoader tools = lm.getToolsLoader();
00063             old = Thread.currentThread().getContextClassLoader();
00064             Thread.currentThread().setContextClassLoader(tools);
00065 
00066             Class manager = tools.loadClass(GENIC_CLASSNAME);
00067             Method m = manager.getDeclaredMethod("main", new Class[] {String[].class});
00068             m.invoke(null, new Object[] {args});
00069         } catch (InvocationTargetException e) {
00070             if (e.getTargetException() instanceof Error) {
00071                 throw (Error) e.getTargetException();
00072             } else if (e.getTargetException() instanceof ServiceException) {
00073                 throw (ServiceException) e.getTargetException();
00074             } else {
00075                 throw new ServiceException("Problems when invoking main method from GenIC", e.getTargetException());
00076             }
00077         } catch (Exception e) {
00078             throw new ServiceException("Problems when invoking main method from GenIC" , e);
00079         } finally {
00080             if (old != null) {
00081                 Thread.currentThread().setContextClassLoader(old);
00082             }
00083         }
00084     }
00085 }
00086 

Generated on Tue Feb 15 15:05:48 2005 for JOnAS by  doxygen 1.3.9.1