KickJava   Java API By Example, From Geeks To Geeks.

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


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.types.Path;
23
24 /**
25  * Abstract class to support vendor-specific hot deployment tools.
26  * This class will validate boilerplate attributes.
27  *
28  * Subclassing this class for a vendor specific tool involves the
29  * following.
30  * <ol><li>Implement the <code>isActionValid()<code> method to insure the
31  * action supplied as the "action" attribute of ServerDeploy is valid.
32  * <li>Implement the <code>validateAttributes()</code> method to insure
33  * all required attributes are supplied, and are in the correct format.
34  * <li>Add a <code>add&lt;TOOL&gt;</code> method to the ServerDeploy
35  * class. This method will be called when Ant encounters a
36  * <code>add&lt;TOOL&gt;</code> task nested in the
37  * <code>serverdeploy</code> task.
38  * <li>Define the <code>deploy</code> method. This method should perform
39  * whatever task it takes to hot-deploy the component. IE: spawn a JVM and
40  * run class, exec a native executable, run Java code...
41  *
42  * @see org.apache.tools.ant.taskdefs.optional.j2ee.HotDeploymentTool
43  * @see org.apache.tools.ant.taskdefs.optional.j2ee.ServerDeploy
44  */

45 public abstract class AbstractHotDeploymentTool implements HotDeploymentTool {
46     /** The parent task **/
47     private ServerDeploy task;
48
49     /** The classpath passed to the JVM on execution. **/
50     private Path classpath;
51
52     /** The username for the deployment server. **/
53     private String JavaDoc userName;
54
55     /** The password for the deployment server. **/
56     private String JavaDoc password;
57
58     /** The address of the deployment server **/
59     private String JavaDoc server;
60
61     /**
62      * Add a classpath as a nested element.
63      * @return A Path object representing the classpath to be used.
64      */

65     public Path createClasspath() {
66         if (classpath == null) {
67             classpath = new Path(task.getProject());
68         }
69         return classpath.createPath();
70     }
71
72     /**
73      * Determines if the "action" attribute defines a valid action.
74      * <p>Subclasses should determine if the action passed in is
75      * supported by the vendor's deployment tool.
76      * <p>Actions may by "deploy", "delete", etc... It all depends
77      * on the tool.
78      * @return true if the "action" attribute is valid, false if not.
79      */

80     protected abstract boolean isActionValid();
81
82     /**
83      * Validates the passed in attributes.
84      * Subclasses should chain to this super-method to insure
85      * validation of boilerplate attributes.
86      * <p>Only the "action" attribute is required in the
87      * base class. Subclasses should check attributes accordingly.
88      * @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete.
89      */

90     public void validateAttributes() throws BuildException {
91         if (task.getAction() == null) {
92             throw new BuildException("The \"action\" attribute must be set");
93         }
94
95         if (!isActionValid()) {
96             throw new BuildException("Invalid action \"" + task.getAction() + "\" passed");
97         }
98
99         if (classpath == null) {
100             throw new BuildException("The classpath attribute must be set");
101         }
102     }
103
104     /**
105      * Perform the actual deployment.
106      * It's up to the subclasses to implement the actual behavior.
107      * @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete.
108      */

109     public abstract void deploy() throws BuildException;
110
111     /**
112      * Sets the parent task.
113      * @param task a ServerDeploy object representing the parent task.
114      * @ant.attribute ignore="true"
115      */

116     public void setTask(ServerDeploy task) {
117         this.task = task;
118     }
119
120     /**
121      * Returns the task field, a ServerDeploy object.
122      * @return An ServerDeploy representing the parent task.
123      */

124     protected ServerDeploy getTask() {
125         return task;
126     }
127
128     /**
129      * gets the classpath field.
130      * @return A Path representing the "classpath" attribute.
131      */

132     public Path getClasspath() {
133         return classpath;
134     }
135
136     /**
137      * The classpath to be passed to the JVM running the tool;
138      * optional depending upon the tool.
139      * The classpath may also be supplied as a nested element.
140      * @param classpath A Path object representing the "classpath" attribute.
141      */

142     public void setClasspath(Path classpath) {
143         this.classpath = classpath;
144     }
145
146     /**
147      * Returns the userName field.
148      * @return A String representing the "userName" attribute.
149      */

150     public String JavaDoc getUserName() {
151         return userName;
152     }
153
154     /**
155      * The user with privileges to deploy applications to the server; optional.
156      * @param userName A String representing the "userName" attribute.
157      */

158     public void setUserName(String JavaDoc userName) {
159         this.userName = userName;
160     }
161
162     /**
163      * Returns the password field.
164      * @return A String representing the "password" attribute.
165      */

166     public String JavaDoc getPassword() {
167         return password;
168     }
169
170     /**
171      * The password of the user; optional.
172      * @param password A String representing the "password" attribute.
173      */

174     public void setPassword(String JavaDoc password) {
175         this.password = password;
176     }
177
178     /**
179      * Returns the server field.
180      * @return A String representing the "server" attribute.
181      */

182     public String JavaDoc getServer() {
183         return server;
184     }
185
186     /**
187      * The address or URL for the server where the component will be deployed.
188      * @param server A String representing the "server" attribute.
189      */

190     public void setServer(String JavaDoc server) {
191         this.server = server;
192     }
193 }
194
Popular Tags