KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > ejtools > deploy > model > WarProxy


1 package net.sourceforge.ejtools.deploy.model;
2
3 import java.io.InputStream JavaDoc;
4 import java.net.JarURLConnection JavaDoc;
5 import java.net.URL JavaDoc;
6 import java.net.URLClassLoader JavaDoc;
7 import java.util.Vector JavaDoc;
8
9 import javax.enterprise.deploy.model.DDBean JavaDoc;
10 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
11 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
12 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
13 import javax.xml.parsers.DocumentBuilder JavaDoc;
14 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
15
16 import net.sourceforge.ejtools.deploy.xml.DTDResolver;
17
18 import org.apache.xpath.XPathAPI;
19 import org.w3c.dom.Document JavaDoc;
20 import org.w3c.dom.NodeList JavaDoc;
21
22 /**
23  * The DeployableObject interface is an abstract representation of a J2EE deployable module (JAR, WAR, RAR, EAR). A DeployableObject provides access to the
24  * module's deployment descriptor and class files.
25  *
26  * @author gfink
27  * @created 28 mai 2002
28  * @version 0.1
29  */

30 public class WarProxy implements DeployableObject JavaDoc
31 {
32    /** Description of the Field */
33    protected URL JavaDoc archiveFile = null;
34    /** Description of the Field */
35    protected Document JavaDoc descriptor = null;
36    /** Description of the Field */
37    protected URLClassLoader JavaDoc loader = null;
38
39
40    /**
41     * Constructor for the WarProxy object
42     *
43     * @param parent Description of the Parameter
44     * @param archiveFile Description of the Parameter
45     */

46    public WarProxy(ClassLoader JavaDoc parent, URL JavaDoc archiveFile)
47    {
48       this.archiveFile = archiveFile;
49       try
50       {
51
52          this.loader = new URLClassLoader JavaDoc(new URL JavaDoc[]{archiveFile}, parent);
53
54          JarURLConnection JavaDoc conn = (JarURLConnection JavaDoc) (new URL JavaDoc("jar:" + archiveFile + "!/WEB-INF/web.xml")).openConnection();
55          InputStream JavaDoc in = conn.getInputStream();
56          DocumentBuilder JavaDoc builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
57          builder.setEntityResolver(new DTDResolver());
58          descriptor = builder.parse(in);
59          in.close();
60       }
61       catch (Exception JavaDoc e)
62       {
63          e.printStackTrace();
64       }
65
66    }
67
68
69    /**
70     * Gets the childBean attribute of the WarProxy object
71     *
72     * @param xpath Description of the Parameter
73     * @return The childBean value
74     */

75    public DDBean JavaDoc[] getChildBean(String JavaDoc xpath)
76    {
77       return null;
78    }
79
80
81    /**
82     * Gets the classFromScope attribute of the WarProxy object
83     *
84     * @param className Description of the Parameter
85     * @return The classFromScope value
86     */

87    public Class JavaDoc getClassFromScope(String JavaDoc className)
88    {
89       try
90       {
91          return loader.loadClass(className);
92       }
93       catch (Exception JavaDoc e)
94       {
95       }
96       return null;
97    }
98
99
100    /**
101     * Gets the dDBeanRoot attribute of the WarProxy object
102     *
103     * @return The dDBeanRoot value
104     */

105    public DDBeanRoot JavaDoc getDDBeanRoot()
106    {
107       return null;
108    }
109
110
111    /**
112     * Gets the moduleDTDVersion attribute of the WarProxy object
113     *
114     * @return The moduleDTDVersion value
115     */

116    public String JavaDoc getModuleDTDVersion()
117    {
118       return "2.3";
119    }
120
121
122    /**
123     * Gets the text attribute of the WarProxy object
124     *
125     * @param xpath Description of the Parameter
126     * @return The text value
127     */

128    public String JavaDoc[] getText(String JavaDoc xpath)
129    {
130       System.out.println("Searching for " + xpath);
131       Vector JavaDoc result = new Vector JavaDoc();
132       try
133       {
134          NodeList JavaDoc 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 JavaDoc e)
142       {
143       }
144
145       return (String JavaDoc[]) result.toArray(new String JavaDoc[0]);
146    }
147
148
149    /**
150     * Gets the type attribute of the WarProxy object
151     *
152     * @return The type value
153     */

154    public ModuleType JavaDoc getType()
155    {
156       return ModuleType.WAR;
157    }
158
159
160    /**
161     * Description of the Method
162     *
163     * @return Description of the Return Value
164     */

165    public String JavaDoc toString()
166    {
167       String JavaDoc 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