1 17 18 package org.apache.geronimo.deployment.util; 19 20 import java.io.IOException ; 21 import java.net.MalformedURLException ; 22 import java.net.URL ; 23 24 import javax.xml.parsers.DocumentBuilder ; 25 26 import org.apache.geronimo.common.DeploymentException; 27 import org.w3c.dom.Document ; 28 import org.xml.sax.SAXException ; 29 30 36 public class DeploymentHelper { 37 protected final URL url; 38 protected final URLType urlType; 39 protected URL j2eeURL; 40 protected URL geronimoURL; 41 42 48 public DeploymentHelper(URLInfo urlInfo, String j2eeDDName, 49 String geronimoDDName) throws DeploymentException { 50 this(urlInfo, j2eeDDName, geronimoDDName, "META-INF"); 51 } 52 53 62 public DeploymentHelper(URLInfo urlInfo, String j2eeDDName, 63 String geronimoDDName, String infDir) throws DeploymentException { 64 this.url = urlInfo.getUrl(); 65 this.urlType = urlInfo.getType(); 66 try { 67 if (URLType.RESOURCE == urlType) { 68 j2eeURL = null; 69 geronimoURL = url; 70 } else if (URLType.PACKED_ARCHIVE == urlType) { 71 j2eeURL = new URL ("jar:" + this.url.toExternalForm() + "!/" + infDir + "/" + j2eeDDName); 72 geronimoURL = new URL ("jar:" + this.url.toExternalForm() + "!/" + infDir + "/" + geronimoDDName); 73 } else if (URLType.UNPACKED_ARCHIVE == urlType) { 74 j2eeURL = new URL (this.url, infDir + "/" + j2eeDDName); 75 geronimoURL = new URL (this.url, infDir + "/" + geronimoDDName); 76 } else { 77 j2eeURL = null; 78 geronimoURL = null; 79 return; 80 } 81 } catch (MalformedURLException e1) { 82 throw new DeploymentException("Should never occur", e1); 83 } 84 } 85 91 public URL locateJ2EEDD() { 92 return j2eeURL; 93 } 94 95 public Document getJ2EEDoc(DocumentBuilder parser) { 96 return getDoc(parser, j2eeURL); 97 } 98 99 public Document getGeronimoDoc(DocumentBuilder parser) { 100 return getDoc(parser, geronimoURL); 101 } 102 103 private Document getDoc(DocumentBuilder parser, URL url) { 104 if (url == null) { 105 return null; 106 } 107 try { 108 return parser.parse(url.openStream()); 109 } catch (SAXException e) { 110 return null; 111 } catch (IOException e) { 112 return null; 113 } 114 } 115 116 122 public URL locateGeronimoDD() { 123 return geronimoURL; 124 } 125 } 126 | Popular Tags |