KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > integration > ant > container > tomcat > Tomcat4xContainer


1 /*
2  * ========================================================================
3  *
4  * Copyright 2003-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.cactus.integration.ant.container.tomcat;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24
25 import org.apache.tools.ant.BuildException;
26 import org.apache.tools.ant.util.FileUtils;
27
28 /**
29  * Special container support for the Apache Tomcat 4.x servlet container.
30  *
31  * @version $Id: Tomcat4xContainer.java,v 1.6 2004/02/29 10:10:41 vmassol Exp $
32  */

33 public class Tomcat4xContainer extends AbstractCatalinaContainer
34 {
35     // Instance Variables ------------------------------------------------------
36

37     /**
38      * A user-specific context xml configuration file.
39      */

40     private File JavaDoc contextXml;
41
42     // Public Methods ----------------------------------------------------------
43

44     /**
45      * @return The context xml file, if set or null otherwise
46      */

47     public final File JavaDoc getContextXml()
48     {
49         return this.contextXml;
50     }
51
52     /**
53      * Sets a user-custom context xml configuration file to use for the test
54      * installation of Tomcat.
55      *
56      * @param theContextXml the custom context xml file to use
57      */

58     public final void setContextXml(File JavaDoc theContextXml)
59     {
60         this.contextXml = theContextXml;
61     }
62     
63     // Container Implementation ------------------------------------------------
64

65     /**
66      * @see org.apache.cactus.integration.ant.container.Container#init
67      */

68     public final void init()
69     {
70         super.init();
71
72         if (!getVersion().startsWith("4"))
73         {
74             throw new BuildException(
75                 "This element doesn't support version " + getVersion()
76                 + " of Tomcat");
77         }
78     }
79
80     /**
81      * @see org.apache.cactus.integration.ant.container.Container#startUp
82      */

83     public final void startUp()
84     {
85         try
86         {
87             prepare("tomcat4x", "cactus/tomcat4x");
88             invokeBootstrap("start");
89         }
90         catch (IOException JavaDoc ioe)
91         {
92             getLog().error("Failed to startup the container", ioe);
93             throw new BuildException(ioe);
94         }
95     }
96
97     /**
98      * @see org.apache.cactus.integration.ant.container.Container#shutDown
99      */

100     public final void shutDown()
101     {
102         invokeBootstrap("stop");
103     }
104
105     /**
106      * Tomcat 4.x-specific setup of a temporary installation of the container.
107      *
108      * @param theResourcePrefix The prefix to use when looking up container
109      * resource in the JAR
110      * @param theDirName The name of the temporary container installation
111      * directory
112      * @throws IOException If an I/O error occurs
113      * @see AbstractCatalinaContainer#prepare(String, String)
114      */

115     protected void prepare(String JavaDoc theResourcePrefix, String JavaDoc theDirName)
116         throws IOException JavaDoc
117     {
118         super.prepare(theResourcePrefix, theDirName);
119
120         FileUtils fileUtils = FileUtils.newFileUtils();
121         
122         // Copy user-provided context xml file into the temporary webapp/
123
// container directory
124
File JavaDoc webappsDir = new File JavaDoc(getTmpDir(), "webapps");
125         if (getContextXml() != null)
126         {
127             fileUtils.copyFile(getContextXml(),
128                 new File JavaDoc(webappsDir, getContextXml().getName()));
129         }
130         
131     }
132     
133 }
134
Popular Tags