1 20 package org.apache.cactus.integration.ant.deployment; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.Iterator ; 25 26 import javax.xml.parsers.ParserConfigurationException ; 27 28 import org.apache.cactus.integration.ant.deployment.application.ApplicationXml; 29 import org.apache.cactus.integration.ant.deployment.application.DefaultEarArchive; 30 import org.apache.cactus.integration.ant.deployment.application.EarArchive; 31 import org.apache.cactus.integration.ant.deployment.webapp.WarArchive; 32 import org.apache.tools.ant.BuildException; 33 import org.xml.sax.SAXException ; 34 35 42 public class EarParser 43 { 44 50 public static final EarDeployableFile parse(File theDeployableFile) 51 { 52 EarDeployableFile deployable = new EarDeployableFile(); 53 54 try 55 { 56 deployable.setFile(theDeployableFile); 57 58 EarArchive earArchive = new DefaultEarArchive(theDeployableFile); 59 String webUri = getUriOfCactifiedWebModule(earArchive); 60 if (webUri == null) 61 { 62 throw new BuildException("Could not find cactified web " 63 + "module in the [" + theDeployableFile + "] EAR."); 64 } 65 66 WarArchive warArchive = earArchive.getWebModule(webUri); 67 if (warArchive == null) 68 { 69 throw new BuildException("Could not find the WAR [" + webUri 70 + "] in the [" + theDeployableFile + "] EAR."); 71 } 72 73 deployable.setWarArchive(warArchive); 74 deployable.setTestContext(parseTestContext(earArchive, webUri)); 75 deployable.setServletRedirectorMapping( 76 WarParser.parseServletRedirectorMapping( 77 deployable.getWarArchive())); 78 deployable.setFilterRedirectorMapping( 79 WarParser.parseFilterRedirectorMapping( 80 deployable.getWarArchive())); 81 deployable.setJspRedirectorMapping( 82 WarParser.parseJspRedirectorMapping( 83 deployable.getWarArchive())); 84 } 85 catch (IOException e) 86 { 87 throw new BuildException("Failed to parse deployment descriptor " 88 + "for EAR file [" + theDeployableFile + "].", e); 89 } 90 catch (ParserConfigurationException e) 91 { 92 throw new BuildException("Failed to parse deployment descriptor " 93 + "for EAR file [" + theDeployableFile + "].", e); 94 } 95 catch (SAXException e) 96 { 97 throw new BuildException("Failed to parse deployment descriptor " 98 + "for EAR file [" + theDeployableFile + "].", e); 99 } 100 101 return deployable; 102 } 103 104 118 protected static final String parseTestContext(EarArchive theEar, 119 String theWebUri) 120 throws ParserConfigurationException , IOException , SAXException 121 { 122 String context = theEar.getApplicationXml() 123 .getWebModuleContextRoot(theWebUri); 124 if (context == null) 125 { 126 throw new BuildException("Your application.xml must define a " 129 + "<context-root> element in the <web> module definition."); 130 } 131 132 if (context.startsWith("/")) 134 { 135 context = context.substring(1); 136 } 137 138 return context; 139 } 140 141 158 protected static final String getUriOfCactifiedWebModule(EarArchive theEar) 159 throws SAXException , IOException , ParserConfigurationException 160 { 161 ApplicationXml applicationXml = theEar.getApplicationXml(); 162 for (Iterator i = applicationXml.getWebModuleUris(); i.hasNext();) 163 { 164 String webUri = (String ) i.next(); 165 WarArchive war = theEar.getWebModule(webUri); 166 if ((war != null) 167 && (WarParser.parseServletRedirectorMapping(war) != null)) 168 { 169 return webUri; 170 } 171 } 172 return null; 173 } 174 } 175 | Popular Tags |