1 6 package org.jfox.deployment.web; 7 8 import java.io.File ; 9 import java.io.IOException ; 10 import java.net.URL ; 11 import java.net.URLClassLoader ; 12 13 import org.jfox.deployment.J2EEClassLoader; 14 import org.jfox.deployment.J2EEDeployMonitor; 15 import org.jfox.deployment.J2EEModule; 16 import org.jfox.ioc.deploy.DeployException; 17 import org.jfox.ioc.deployment.Deployer; 18 import org.jfox.ioc.util.JarUtils; 19 20 23 24 public class WebModule extends J2EEModule { 25 private File warFile; 26 private String baseDeployDirectory = J2EEDeployMonitor.getDeploymentDir(); 27 28 private J2EEClassLoader loader; 29 private String webContext; 30 31 public WebModule(File warFile) throws DeployException { 32 this.warFile = warFile; 33 this.webContext = warFile.getName().substring(0, warFile.getName().length() - 4); 35 init(); 36 } 37 38 protected WebModule(File warFile, String webContext) { 39 this.warFile = warFile; 40 this.webContext = webContext; 41 } 42 43 protected void init() throws DeployException { 44 try { 45 JarUtils.extract(warFile, getTempDeployDirectory()); 46 } 47 catch(IOException e) { 48 throw new DeployException("extract web module " + warFile + " error", e); 49 } 50 } 51 52 public URL getDescriptorURL() { 53 try { 54 return new File (getTempDeployDirectory(), "WEB-INF/web.xml").toURL(); 55 } 56 catch(Exception e) { 57 return null; 58 } 59 } 60 61 public File getPackage() { 62 return warFile; 63 } 64 65 70 public URLClassLoader getClassLoader() { 71 if(loader == null) { 72 loader = new J2EEClassLoader(new URL []{}, this.getClass().getClassLoader()); 73 } 74 return loader; 75 } 76 77 public File getTempDeployDirectory() { 78 File dir = new File (baseDeployDirectory, warFile.getName() + File.separator + "webapp" + File.separator + webContext); 79 if(!dir.exists()) { 80 dir.mkdirs(); 81 } 82 return dir; 83 } 84 85 public void deploy(Deployer deployer) throws DeployException { 86 deployer.deploy(this); 87 } 88 89 public String getWebContext() { 90 return webContext; 91 } 92 93 public static void main(String [] args) { 94 95 } 96 } 97 98 | Popular Tags |