Source Code Cross Referenced for EarParser.java in  » Testing » jakarta-cactus » org » apache » cactus » integration » ant » deployment » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » jakarta cactus » org.apache.cactus.integration.ant.deployment 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * ========================================================================
003:         * 
004:         * Copyright 2003 The Apache Software Foundation.
005:         *
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         * 
010:         *   http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         * 
018:         * ========================================================================
019:         */
020:        package org.apache.cactus.integration.ant.deployment;
021:
022:        import java.io.File;
023:        import java.io.IOException;
024:        import java.util.Iterator;
025:
026:        import javax.xml.parsers.ParserConfigurationException;
027:
028:        import org.apache.cactus.integration.ant.deployment.application.ApplicationXml;
029:        import org.apache.cactus.integration.ant.deployment.application.DefaultEarArchive;
030:        import org.apache.cactus.integration.ant.deployment.application.EarArchive;
031:        import org.apache.cactus.integration.ant.deployment.webapp.WarArchive;
032:        import org.apache.tools.ant.BuildException;
033:        import org.xml.sax.SAXException;
034:
035:        /**
036:         * Parse an EAR descriptor to extract meaninful information for Cactus,
037:         * the results being stored in a {@link EarDeployableFile} object. 
038:         * 
039:         * @since Cactus 1.5
040:         * @version $Id: EarParser.java 239003 2004-05-31 20:05:27Z vmassol $
041:         */
042:        public class EarParser {
043:            /**
044:             * Parse an EAR descriptor to extract meaninful information for Cactus.
045:             * 
046:             * @param theDeployableFile the file to parse and deploy
047:             * @return the parse results as a {@link EarDeployableFile} object
048:             */
049:            public static final EarDeployableFile parse(File theDeployableFile) {
050:                EarDeployableFile deployable = new EarDeployableFile();
051:
052:                try {
053:                    deployable.setFile(theDeployableFile);
054:
055:                    EarArchive earArchive = new DefaultEarArchive(
056:                            theDeployableFile);
057:                    String webUri = getUriOfCactifiedWebModule(earArchive);
058:                    if (webUri == null) {
059:                        throw new BuildException(
060:                                "Could not find cactified web "
061:                                        + "module in the [" + theDeployableFile
062:                                        + "] EAR.");
063:                    }
064:
065:                    WarArchive warArchive = earArchive.getWebModule(webUri);
066:                    if (warArchive == null) {
067:                        throw new BuildException("Could not find the WAR ["
068:                                + webUri + "] in the [" + theDeployableFile
069:                                + "] EAR.");
070:                    }
071:
072:                    deployable.setWarArchive(warArchive);
073:                    deployable.setTestContext(parseTestContext(earArchive,
074:                            webUri));
075:                    deployable.setServletRedirectorMapping(WarParser
076:                            .parseServletRedirectorMapping(deployable
077:                                    .getWarArchive()));
078:                    deployable.setFilterRedirectorMapping(WarParser
079:                            .parseFilterRedirectorMapping(deployable
080:                                    .getWarArchive()));
081:                    deployable.setJspRedirectorMapping(WarParser
082:                            .parseJspRedirectorMapping(deployable
083:                                    .getWarArchive()));
084:                } catch (IOException e) {
085:                    throw new BuildException(
086:                            "Failed to parse deployment descriptor "
087:                                    + "for EAR file [" + theDeployableFile
088:                                    + "].", e);
089:                } catch (ParserConfigurationException e) {
090:                    throw new BuildException(
091:                            "Failed to parse deployment descriptor "
092:                                    + "for EAR file [" + theDeployableFile
093:                                    + "].", e);
094:                } catch (SAXException e) {
095:                    throw new BuildException(
096:                            "Failed to parse deployment descriptor "
097:                                    + "for EAR file [" + theDeployableFile
098:                                    + "].", e);
099:                }
100:
101:                return deployable;
102:            }
103:
104:            /**
105:             * Find the test context from the EAR archive. 
106:             * 
107:             * @return the test context
108:             * @param theEar the EAR archive from which to extract the test context
109:             * @param theWebUri the WAR URI of the WAR file in the EAR from which to
110:             *        extract the test context
111:             * @throws IOException If there was a problem reading the  deployment
112:             *         descriptor in the WAR
113:             * @throws SAXException If the deployment descriptor of the WAR could not
114:             *         be parsed
115:             * @throws ParserConfigurationException If there is an XML parser
116:             *         configration problem
117:             */
118:            protected static final String parseTestContext(EarArchive theEar,
119:                    String theWebUri) throws ParserConfigurationException,
120:                    IOException, SAXException {
121:                String context = theEar.getApplicationXml()
122:                        .getWebModuleContextRoot(theWebUri);
123:                if (context == null) {
124:                    // The application.xml does not define a <context-root> element.
125:                    // This is wrong!
126:                    throw new BuildException(
127:                            "Your application.xml must define a "
128:                                    + "<context-root> element in the <web> module definition.");
129:                }
130:
131:                // Remove leading "/" if there is one.
132:                if (context.startsWith("/")) {
133:                    context = context.substring(1);
134:                }
135:
136:                return context;
137:            }
138:
139:            /**
140:             * Finds the web module in the EAR that contains the servlet test 
141:             * redirector, and returns the web-uri of the module found.
142:             * 
143:             * <em>A web-app is considered cactified when it contains at least a 
144:             * mapping for the Cactus servlet test redirector</em>
145:             * 
146:             * @return The URI of the cactified web-module, or <code>null</code> if no
147:             *         cactified web-app could be found
148:             * @param theEar the EAR archive from which to extract the web URI 
149:             * @throws IOException If there was a problem reading the  deployment
150:             *         descriptor in the WAR
151:             * @throws SAXException If the deployment descriptor of the WAR could not
152:             *         be parsed
153:             * @throws ParserConfigurationException If there is an XML parser
154:             *         configration problem
155:             */
156:            protected static final String getUriOfCactifiedWebModule(
157:                    EarArchive theEar) throws SAXException, IOException,
158:                    ParserConfigurationException {
159:                ApplicationXml applicationXml = theEar.getApplicationXml();
160:                for (Iterator i = applicationXml.getWebModuleUris(); i
161:                        .hasNext();) {
162:                    String webUri = (String) i.next();
163:                    WarArchive war = theEar.getWebModule(webUri);
164:                    if ((war != null)
165:                            && (WarParser.parseServletRedirectorMapping(war) != null)) {
166:                        return webUri;
167:                    }
168:                }
169:                return null;
170:            }
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.