KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > deployment > web > NestedWebModule


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6 package org.jfox.deployment.web;
7
8 import java.io.File JavaDoc;
9 import java.net.URL JavaDoc;
10 import java.net.URLClassLoader JavaDoc;
11
12 import org.jfox.deployment.NestedModule;
13 import org.jfox.deployment.application.EARModule;
14 import org.jfox.ioc.deploy.DeployException;
15 import org.jfox.ioc.deployment.Deployer;
16 import org.jfox.ioc.util.JarUtils;
17 import org.jfox.ioc.util.XMLUtils;
18 import org.jfox.jndi.enc.EnterpriseContext;
19
20 /**
21  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
22  */

23
24 public class NestedWebModule extends WebModule implements NestedModule {
25     public static final String JavaDoc Target = "webapps" + File.separator;
26     private EARModule earModule;
27
28     //enterprise context
29
private EnterpriseContext enc = new EnterpriseContext();
30
31     private WebDescriptor webDescriptor;
32
33     public NestedWebModule(EARModule earModule, File JavaDoc warFile, String JavaDoc webConext) throws DeployException {
34         super(warFile, webConext);
35         this.earModule = earModule;
36         init();
37     }
38
39     protected void init() throws DeployException {
40         try {
41             JarUtils.extract(getPackage(), getTempDeployDirectory());
42
43             // parse web.xml for ejb-ref etc...
44
URL JavaDoc url = getDescriptorURL();
45             webDescriptor = new WebDescriptor(this);
46             webDescriptor.processXML(XMLUtils.getDocument(url).getDocumentElement());
47
48         }
49         catch(Exception JavaDoc e) {
50             throw new DeployException("extract web module " + getPackage() + " error", e);
51         }
52
53     }
54
55     public URL JavaDoc getDescriptorURL() {
56         try {
57             return new File JavaDoc(getTempDeployDirectory(), "WEB-INF/web.xml").toURL();
58         }
59         catch(Exception JavaDoc e) {
60             return null;
61         }
62     }
63
64     public void deploy(Deployer deployer) throws DeployException {
65         deployer.deploy(this);
66     }
67
68     public EARModule getEARModule() {
69         return earModule;
70     }
71
72     public File JavaDoc getTempDeployDirectory() {
73         File JavaDoc dir = new File JavaDoc(earModule.getTempDeployDirectory(), Target + getWebContext());
74         if(!dir.exists()) {
75             dir.mkdirs();
76         }
77         return dir;
78     }
79
80     public URLClassLoader JavaDoc getClassLoader() {
81         return earModule.getClassLoader();
82 // return (URLClassLoader)this.getClass().getClassLoader();
83
}
84
85     /**
86      * only nested web module need parse Web Descriptor
87      * the not nested WebModule let WebContainer do all of this
88      *
89      * @return
90      */

91     public WebDescriptor getWebDescriptor() {
92         return webDescriptor;
93     }
94
95     /**
96      * get the EnterpriseContext java:comp/env
97      *
98      * @return
99      */

100     public EnterpriseContext getEnterpriseContext() {
101         return enc;
102     }
103
104     public static void main(String JavaDoc[] args) {
105
106     }
107 }
108
109
Popular Tags