1 6 package org.jfox.deployment.web; 7 8 import java.io.File ; 9 import java.net.URL ; 10 import java.net.URLClassLoader ; 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 23 24 public class NestedWebModule extends WebModule implements NestedModule { 25 public static final String Target = "webapps" + File.separator; 26 private EARModule earModule; 27 28 private EnterpriseContext enc = new EnterpriseContext(); 30 31 private WebDescriptor webDescriptor; 32 33 public NestedWebModule(EARModule earModule, File warFile, String 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 URL url = getDescriptorURL(); 45 webDescriptor = new WebDescriptor(this); 46 webDescriptor.processXML(XMLUtils.getDocument(url).getDocumentElement()); 47 48 } 49 catch(Exception e) { 50 throw new DeployException("extract web module " + getPackage() + " error", e); 51 } 52 53 } 54 55 public URL getDescriptorURL() { 56 try { 57 return new File (getTempDeployDirectory(), "WEB-INF/web.xml").toURL(); 58 } 59 catch(Exception 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 getTempDeployDirectory() { 73 File dir = new File (earModule.getTempDeployDirectory(), Target + getWebContext()); 74 if(!dir.exists()) { 75 dir.mkdirs(); 76 } 77 return dir; 78 } 79 80 public URLClassLoader getClassLoader() { 81 return earModule.getClassLoader(); 82 } 84 85 91 public WebDescriptor getWebDescriptor() { 92 return webDescriptor; 93 } 94 95 100 public EnterpriseContext getEnterpriseContext() { 101 return enc; 102 } 103 104 public static void main(String [] args) { 105 106 } 107 } 108 109 | Popular Tags |