KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > launcher > CatalinaLaunchFilter


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

16
17
18 package org.apache.catalina.launcher;
19
20
21 import java.util.ArrayList JavaDoc;
22 import org.apache.commons.launcher.LaunchCommand;
23 import org.apache.commons.launcher.LaunchFilter;
24 import org.apache.tools.ant.BuildException;
25
26
27 /**
28  * This class implements the LaunchFilter interface. This class is designed to
29  * unconditionally force the "waitforchild" attribute for certain Catalina
30  * applications to true.
31  *
32  * @author Patrick Luby
33  */

34 public class CatalinaLaunchFilter implements LaunchFilter {
35
36     //----------------------------------------------------------- Static Fields
37

38     /**
39      * The Catalina bootstrap class name.
40      */

41     private static String JavaDoc CATALINA_BOOTSTRAP_CLASS_NAME = "org.apache.catalina.startup.Bootstrap";
42
43     //----------------------------------------------------------------- Methods
44

45     /**
46      * This method allows dynamic configuration and error checking of the
47      * attributes and nested elements in a "launch" task that is launching a
48      * Catalina application. This method evaluates the nested command line
49      * arguments and, depending on which class is specified in the task's
50      * "classname" attribute, may force the application to run
51      * in the foreground by forcing the "waitforchild" attribute to "true".
52      *
53      * @param launchCommand a configured instance of the {@link LaunchCommand}
54      * class
55      * @throws BuildException if any errors occur
56      */

57     public void filter(LaunchCommand launchCommand) throws BuildException {
58
59         // Get attributes
60
String JavaDoc mainClassName = launchCommand.getClassname();
61         boolean waitForChild = launchCommand.getWaitforchild();
62         ArrayList JavaDoc argsList = launchCommand.getArgs();
63         String JavaDoc[] args = (String JavaDoc[])argsList.toArray(new String JavaDoc[argsList.size()]);
64
65         // Evaluate main class
66
if (CatalinaLaunchFilter.CATALINA_BOOTSTRAP_CLASS_NAME.equals(mainClassName)) {
67             // If "start" is not the last argument, make "waitforchild" true
68
if (args.length == 0 || !"start".equals(args[args.length - 1])) {
69                 launchCommand.setWaitforchild(true);
70                 return;
71             }
72
73             // If "start" is the last argument, make sure that all of the
74
// preceding arguments are OK for running in the background
75
for (int i = 0; i < args.length - 1; i++) {
76                 if ("-config".equals(args[i])) {
77                     // Skip next argument since it should be a file
78
if (args.length > i + 1) {
79                         i++;
80                     } else {
81                         launchCommand.setWaitforchild(true);
82                         return;
83                     }
84                 } else if ("-debug".equals(args[i])) {
85                     // Do nothing
86
} else if ("-nonaming".equals(args[i])) {
87                     // Do nothing
88
} else {
89                      launchCommand.setWaitforchild(true);
90                      return;
91                 }
92             }
93         }
94
95     }
96
97 }
98
Popular Tags