KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > j2ee > GenericHotDeploymentTool


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

18
19 package org.apache.tools.ant.taskdefs.optional.j2ee;
20
21 import org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.taskdefs.Java;
23 import org.apache.tools.ant.types.Commandline;
24
25 /**
26  * A generic tool for J2EE server hot deployment.
27  * <p>The simple implementation spawns a JVM with the supplied
28  * class name, jvm args, and arguments.
29  *
30  * @see org.apache.tools.ant.taskdefs.optional.j2ee.HotDeploymentTool
31  * @see org.apache.tools.ant.taskdefs.optional.j2ee.AbstractHotDeploymentTool
32  * @see org.apache.tools.ant.taskdefs.optional.j2ee.ServerDeploy
33  */

34 public class GenericHotDeploymentTool extends AbstractHotDeploymentTool {
35     /** A Java task used to run the deployment tool **/
36     private Java java;
37
38     /** The fully qualified class name of the deployment tool **/
39     private String JavaDoc className;
40
41     /** List of valid actions **/
42     private static final String JavaDoc[] VALID_ACTIONS = {ACTION_DEPLOY};
43
44     /**
45      * Add a nested argument element to hand to the deployment tool; optional.
46      * @return A Commandline.Argument object representing the
47      * command line argument being passed when the deployment
48      * tool is run. IE: "-user=mark", "-password=venture"...
49      */

50     public Commandline.Argument createArg() {
51         return java.createArg();
52     }
53
54     /**
55      * Add a nested argment element to hand to the JVM running the
56      * deployment tool.
57      * Creates a nested arg element.
58      * @return A Commandline.Argument object representing the
59      * JVM command line argument being passed when the deployment
60      * tool is run. IE: "-ms64m", "-mx128m"...
61      */

62     public Commandline.Argument createJvmarg() {
63         return java.createJvmarg();
64     }
65
66     /**
67      * Determines if the "action" attribute defines a valid action.
68      * <p>Subclasses should determine if the action passed in is
69      * supported by the vendor's deployment tool.
70      * For this generic implementation, the only valid action is "deploy"
71      * @return true if the "action" attribute is valid, false if not.
72      */

73     protected boolean isActionValid() {
74         return (getTask().getAction().equals(VALID_ACTIONS[0]));
75     }
76
77     /**
78      * Sets the parent task.
79      * @param task An ServerDeploy object representing the parent task.
80      * @ant.attribute ignored="true"
81      */

82     public void setTask(ServerDeploy task) {
83         super.setTask(task);
84         java = new Java(task);
85     }
86
87     /**
88      * Perform the actual deployment.
89      * For this generic implementation, a JVM is spawned using the
90      * supplied classpath, classname, JVM args, and command line arguments.
91      * @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete.
92      */

93     public void deploy() throws BuildException {
94         java.setClassname(className);
95         java.setClasspath(getClasspath());
96         java.setFork(true);
97         java.setFailonerror(true);
98         java.execute();
99     }
100
101     /**
102      * Validates the passed in attributes.
103      * Ensures the className and arguments attribute have been set.
104      * @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete.
105      */

106     public void validateAttributes() throws BuildException {
107         super.validateAttributes();
108
109         if (className == null) {
110             throw new BuildException("The classname attribute must be set");
111         }
112     }
113
114     /**
115      * The name of the class to execute to perfom
116      * deployment; required.
117      * Example: "com.foobar.tools.deploy.DeployTool"
118      * @param className The fully qualified class name of the class
119      * to perform deployment.
120      */

121     public void setClassName(String JavaDoc className) {
122         this.className = className;
123     }
124
125     /**
126      * get the java attribute.
127      * @return the java attribute.
128      */

129     public Java getJava() {
130         return java;
131     }
132
133     /**
134      * Get the classname attribute.
135      * @return the classname value.
136      */

137     public String JavaDoc getClassName() {
138         return className;
139     }
140 }
141
Popular Tags