1 25 package org.objectweb.jonas_ws.deployment.lib.wrapper; 26 27 import java.io.File ; 28 import java.io.InputStream ; 29 import java.lang.reflect.InvocationTargetException ; 30 import java.lang.reflect.Method ; 31 32 import org.objectweb.jonas_ws.deployment.api.MappingFile; 33 import org.objectweb.jonas_ws.deployment.api.WSDeploymentDescException; 34 35 import org.objectweb.jonas.server.LoaderManager; 36 37 38 44 public class MappingFileManagerWrapper { 45 46 49 private static final String MAPPINGFILEMANAGER_CLASSNAME = "org.objectweb.jonas_ws.deployment.lib.MappingFileManager"; 50 51 54 private MappingFileManagerWrapper() { } 55 56 66 public static MappingFile getMappingFile(File module, String filename) 67 throws WSDeploymentDescException { 68 LoaderManager lm = LoaderManager.getInstance(); 69 MappingFile mf = null; 70 71 try { 72 ClassLoader tools = lm.getToolsLoader(); 73 Class manager = tools.loadClass(MAPPINGFILEMANAGER_CLASSNAME); 74 Method m = manager.getDeclaredMethod("getInstance", new Class [] {File .class, String .class}); 75 mf = (MappingFile) m.invoke(null, new Object [] {module, filename}); 76 } catch (InvocationTargetException ite) { 77 Throwable t = ite.getTargetException(); 78 if (WSDeploymentDescException.class.isInstance(t)) { 79 throw (WSDeploymentDescException) ite.getTargetException(); 80 } else { 81 throw new WSDeploymentDescException("MappingFileManager.getInstance fails", t); 82 } 83 } catch (Exception e) { 84 throw new WSDeploymentDescException("Problems when using reflection on MappingFileManager", e); 86 } 87 88 return mf; 89 } 90 91 101 public static MappingFile getMappingFile(InputStream is, String filename) 102 throws WSDeploymentDescException { 103 LoaderManager lm = LoaderManager.getInstance(); 104 MappingFile mf = null; 105 106 try { 107 ClassLoader tools = lm.getToolsLoader(); 108 Class manager = tools.loadClass(MAPPINGFILEMANAGER_CLASSNAME); 109 Method m = manager.getDeclaredMethod("getInstance", new Class [] {InputStream .class, String .class}); 110 mf = (MappingFile) m.invoke(null, new Object [] {is, filename}); 111 } catch (InvocationTargetException ite) { 112 Throwable t = ite.getTargetException(); 113 if (WSDeploymentDescException.class.isInstance(t)) { 114 throw (WSDeploymentDescException) ite.getTargetException(); 115 } else { 116 throw new WSDeploymentDescException("MappingFileManager.getInstance fails", t); 117 } 118 } catch (Exception e) { 119 throw new WSDeploymentDescException("Problems when using reflection on MappingFileManager", e); 121 } 122 123 return mf; 124 } 125 } 126 | Popular Tags |