00001 00026 package org.objectweb.jonas_ws.wsgen.wrapper; 00027 00028 import java.lang.reflect.InvocationTargetException; 00029 import java.lang.reflect.Method; 00030 00031 import org.objectweb.jonas.server.LoaderManager; 00032 00037 public class WsGenWrapper { 00038 00042 private static final String WSGEN_CLASSNAME = "org.objectweb.jonas_ws.wsgen.WsGen"; 00043 00047 private static final int ARGS_NUMBER = 3; 00048 00052 private static Method executeMethod = null; 00053 00057 private static Method isInputModifiedMethod = null; 00058 00062 private Object wsgen = null; 00063 00067 public WsGenWrapper() { 00068 }; 00069 00076 public String callWsGenExecute(String fileName) throws Exception { 00077 LoaderManager lm = LoaderManager.getInstance(); 00078 ClassLoader old = null; 00079 00080 try { 00081 ClassLoader tools = lm.getToolsLoader(); 00082 old = Thread.currentThread().getContextClassLoader(); 00083 Thread.currentThread().setContextClassLoader(tools); 00084 00085 if (executeMethod == null) { 00086 Class clazz = tools.loadClass(WSGEN_CLASSNAME); 00087 executeMethod = clazz.getDeclaredMethod("execute", new Class[] {String[].class}); 00088 } 00089 00090 if (wsgen == null) { 00091 Class clazz = tools.loadClass(WSGEN_CLASSNAME); 00092 wsgen = clazz.newInstance(); 00093 } 00094 00095 String[] args = new String[ARGS_NUMBER]; 00096 args[0] = "-d"; 00097 args[1] = System.getProperty("java.io.tmpdir"); 00098 args[2] = fileName; 00099 00100 return (String) executeMethod.invoke(wsgen, new Object[] {args}); 00101 } catch (InvocationTargetException e) { 00102 if (e.getTargetException() instanceof Error) { 00103 throw (Error) e.getTargetException(); 00104 } else { 00105 throw new Exception("Exception when executing WsGen.execute(String[])", e.getTargetException()); 00106 } 00107 } catch (Exception e) { 00108 throw new Exception("Problems when invoking method WsGen.execute(String[])", e); 00109 } finally { 00110 if (old != null) { 00111 Thread.currentThread().setContextClassLoader(old); 00112 } 00113 } 00114 } 00115 00121 public boolean callWsGenIsInputModifed() throws Exception { 00122 LoaderManager lm = LoaderManager.getInstance(); 00123 ClassLoader old = null; 00124 00125 try { 00126 ClassLoader tools = lm.getToolsLoader(); 00127 old = Thread.currentThread().getContextClassLoader(); 00128 Thread.currentThread().setContextClassLoader(tools); 00129 00130 if (isInputModifiedMethod == null) { 00131 Class clazz = tools.loadClass(WSGEN_CLASSNAME); 00132 isInputModifiedMethod = clazz.getDeclaredMethod("isInputModified", new Class[] {}); 00133 } 00134 00135 if (wsgen == null) { 00136 Class clazz = tools.loadClass(WSGEN_CLASSNAME); 00137 wsgen = clazz.newInstance(); 00138 } 00139 00140 return ((Boolean) isInputModifiedMethod.invoke(wsgen, (Object[]) null)).booleanValue(); 00141 } catch (InvocationTargetException e) { 00142 if (e.getTargetException() instanceof Error) { 00143 throw (Error) e.getTargetException(); 00144 } else { 00145 throw new Exception("Exception when executing WsGen.isInputModified()", e.getTargetException()); 00146 } 00147 } catch (Exception e) { 00148 throw new Exception("Problems when invoking method WsGen.isInputModified()", e); 00149 } finally { 00150 if (old != null) { 00151 Thread.currentThread().setContextClassLoader(old); 00152 } 00153 } 00154 } 00155 } 00156