1 25 26 package org.objectweb.jonas_ws.wsgen.wrapper; 27 28 import java.lang.reflect.InvocationTargetException ; 29 import java.lang.reflect.Method ; 30 31 import org.objectweb.jonas.server.LoaderManager; 32 33 37 public class WsGenWrapper { 38 39 42 private static final String WSGEN_CLASSNAME = "org.objectweb.jonas_ws.wsgen.WsGen"; 43 44 47 private static final int ARGS_NUMBER = 3; 48 49 52 private static Method executeMethod = null; 53 54 57 private static Method isInputModifiedMethod = null; 58 59 62 private Object wsgen = null; 63 64 67 public WsGenWrapper() { 68 }; 69 70 76 public String callWsGenExecute(String fileName) throws Exception { 77 LoaderManager lm = LoaderManager.getInstance(); 78 ClassLoader old = null; 79 80 try { 81 ClassLoader tools = lm.getToolsLoader(); 82 old = Thread.currentThread().getContextClassLoader(); 83 Thread.currentThread().setContextClassLoader(tools); 84 85 if (executeMethod == null) { 86 Class clazz = tools.loadClass(WSGEN_CLASSNAME); 87 executeMethod = clazz.getDeclaredMethod("execute", new Class [] {String [].class}); 88 } 89 90 if (wsgen == null) { 91 Class clazz = tools.loadClass(WSGEN_CLASSNAME); 92 wsgen = clazz.newInstance(); 93 } 94 95 String [] args = new String [ARGS_NUMBER]; 96 args[0] = "-d"; 97 args[1] = System.getProperty("java.io.tmpdir"); 98 args[2] = fileName; 99 100 return (String ) executeMethod.invoke(wsgen, new Object [] {args}); 101 } catch (InvocationTargetException e) { 102 if (e.getTargetException() instanceof Error ) { 103 throw (Error ) e.getTargetException(); 104 } else { 105 throw new Exception ("Exception when executing WsGen.execute(String[])", e.getTargetException()); 106 } 107 } catch (Exception e) { 108 throw new Exception ("Problems when invoking method WsGen.execute(String[])", e); 109 } finally { 110 if (old != null) { 111 Thread.currentThread().setContextClassLoader(old); 112 } 113 } 114 } 115 116 121 public boolean callWsGenIsInputModifed() throws Exception { 122 LoaderManager lm = LoaderManager.getInstance(); 123 ClassLoader old = null; 124 125 try { 126 ClassLoader tools = lm.getToolsLoader(); 127 old = Thread.currentThread().getContextClassLoader(); 128 Thread.currentThread().setContextClassLoader(tools); 129 130 if (isInputModifiedMethod == null) { 131 Class clazz = tools.loadClass(WSGEN_CLASSNAME); 132 isInputModifiedMethod = clazz.getDeclaredMethod("isInputModified", new Class [] {}); 133 } 134 135 if (wsgen == null) { 136 Class clazz = tools.loadClass(WSGEN_CLASSNAME); 137 wsgen = clazz.newInstance(); 138 } 139 140 return ((Boolean ) isInputModifiedMethod.invoke(wsgen, (Object []) null)).booleanValue(); 141 } catch (InvocationTargetException e) { 142 if (e.getTargetException() instanceof Error ) { 143 throw (Error ) e.getTargetException(); 144 } else { 145 throw new Exception ("Exception when executing WsGen.isInputModified()", e.getTargetException()); 146 } 147 } catch (Exception e) { 148 throw new Exception ("Problems when invoking method WsGen.isInputModified()", e); 149 } finally { 150 if (old != null) { 151 Thread.currentThread().setContextClassLoader(old); 152 } 153 } 154 } 155 } 156 157 | Popular Tags |