1 27 package org.objectweb.jonas_client.deployment.lib.wrapper; 28 29 import java.lang.reflect.InvocationTargetException ; 30 import java.lang.reflect.Method ; 31 import java.net.URL ; 32 import java.net.URLClassLoader ; 33 34 import org.objectweb.jonas_client.deployment.api.ClientContainerDeploymentDesc; 35 import org.objectweb.jonas_client.deployment.api.ClientContainerDeploymentDescException; 36 37 import org.objectweb.jonas.common.Log; 38 import org.objectweb.jonas.server.LoaderManager; 39 40 import org.objectweb.util.monolog.api.BasicLevel; 41 import org.objectweb.util.monolog.api.Logger; 42 43 49 public class ClientManagerWrapper { 50 51 54 private static Logger logger = Log.getLogger(Log.JONAS_CLIENT_PREFIX); 55 56 59 private ClientManagerWrapper() { } 60 61 72 public static ClientContainerDeploymentDesc getDeploymentDesc(URL url, ClassLoader moduleCL, ClassLoader earCL) 73 throws ClientContainerDeploymentDescException { 74 LoaderManager lm = LoaderManager.getInstance(); 75 ClientContainerDeploymentDesc ccDD = null; 76 77 try { 78 ClassLoader tools = lm.getToolsLoader(); 79 Class manager = tools.loadClass("org.objectweb.jonas_client.deployment.lib.ClientDeploymentDescManager"); 80 Method m = manager.getDeclaredMethod("getInstance", new Class [] {}); 81 Object instance = m.invoke(null, new Object [] {}); 82 m = manager.getDeclaredMethod("getDeploymentDesc", new Class [] {URL .class, ClassLoader .class, 83 ClassLoader .class}); 84 ccDD = (ClientContainerDeploymentDesc) m.invoke(instance, new Object [] {url, moduleCL, earCL}); 85 } catch (InvocationTargetException ite) { 86 Throwable t = ite.getTargetException(); 87 if (ClientContainerDeploymentDescException.class.isInstance(t)) { 88 throw (ClientContainerDeploymentDescException) ite.getTargetException(); 89 } else { 90 throw new ClientContainerDeploymentDescException("ClientDeploymentDescManager.getDeploymentDesc fails", t); 91 } 92 } catch (Exception e) { 93 e.printStackTrace(); 94 throw new ClientContainerDeploymentDescException("Problems when using reflection on ClientDeploymentDescManager", e); 96 } 97 98 return ccDD; 99 } 100 101 108 public static void setAltDD(URLClassLoader earClassLoader, URL [] clientUrls, URL [] clientsAltDDs) { 109 LoaderManager lm = LoaderManager.getInstance(); 110 try { 111 ClassLoader tools = lm.getToolsLoader(); 112 Class manager = tools.loadClass("org.objectweb.jonas_client.deployment.lib.ClientDeploymentDescManager"); 113 Method m = manager.getDeclaredMethod("getInstance", new Class [] {}); 114 Object instance = m.invoke(null, new Object [] {}); 115 m = manager.getDeclaredMethod("setAltDD", new Class [] {ClassLoader .class, URL [].class, URL [].class}); 116 m.invoke(instance, new Object [] {earClassLoader, clientUrls, clientsAltDDs}); 117 } catch (Exception e) { 118 logger.log(BasicLevel.ERROR, e); 120 } 121 } 122 123 } | Popular Tags |