KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > integration > ant > container > orion > AbstractOrionContainer


1 /*
2  * ========================================================================
3  *
4  * Copyright 2003 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.orion;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24
25 import org.apache.cactus.integration.ant.container.AbstractJavaContainer;
26 import org.apache.cactus.integration.ant.util.ResourceUtils;
27 import org.apache.tools.ant.BuildException;
28 import org.apache.tools.ant.taskdefs.Java;
29 import org.apache.tools.ant.types.FileSet;
30 import org.apache.tools.ant.types.FilterChain;
31 import org.apache.tools.ant.types.Path;
32 import org.apache.tools.ant.util.FileUtils;
33
34 /**
35  * Basic support for the Orin application server.
36  *
37  * @version $Id: AbstractOrionContainer.java,v 1.11 2004/05/31 20:05:26 vmassol Exp $
38  */

39 public abstract class AbstractOrionContainer extends AbstractJavaContainer
40 {
41
42     // Instance Variables ------------------------------------------------------
43

44     /**
45      * The Orion 1.x installation directory.
46      */

47     private File JavaDoc dir;
48
49     /**
50      * The port to which the container should be bound.
51      */

52     private int port = 8080;
53
54     /**
55      * The temporary directory from which the container will be started.
56      */

57     private File JavaDoc tmpDir;
58
59     // Public Methods ----------------------------------------------------------
60

61     /**
62      * Sets the Orion installation directory.
63      *
64      * @param theDir The directory to set
65      */

66     public final void setDir(File JavaDoc theDir)
67     {
68         this.dir = theDir;
69     }
70
71     /**
72      * Sets the port to which the container should listen.
73      *
74      * @param thePort The port to set
75      */

76     public final void setPort(int thePort)
77     {
78         this.port = thePort;
79     }
80
81     /**
82      * Sets the temporary directory from which to start the container.
83      *
84      * @param theTmpDir The directory to set
85      */

86     public final void setTmpDir(File JavaDoc theTmpDir)
87     {
88         this.tmpDir = theTmpDir;
89     }
90
91     // AbstractContainer Implementation ----------------------------------------
92

93     /**
94      * Returns the port to which the container should listen.
95      *
96      * @return The port
97      */

98     public final int getPort()
99     {
100         return this.port;
101     }
102
103     /**
104      * @see org.apache.cactus.integration.ant.container.Container#init
105      */

106     public final void init()
107     {
108         if (!this.dir.isDirectory())
109         {
110             throw new BuildException(this.dir + " is not a directory");
111         }
112     }
113
114     /**
115      * @see org.apache.cactus.integration.ant.container.Container#shutDown
116      */

117     public final void shutDown()
118     {
119         // invoke the main class
120
Java java = createJavaForShutDown();
121         Path classpath = java.createClasspath();
122         FileSet fileSet = new FileSet();
123         fileSet.setDir(this.dir);
124         fileSet.createInclude().setName("*.jar");
125         classpath.addFileset(fileSet);
126         java.setClassname("com.evermind.client.orion.OrionConsoleAdmin");
127         java.createArg().setValue("ormi://localhost:23791/");
128         java.createArg().setValue("admin");
129         java.createArg().setValue("password");
130         java.createArg().setValue("-shutdown");
131         java.execute();
132     }
133     
134     // Private Methods ---------------------------------------------------------
135

136     /**
137      * Invokes the command to start the Orion application server.
138      */

139     protected final void invokeServer()
140     {
141         // invoke the main class
142
Java java = createJavaForStartUp();
143         Path classpath = java.createClasspath();
144         FileSet fileSet = new FileSet();
145         fileSet.setDir(this.dir);
146         fileSet.createInclude().setName("*.jar");
147         classpath.addFileset(fileSet);
148         addToolsJarToClasspath(classpath);
149         java.setClassname("com.evermind.server.ApplicationServer");
150         java.createArg().setValue("-config");
151         java.createArg().setFile(new File JavaDoc(tmpDir, "conf/server.xml"));
152         java.execute();
153     }
154
155     /**
156      * Prepares a temporary installation of the container and deploys the
157      * web-application.
158      *
159      * @param theResourcePrefix The prefix to use when looking up container
160      * resource in the JAR
161      * @param theDirName The name of the temporary container installation
162      * directory
163      * @throws IOException If an I/O error occurs
164      */

165     protected final void prepare(String JavaDoc theResourcePrefix, String JavaDoc theDirName)
166         throws IOException JavaDoc
167     {
168         FileUtils fileUtils = FileUtils.newFileUtils();
169         FilterChain filterChain = createFilterChain();
170
171         this.tmpDir = setupTempDirectory(this.tmpDir, theDirName);
172         cleanTempDirectory(this.tmpDir);
173
174         // Copy configuration files into the temporary container directory
175

176         File JavaDoc confDir = createDirectory(tmpDir, "conf");
177
178         // Configuration files are not the same whether we deploy a
179
// WAR or an EAR
180
String JavaDoc sharePath = RESOURCE_PATH + theResourcePrefix + "/share";
181         String JavaDoc specificPath;
182         if (getDeployableFile().isWar())
183         {
184             specificPath = RESOURCE_PATH + theResourcePrefix + "/war";
185         }
186         else
187         {
188             specificPath = RESOURCE_PATH + theResourcePrefix + "/ear";
189         }
190
191         ResourceUtils.copyResource(getProject(),
192             specificPath + "/server.xml",
193             new File JavaDoc(confDir, "server.xml"), filterChain);
194         ResourceUtils.copyResource(getProject(),
195             specificPath + "/application.xml",
196             new File JavaDoc(confDir, "application.xml"), filterChain);
197         ResourceUtils.copyResource(getProject(),
198             specificPath + "/default-web-site.xml",
199             new File JavaDoc(confDir, "default-web-site.xml"), filterChain);
200
201         ResourceUtils.copyResource(getProject(),
202             sharePath + "/global-web-application.xml",
203             new File JavaDoc(confDir, "global-web-application.xml"), filterChain);
204         ResourceUtils.copyResource(getProject(),
205             sharePath + "/mime.types",
206             new File JavaDoc(confDir, "mime.types"), filterChain);
207         ResourceUtils.copyResource(getProject(),
208             sharePath + "/principals.xml",
209             new File JavaDoc(confDir, "principals.xml"), filterChain);
210         ResourceUtils.copyResource(getProject(),
211             sharePath + "/rmi.xml",
212             new File JavaDoc(confDir, "rmi.xml"), filterChain);
213
214         // Create default web app (required by Orion unfortunately...)
215
File JavaDoc defaultWebAppDir = createDirectory(tmpDir,
216             "default-web-app/WEB-INF");
217         ResourceUtils.copyResource(getProject(),
218             sharePath + "/web.xml",
219             new File JavaDoc(defaultWebAppDir, "web.xml"), filterChain);
220         
221         // Orion need to have a /persistence directory created, otherwise it
222
// throws an error
223
createDirectory(tmpDir, "persistence");
224
225         // Directory where modules to be deployed are located
226
File JavaDoc appDir = createDirectory(tmpDir, "applications");
227
228         // Deployment directory (i.e. where Orion expands modules)
229
createDirectory(tmpDir, "application-deployments");
230
231         // Orion log directory
232
createDirectory(tmpDir, "log");
233                
234         fileUtils.copyFile(getDeployableFile().getFile(),
235             new File JavaDoc(appDir, getDeployableFile().getFile().getName()),
236             null, true);
237     }
238
239 }
240
Popular Tags