1 25 package org.objectweb.jonas_rar.deployment.lib.wrapper; 26 27 import java.lang.reflect.InvocationTargetException ; 28 import java.lang.reflect.Method ; 29 30 import javax.naming.Context ; 31 32 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException; 33 34 import org.objectweb.jonas_rar.deployment.api.RarDeploymentDesc; 35 import org.objectweb.jonas_rar.deployment.api.RarDeploymentDescException; 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 44 49 public class RarManagerWrapper { 50 51 54 private static final String RAR_MANAGER_CLASSNAME = "org.objectweb.jonas_rar.deployment.lib.RarDeploymentDescManager"; 55 56 59 private static Logger logger = Log.getLogger(Log.JONAS_EAR_PREFIX); 60 61 64 private RarManagerWrapper() { 65 } 66 67 77 public static RarDeploymentDesc getRarDeploymentDesc(String rar, ClassLoader cl) 78 throws DeploymentDescException { 79 LoaderManager lm = LoaderManager.getInstance(); 80 RarDeploymentDesc rarDD = null; 81 try { 82 ClassLoader tools = lm.getToolsLoader(); 83 Class manager = tools.loadClass(RAR_MANAGER_CLASSNAME); 84 Method m = manager.getDeclaredMethod("getInstance", new Class [] {java.lang.String .class, java.lang.ClassLoader .class}); 85 rarDD = (RarDeploymentDesc) m.invoke(null, new Object [] {rar, cl}); 86 } catch (InvocationTargetException ite) { 87 Throwable t = ite.getTargetException(); 88 if (RarDeploymentDescException.class.isInstance(t)) { 89 throw (RarDeploymentDescException) ite.getTargetException(); 90 } else { 91 throw new RarDeploymentDescException("RarDeploymentDescManager.getInstance fails", t); 92 } 93 } catch (Exception e) { 94 throw new RarDeploymentDescException("Problems when using reflection on RarDeploymentDescManager", e); 96 } 97 return rarDD; 98 } 99 100 105 public static void setParsingWithValidation(boolean b) { 106 LoaderManager lm = LoaderManager.getInstance(); 107 108 try { 109 ClassLoader tools = lm.getToolsLoader(); 110 Class manager = tools.loadClass(RAR_MANAGER_CLASSNAME); 111 Method m = manager.getDeclaredMethod("setParsingWithValidation", new Class [] {boolean.class}); 112 m.invoke(null, new Object [] {new Boolean (b)}); 113 } catch (Exception e) { 114 logger.log(BasicLevel.ERROR, e); 116 } 117 } 118 119 128 public static RarDeploymentDesc getInstance(Context ctx) throws DeploymentDescException { 129 LoaderManager lm = LoaderManager.getInstance(); 130 RarDeploymentDesc rarDD = null; 131 132 try { 133 ClassLoader tools = lm.getToolsLoader(); 134 Class manager = tools.loadClass(RAR_MANAGER_CLASSNAME); 135 Method m = manager.getDeclaredMethod("getInstance", new Class [] {javax.naming.Context .class}); 136 rarDD = (RarDeploymentDesc) m.invoke(null, new Object [] {ctx}); 137 } catch (InvocationTargetException ite) { 138 Throwable t = ite.getTargetException(); 139 if (RarDeploymentDescException.class.isInstance(t)) { 140 throw (RarDeploymentDescException) ite.getTargetException(); 141 } else { 142 throw new RarDeploymentDescException("RarDeploymentDescManager.getInstance fails", t); 143 } 144 } catch (Exception e) { 145 throw new RarDeploymentDescException("Problems when using reflection on RarDeploymentDescManager", e); 147 } 148 149 return rarDD; 150 } 151 152 } 153 | Popular Tags |