1 25 package org.objectweb.jonas_web.deployment.lib.wrapper; 26 27 import java.lang.reflect.InvocationTargetException ; 28 import java.lang.reflect.Method ; 29 import java.net.URL ; 30 import java.net.URLClassLoader ; 31 32 import org.objectweb.jonas_web.deployment.api.WebContainerDeploymentDesc; 33 import org.objectweb.jonas_web.deployment.api.WebContainerDeploymentDescException; 34 35 import org.objectweb.jonas.common.Log; 36 import org.objectweb.jonas.server.LoaderManager; 37 38 import org.objectweb.util.monolog.api.BasicLevel; 39 import org.objectweb.util.monolog.api.Logger; 40 41 47 public class WebManagerWrapper { 48 49 52 private static Logger logger = Log.getLogger(Log.JONAS_EAR_PREFIX); 53 54 57 private static final String WEBMANAGER_CLASSNAME = "org.objectweb.jonas_web.deployment.lib.WebDeploymentDescManager"; 58 59 62 private WebManagerWrapper() { } 63 64 75 public static WebContainerDeploymentDesc getDeploymentDesc(URL url, ClassLoader moduleCL, ClassLoader earCL) 76 throws WebContainerDeploymentDescException { 77 LoaderManager lm = LoaderManager.getInstance(); 78 WebContainerDeploymentDesc webDD = null; 79 80 try { 81 ClassLoader tools = lm.getToolsLoader(); 82 Class manager = tools.loadClass(WEBMANAGER_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 webDD = (WebContainerDeploymentDesc) m.invoke(instance, new Object [] {url, moduleCL, earCL}); 88 } catch (InvocationTargetException ite) { 89 Throwable t = ite.getTargetException(); 90 if (WebContainerDeploymentDescException.class.isInstance(t)) { 91 throw (WebContainerDeploymentDescException) ite.getTargetException(); 92 } else { 93 throw new WebContainerDeploymentDescException("WebDeploymentDescManager.getDeploymentDesc fails", t); 94 } 95 } catch (Exception e) { 96 throw new WebContainerDeploymentDescException("Problems when using reflection on WebDeploymentDescManager", e); 98 } 99 100 return webDD; 101 } 102 103 110 public static void setAltDD(URLClassLoader earClassLoader, URL [] warUrls, URL [] warsAltDDs) { 111 LoaderManager lm = LoaderManager.getInstance(); 112 113 try { 114 ClassLoader tools = lm.getToolsLoader(); 115 Class manager = tools.loadClass(WEBMANAGER_CLASSNAME); 116 Method m = manager.getDeclaredMethod("getInstance", new Class [] {}); 117 Object instance = m.invoke(null, new Object [] {}); 118 m = manager.getDeclaredMethod("setAltDD", new Class [] {ClassLoader .class, URL [].class, URL [].class}); 119 m.invoke(instance, new Object [] {earClassLoader, warUrls, warsAltDDs}); 120 } catch (Exception e) { 121 logger.log(BasicLevel.ERROR, e); 123 } 124 } 125 126 131 public static void setParsingWithValidation(boolean b) { 132 LoaderManager lm = LoaderManager.getInstance(); 133 134 try { 135 ClassLoader tools = lm.getToolsLoader(); 136 Class manager = tools.loadClass(WEBMANAGER_CLASSNAME); 137 Method m = manager.getDeclaredMethod("setParsingWithValidation", new Class [] {boolean.class}); 138 m.invoke(null, new Object [] {new Boolean (b)}); 139 } catch (Exception e) { 140 logger.log(BasicLevel.ERROR, e); 142 } 143 } 144 145 150 public static void removeCache(ClassLoader classLoader) { 151 LoaderManager lm = LoaderManager.getInstance(); 152 153 try { 154 ClassLoader tools = lm.getToolsLoader(); 155 Class manager = tools.loadClass(WEBMANAGER_CLASSNAME); 156 Method m = manager.getDeclaredMethod("getInstance", new Class [] {}); 157 Object instance = m.invoke(null, new Object [] {}); 158 m = manager.getDeclaredMethod("removeCache", new Class [] {ClassLoader .class}); 159 m.invoke(instance, new Object [] {classLoader}); 160 } catch (Exception e) { 161 logger.log(BasicLevel.ERROR, e); 163 } 164 } 165 166 176 public static WebContainerDeploymentDesc getDeploymentDesc(String warName, ClassLoader cl) 177 throws WebContainerDeploymentDescException { 178 LoaderManager lm = LoaderManager.getInstance(); 179 WebContainerDeploymentDesc desc = null; 180 181 try { 182 ClassLoader tools = lm.getToolsLoader(); 183 Class manager = tools.loadClass(WEBMANAGER_CLASSNAME); 184 Method m = manager.getDeclaredMethod("getDeploymentDesc", new Class [] {String .class, ClassLoader .class}); 185 desc = (WebContainerDeploymentDesc) m.invoke(null, new Object [] {warName, cl}); 186 } catch (InvocationTargetException ite) { 187 Throwable t = ite.getTargetException(); 188 if (WebContainerDeploymentDescException.class.isInstance(t)) { 189 throw (WebContainerDeploymentDescException) ite.getTargetException(); 190 } else { 191 throw new WebContainerDeploymentDescException("WebDeploymentDescManager.getDeploymentDesc fails", t); 192 } 193 } catch (Exception e) { 194 throw new WebContainerDeploymentDescException("Problems when using reflection on WebDeploymentDescManager", e); 196 } 197 198 return desc; 199 } 200 201 } | Popular Tags |