Source Code Cross Referenced for AbstractCatalinaContainer.java in  » Testing » jakarta-cactus » org » apache » cactus » integration » ant » container » tomcat » 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.container.tomcat 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * ========================================================================
003:         * 
004:         * Copyright 2003-2004 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.container.tomcat;
021:
022:        import java.io.File;
023:        import java.io.IOException;
024:        import java.util.Properties;
025:        import java.util.jar.JarFile;
026:        import java.util.zip.ZipEntry;
027:
028:        import org.apache.cactus.integration.ant.util.ResourceUtils;
029:        import org.apache.tools.ant.BuildException;
030:        import org.apache.tools.ant.taskdefs.Java;
031:        import org.apache.tools.ant.types.FilterChain;
032:        import org.apache.tools.ant.types.Path;
033:        import org.apache.tools.ant.util.FileUtils;
034:
035:        /**
036:         * Base support for Catalina based containers.
037:         * 
038:         * @version $Id: AbstractCatalinaContainer.java 239003 2004-05-31 20:05:27Z vmassol $
039:         */
040:        public abstract class AbstractCatalinaContainer extends
041:                AbstractTomcatContainer {
042:            // Instance Variables ------------------------------------------------------
043:
044:            /**
045:             * The temporary directory from which the container will be started.
046:             */
047:            private File tmpDir;
048:
049:            /**
050:             * The Catalina version detected by reading a property file in the
051:             * installation directory.
052:             */
053:            private String version;
054:
055:            // Public Methods ----------------------------------------------------------
056:
057:            /**
058:             * Sets the temporary installation directory.
059:             * 
060:             * @param theTmpDir The temporary directory to set
061:             */
062:            public final void setTmpDir(File theTmpDir) {
063:                this .tmpDir = theTmpDir;
064:            }
065:
066:            // AbstractContainer Implementation ----------------------------------------
067:
068:            /**
069:             * @see org.apache.cactus.integration.ant.container.Container#getName
070:             */
071:            public final String getName() {
072:                return "Tomcat " + this .version;
073:            }
074:
075:            /**
076:             * @see org.apache.cactus.integration.ant.container.Container#init
077:             */
078:            public void init() {
079:                // Check the installation directory
080:                this .version = getVersion();
081:                if (this .version == null) {
082:                    throw new BuildException(getDir()
083:                            + " not recognized as a Tomcat 4.x installation");
084:                }
085:            }
086:
087:            // Protected Methods -------------------------------------------------------
088:
089:            /**
090:             * Returns the version of the Tomcat installation.
091:             * 
092:             * @return The Tomcat version, or <code>null</code> if the verion number
093:             *         could not be retrieved
094:             */
095:            protected final String getVersion() {
096:                if (this .version == null) {
097:                    try {
098:                        // Unfortunately, there's no safe way to find out the version of
099:                        // a Catalina installation, so we need to try multiple paths
100:                        // here
101:
102:                        // Tomcat 4.1.0 and later includes a ServerInfo.properties
103:                        // resource in catalina.jar that contains the version number. If
104:                        // that resource doesn't exist, we're on Tomcat 4.0.x
105:                        JarFile catalinaJar = new JarFile(new File(getDir(),
106:                                "server/lib/catalina.jar"));
107:                        ZipEntry entry = catalinaJar
108:                                .getEntry("org/apache/catalina/util/ServerInfo.properties");
109:                        if (entry != null) {
110:                            Properties props = new Properties();
111:                            props.load(catalinaJar.getInputStream(entry));
112:                            String serverInfo = props
113:                                    .getProperty("server.info");
114:                            if (serverInfo.indexOf('/') > 0) {
115:                                this .version = serverInfo.substring(serverInfo
116:                                        .indexOf('/') + 1);
117:                            }
118:                        } else {
119:                            this .version = "4.0.x";
120:                        }
121:                    } catch (IOException ioe) {
122:                        getLog().warn(
123:                                "Couldn't retrieve Tomcat version information",
124:                                ioe);
125:                    }
126:                }
127:                return this .version;
128:            }
129:
130:            /**
131:             * Invokes the Catalina Bootstrap class to start or stop the container, 
132:             * depending on the value of the provided argument.
133:             * 
134:             * @param theArg Either 'start' or 'stop'
135:             */
136:            protected final void invokeBootstrap(String theArg) {
137:                Java java = null;
138:                if ("start".equals(theArg)) {
139:                    java = createJavaForStartUp();
140:                } else {
141:                    java = createJavaForShutDown();
142:                }
143:                java
144:                        .addSysproperty(createSysProperty("catalina.home",
145:                                getDir()));
146:                java.addSysproperty(createSysProperty("catalina.base",
147:                        getTmpDir()));
148:                Path classpath = java.createClasspath();
149:                classpath.createPathElement().setLocation(
150:                        new File(getDir(), "bin/bootstrap.jar"));
151:                addToolsJarToClasspath(classpath);
152:                java.setClassname("org.apache.catalina.startup.Bootstrap");
153:                java.createArg().setValue(theArg);
154:                java.execute();
155:            }
156:
157:            /**
158:             * Prepares a temporary installation of the container and deploys the 
159:             * web-application.
160:             * 
161:             * @param theResourcePrefix The prefix to use when looking up container
162:             *        resource in the JAR
163:             * @param theDirName The name of the temporary container installation
164:             *        directory
165:             * @throws IOException If an I/O error occurs
166:             */
167:            protected void prepare(String theResourcePrefix, String theDirName)
168:                    throws IOException {
169:                FileUtils fileUtils = FileUtils.newFileUtils();
170:                FilterChain filterChain = createFilterChain();
171:
172:                setTmpDir(setupTempDirectory(getTmpDir(), theDirName));
173:                cleanTempDirectory(getTmpDir());
174:
175:                File confDir = createDirectory(getTmpDir(), "conf");
176:
177:                // Copy first the default configuration files so that they can be
178:                // overriden by the user-provided ones.
179:
180:                if (getServerXml() == null) {
181:                    ResourceUtils.copyResource(getProject(), RESOURCE_PATH
182:                            + theResourcePrefix + "/server.xml", new File(
183:                            confDir, "server.xml"), filterChain);
184:                }
185:
186:                ResourceUtils.copyResource(getProject(), RESOURCE_PATH
187:                        + theResourcePrefix + "/tomcat-users.xml", new File(
188:                        confDir, "tomcat-users.xml"));
189:                fileUtils.copyFile(new File(getDir(), "conf/web.xml"),
190:                        new File(confDir, "web.xml"));
191:
192:                // deploy the web-app by copying the WAR file into the webapps
193:                // directory
194:                File webappsDir = createDirectory(getTmpDir(), "webapps");
195:                fileUtils.copyFile(getDeployableFile().getFile(), new File(
196:                        webappsDir, getDeployableFile().getFile().getName()),
197:                        null, true);
198:
199:                // Copy user-provided configuration files into the temporary conf/ 
200:                // container directory.
201:                copyConfFiles(confDir);
202:            }
203:
204:            /**
205:             * @return The temporary directory from which the container will be 
206:             *         started.
207:             */
208:            protected final File getTmpDir() {
209:                return this.tmpDir;
210:            }
211:        }
w___w_w__._j__a_v_a_2__s__.__c__om_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.