1 25 package org.objectweb.jonas_ws.deployment.lib.wrapper; 26 27 import java.lang.reflect.InvocationTargetException ; 28 import java.lang.reflect.Method ; 29 import java.net.URL ; 30 31 import org.objectweb.jonas_ws.deployment.api.WSDeploymentDesc; 32 import org.objectweb.jonas_ws.deployment.api.WSDeploymentDescException; 33 34 import org.objectweb.jonas.common.Log; 35 import org.objectweb.jonas.server.LoaderManager; 36 37 import org.objectweb.util.monolog.api.BasicLevel; 38 import org.objectweb.util.monolog.api.Logger; 39 40 41 47 public class WSManagerWrapper { 48 49 52 private static final String WS_MANAGER_CLASSNAME = "org.objectweb.jonas_ws.deployment.lib.WSDeploymentDescManager"; 53 54 57 private static Logger logger = Log.getLogger(Log.JONAS_EAR_PREFIX); 58 59 62 private WSManagerWrapper() { } 63 64 75 public static WSDeploymentDesc getDeploymentDesc(URL url, ClassLoader moduleCL, ClassLoader earCL) 76 throws WSDeploymentDescException { 77 LoaderManager lm = LoaderManager.getInstance(); 78 WSDeploymentDesc wsDD = null; 79 80 try { 81 ClassLoader tools = lm.getToolsLoader(); 82 Class manager = tools.loadClass(WS_MANAGER_CLASSNAME); 83 Method m = manager.getDeclaredMethod("getInstance", new Class [] {}); 84 Object instance = m.invoke(null, new Object [] {}); 85 m = manager.getDeclaredMethod("getDeploymentDesc", new Class [] {URL .class, ClassLoader .class, 86 ClassLoader .class}); 87 wsDD = (WSDeploymentDesc) m.invoke(instance, new Object [] {url, moduleCL, earCL}); 88 } catch (InvocationTargetException ite) { 89 Throwable t = ite.getTargetException(); 90 if (WSDeploymentDescException.class.isInstance(t)) { 91 throw (WSDeploymentDescException) ite.getTargetException(); 92 } else { 93 throw new WSDeploymentDescException("WSDeploymentDescManager.getDeploymentDesc fails", t); 94 } 95 } catch (Exception e) { 96 throw new WSDeploymentDescException("Problems when using reflection on WSDeploymentDescManager", e); 98 } 99 100 return wsDD; 101 } 102 103 115 public static WSDeploymentDesc getDeploymentDesc(URL url, URL unpackedURL, ClassLoader moduleCL, ClassLoader earCL) 116 throws WSDeploymentDescException { 117 LoaderManager lm = LoaderManager.getInstance(); 118 WSDeploymentDesc wsDD = null; 119 120 try { 121 ClassLoader tools = lm.getToolsLoader(); 122 Class manager = tools.loadClass(WS_MANAGER_CLASSNAME); 123 Method m = manager.getDeclaredMethod("getInstance", new Class [] {}); 124 Object instance = m.invoke(null, new Object [] {}); 125 m = manager.getDeclaredMethod("getDeploymentDesc", new Class [] {URL .class, URL .class, ClassLoader .class, 126 ClassLoader .class}); 127 wsDD = (WSDeploymentDesc) m.invoke(instance, new Object [] {url, unpackedURL, moduleCL, earCL}); 128 } catch (InvocationTargetException ite) { 129 Throwable t = ite.getTargetException(); 130 if (WSDeploymentDescException.class.isInstance(t)) { 131 throw (WSDeploymentDescException) ite.getTargetException(); 132 } else { 133 throw new WSDeploymentDescException("WSDeploymentDescManager.getDeploymentDesc fails", t); 134 } 135 } catch (Exception e) { 136 throw new WSDeploymentDescException("Problems when using reflection on WSDeploymentDescManager", e); 138 } 139 140 return wsDD; 141 } 142 143 148 public static void setParsingWithValidation(boolean b) { 149 LoaderManager lm = LoaderManager.getInstance(); 150 151 try { 152 ClassLoader tools = lm.getToolsLoader(); 153 Class manager = tools.loadClass(WS_MANAGER_CLASSNAME); 154 Method m = manager.getDeclaredMethod("setParsingWithValidation", new Class [] {boolean.class}); 155 m.invoke(null, new Object [] {new Boolean (b)}); 156 } catch (Exception e) { 157 logger.log(BasicLevel.ERROR, e); 159 } 160 } 161 162 167 public static void removeCache(ClassLoader cl) { 168 LoaderManager lm = LoaderManager.getInstance(); 169 170 try { 171 ClassLoader tools = lm.getToolsLoader(); 172 Class manager = tools.loadClass(WS_MANAGER_CLASSNAME); 173 Method m = manager.getDeclaredMethod("getInstance", new Class [] {}); 174 Object instance = m.invoke(null, new Object [] {}); 175 m = manager.getDeclaredMethod("removeCache", new Class [] {ClassLoader .class}); 176 m.invoke(instance, new Object [] {cl}); 177 } catch (Exception e) { 178 logger.log(BasicLevel.ERROR, e); 180 } 181 } 182 183 } 184 | Popular Tags |