1 25 26 package org.objectweb.jonas_lib.genclientstub.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 ClientGenStubWrapper { 38 39 42 private static final String GENSTUB_CLASSNAME = "org.objectweb.jonas_lib.genclientstub.ClientStubGen"; 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 clientGenStub = null; 63 64 67 public ClientGenStubWrapper() { 68 }; 69 70 76 public String callClientGenStubExecute(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(GENSTUB_CLASSNAME); 87 executeMethod = clazz.getDeclaredMethod("execute", new Class [] {String [].class}); 88 } 89 90 if (clientGenStub == null) { 91 Class clazz = tools.loadClass(GENSTUB_CLASSNAME); 92 clientGenStub = 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(clientGenStub, 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 ClientstubGen.execute(String[])", e.getTargetException()); 106 } 107 } catch (Exception e) { 108 throw new Exception ("Problems when invoking method ClientstubGen.execute(String[])", e); 109 } finally { 110 if (old != null) { 111 Thread.currentThread().setContextClassLoader(old); 112 } 113 } 114 } 115 116 121 public boolean callClientGenStubIsInputModifed() 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(GENSTUB_CLASSNAME); 132 isInputModifiedMethod = clazz.getDeclaredMethod("isInputModified", new Class [] {}); 133 } 134 135 if (clientGenStub == null) { 136 Class clazz = tools.loadClass(GENSTUB_CLASSNAME); 137 clientGenStub = clazz.newInstance(); 138 } 139 140 return ((Boolean ) isInputModifiedMethod.invoke(clientGenStub, (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 clientGenStub.isInputModified()", e.getTargetException()); 146 } 147 } catch (Exception e) { 148 throw new Exception ("Problems when invoking method clientGenStub.isInputModified()", e); 149 } finally { 150 if (old != null) { 151 Thread.currentThread().setContextClassLoader(old); 152 } 153 } 154 } 155 } 156 157 | Popular Tags |