1 25 package org.objectweb.jonas_ejb.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_ejb.deployment.api.DeploymentDesc; 33 34 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException; 35 36 import org.objectweb.jonas.common.Log; 37 import org.objectweb.jonas.server.LoaderManager; 38 39 import org.objectweb.util.monolog.api.BasicLevel; 40 import org.objectweb.util.monolog.api.Logger; 41 42 43 48 public class EjbManagerWrapper { 49 50 53 private static final String EJB_MANAGER_CLASSNAME = "org.objectweb.jonas_ejb.deployment.lib.EjbDeploymentDescManager"; 54 55 58 private static Logger logger = Log.getLogger(Log.JONAS_EAR_PREFIX); 59 60 63 private EjbManagerWrapper() { } 64 65 76 public static DeploymentDesc getDeploymentDesc(URL url, ClassLoader moduleCL, ClassLoader earCL) 77 throws DeploymentDescException { 78 LoaderManager lm = LoaderManager.getInstance(); 79 DeploymentDesc dd = null; 80 81 try { 82 ClassLoader tools = lm.getToolsLoader(); 83 Class manager = tools.loadClass(EJB_MANAGER_CLASSNAME); 84 Method m = manager.getDeclaredMethod("getInstance", new Class [] {}); 85 Object instance = m.invoke(null, new Object [] {}); 86 m = manager.getDeclaredMethod("getDeploymentDesc", new Class [] {URL .class, ClassLoader .class, ClassLoader .class}); 87 dd = (DeploymentDesc) m.invoke(instance, new Object [] {url, moduleCL, earCL}); 88 } catch (InvocationTargetException ite) { 89 Throwable t = ite.getTargetException(); 90 if (DeploymentDescException.class.isInstance(t)) { 91 throw (DeploymentDescException) ite.getTargetException(); 92 } else { 93 throw new DeploymentDescException("EjbDeploymentDescManager.getDeploymentDesc fails", t); 94 } 95 } catch (Exception e) { 96 throw new DeploymentDescException("Problems when using reflection on EjbDeploymentDescManager", e); 98 } 99 100 return dd; 101 } 102 103 110 public static void setAvailableEjbJarsAndAltDDs(URLClassLoader earClassLoader, URL [] jarUrls, URL [] ejbsAltDDs) { 111 LoaderManager lm = LoaderManager.getInstance(); 112 try { 113 ClassLoader tools = lm.getToolsLoader(); 114 Class manager = tools.loadClass(EJB_MANAGER_CLASSNAME); 115 Method m = manager.getDeclaredMethod("getInstance", new Class [] {}); 116 Object instance = m.invoke(null, new Object [] {}); 117 m = manager.getDeclaredMethod("setAvailableEjbJarsAndAltDDs", new Class [] {ClassLoader .class, URL [].class, URL [].class}); 118 m.invoke(instance, new Object [] {earClassLoader, jarUrls, ejbsAltDDs}); 119 } catch (Exception e) { 120 logger.log(BasicLevel.ERROR, e); 122 } 123 } 124 125 130 public static void setParsingWithValidation(boolean b) { 131 LoaderManager lm = LoaderManager.getInstance(); 132 try { 133 ClassLoader tools = lm.getToolsLoader(); 134 Class manager = tools.loadClass(EJB_MANAGER_CLASSNAME); 135 Method m = manager.getDeclaredMethod("setParsingWithValidation", new Class [] {boolean.class}); 136 m.invoke(null, new Object [] {new Boolean (b)}); 137 } catch (Exception e) { 138 logger.log(BasicLevel.ERROR, e); 140 } 141 } 142 143 148 public static void removeCache(ClassLoader classLoader) { 149 LoaderManager lm = LoaderManager.getInstance(); 150 try { 151 ClassLoader tools = lm.getToolsLoader(); 152 Class manager = tools.loadClass(EJB_MANAGER_CLASSNAME); 153 Method m = manager.getDeclaredMethod("getInstance", new Class [] {}); 154 Object instance = m.invoke(null, new Object [] {}); 155 m = manager.getDeclaredMethod("removeCache", new Class [] {ClassLoader .class}); 156 m.invoke(instance, new Object [] {classLoader}); 157 } catch (Exception e) { 158 logger.log(BasicLevel.ERROR, e); 160 } 161 } 162 163 } 164 | Popular Tags |