1 25 26 package org.objectweb.jonas_ejb.genic.wrapper; 27 28 import java.lang.reflect.InvocationTargetException ; 29 import java.lang.reflect.Method ; 30 31 import org.objectweb.jonas.server.LoaderManager; 32 import org.objectweb.jonas.service.ServiceException; 33 34 39 public class GenicServiceWrapper { 40 41 42 45 private static final String GENIC_CLASSNAME = "org.objectweb.jonas_ejb.genic.GenIC"; 46 47 50 private GenicServiceWrapper() { }; 51 52 57 public static void callGenic(String [] args) throws ServiceException { 58 LoaderManager lm = LoaderManager.getInstance(); 59 ClassLoader old = null; 60 61 try { 62 ClassLoader tools = lm.getToolsLoader(); 63 old = Thread.currentThread().getContextClassLoader(); 64 Thread.currentThread().setContextClassLoader(tools); 65 66 Class manager = tools.loadClass(GENIC_CLASSNAME); 67 Method m = manager.getDeclaredMethod("main", new Class [] {String [].class}); 68 m.invoke(null, new Object [] {args}); 69 } catch (InvocationTargetException e) { 70 if (e.getTargetException() instanceof Error ) { 71 throw (Error ) 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 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 |