source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/AbstractHotDeploymentTool.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 6.4 KB
Line 
1/*
2 * Copyright 2002-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
18package org.apache.tools.ant.taskdefs.optional.j2ee;
19
20import org.apache.tools.ant.BuildException;
21import org.apache.tools.ant.types.Path;
22
23/**
24 * Abstract class to support vendor-specific hot deployment tools.
25 * This class will validate boilerplate attributes.
26 *
27 * Subclassing this class for a vendor specific tool involves the
28 * following.
29 * <ol><li>Implement the <code>isActionValid()<code> method to insure the
30 * action supplied as the "action" attribute of ServerDeploy is valid.
31 * <li>Implement the <code>validateAttributes()</code> method to insure
32 * all required attributes are supplied, and are in the correct format.
33 * <li>Add a <code>add&lt;TOOL&gt;</code> method to the ServerDeploy
34 * class. This method will be called when Ant encounters a
35 * <code>add&lt;TOOL&gt;</code> task nested in the
36 * <code>serverdeploy</code> task.
37 * <li>Define the <code>deploy</code> method. This method should perform
38 * whatever task it takes to hot-deploy the component. IE: spawn a JVM and
39 * run class, exec a native executable, run Java code...
40 *
41 *
42 * @see org.apache.tools.ant.taskdefs.optional.j2ee.HotDeploymentTool
43 * @see org.apache.tools.ant.taskdefs.optional.j2ee.ServerDeploy
44 */
45public 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 userName;
54
55 /** The password for the deployment server. **/
56 private String password;
57
58 /** The address of the deployment server **/
59 private String 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 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 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 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 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 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 server) {
191 this.server = server;
192 }
193}
Note: See TracBrowser for help on using the repository browser.