1 package net.sourceforge.ejtools.deploy.model; 2 3 import java.io.InputStream ; 4 import java.net.JarURLConnection ; 5 import java.net.URL ; 6 import java.net.URLClassLoader ; 7 import java.util.Vector ; 8 9 import javax.enterprise.deploy.model.DDBean ; 10 import javax.enterprise.deploy.model.DDBeanRoot ; 11 import javax.enterprise.deploy.model.DeployableObject ; 12 import javax.enterprise.deploy.shared.ModuleType ; 13 import javax.xml.parsers.DocumentBuilder ; 14 import javax.xml.parsers.DocumentBuilderFactory ; 15 16 import net.sourceforge.ejtools.deploy.xml.DTDResolver; 17 18 import org.apache.xpath.XPathAPI; 19 import org.w3c.dom.Document ; 20 import org.w3c.dom.NodeList ; 21 22 30 public class WarProxy implements DeployableObject 31 { 32 33 protected URL archiveFile = null; 34 35 protected Document descriptor = null; 36 37 protected URLClassLoader loader = null; 38 39 40 46 public WarProxy(ClassLoader parent, URL archiveFile) 47 { 48 this.archiveFile = archiveFile; 49 try 50 { 51 52 this.loader = new URLClassLoader (new URL []{archiveFile}, parent); 53 54 JarURLConnection conn = (JarURLConnection ) (new URL ("jar:" + archiveFile + "!/WEB-INF/web.xml")).openConnection(); 55 InputStream in = conn.getInputStream(); 56 DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 57 builder.setEntityResolver(new DTDResolver()); 58 descriptor = builder.parse(in); 59 in.close(); 60 } 61 catch (Exception e) 62 { 63 e.printStackTrace(); 64 } 65 66 } 67 68 69 75 public DDBean [] getChildBean(String xpath) 76 { 77 return null; 78 } 79 80 81 87 public Class getClassFromScope(String className) 88 { 89 try 90 { 91 return loader.loadClass(className); 92 } 93 catch (Exception e) 94 { 95 } 96 return null; 97 } 98 99 100 105 public DDBeanRoot getDDBeanRoot() 106 { 107 return null; 108 } 109 110 111 116 public String getModuleDTDVersion() 117 { 118 return "2.3"; 119 } 120 121 122 128 public String [] getText(String xpath) 129 { 130 System.out.println("Searching for " + xpath); 131 Vector result = new Vector (); 132 try 133 { 134 NodeList list = XPathAPI.selectNodeList(descriptor, xpath); 135 System.out.println("List " + list); 136 for (int i = 0; i < list.getLength(); i++) 137 { 138 result.add(list.item(i).toString()); 139 } 140 } 141 catch (Exception e) 142 { 143 } 144 145 return (String []) result.toArray(new String [0]); 146 } 147 148 149 154 public ModuleType getType() 155 { 156 return ModuleType.WAR; 157 } 158 159 160 165 public String toString() 166 { 167 String result = ""; 168 169 result = result + archiveFile + "\n"; 170 result = result + loader + "\n"; 171 result = result + descriptor + "\n"; 172 173 return result; 174 } 175 } 176 | Popular Tags |