001: /**
002: * Copyright 2002-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: *
016: */package org.objectweb.jonas.ant;
017:
018: import java.io.File;
019: import java.util.Enumeration;
020: import java.util.Vector;
021: import org.apache.tools.ant.BuildException;
022: import org.apache.tools.ant.Task;
023: import org.apache.tools.ant.taskdefs.optional.j2ee.GenericHotDeploymentTool;
024: import org.apache.tools.ant.taskdefs.optional.j2ee.WebLogicHotDeploymentTool;
025:
026: /**
027: * Controls hot deployment tools for J2EE servers. This class is used as a
028: * framework for the creation of vendor specific hot deployment tools.
029: * @see org.apache.tools.ant.taskdefs.optional.j2ee.HotDeploymentTool
030: * @see org.apache.tools.ant.taskdefs.optional.j2ee.AbstractHotDeploymentTool
031: * @see org.apache.tools.ant.taskdefs.optional.j2ee.GenericHotDeploymentTool
032: * @see org.apache.tools.ant.taskdefs.optional.j2ee.WebLogicHotDeploymentTool
033: */
034: public class ServerDeploy extends Task {
035:
036: /**
037: * The action to be performed. IE: "deploy", "delete", etc...
038: */
039: private String action;
040:
041: /**
042: * The source (fully-qualified path) to the component being deployed
043: */
044: private File source;
045:
046: /**
047: * The vendor specific tool for deploying the component
048: */
049: private Vector vendorTools = new Vector();
050:
051: ///////////////////////////////////////////////////////////////////////////
052: //
053: // Place vendor specific tool creations here.
054: //
055: ///////////////////////////////////////////////////////////////////////////
056:
057: /**
058: * Creates a generic deployment tool. <p>Ant calls this method on creation
059: * to handle embedded "generic" elements in the ServerDeploy task.
060: * @param tool An instance of GenericHotDeployment tool, passed in by Ant.
061: */
062: public void addGeneric(GenericHotDeploymentTool tool) {
063: }
064:
065: /**
066: * Creates a WebLogic deployment tool, for deployment to WebLogic servers.
067: * <p>Ant calls this method on creation to handle embedded "weblogic"
068: * elements in the ServerDeploy task.
069: * @param tool An instance of WebLogicHotDeployment tool, passed in by Ant.
070: */
071: public void addWeblogic(WebLogicHotDeploymentTool tool) {
072: }
073:
074: /**
075: * Creates a JOnAS deployment tool, for deployment to JOnAS servers. <p>Ant
076: * calls this method on creation to handle embedded "jonas" elements in the
077: * ServerDeploy task.
078: * @param tool An instance of JonasHotDeployment tool, passed in by Ant.
079: */
080: public void addJonas(JonasHotDeploymentTool tool) {
081: tool.setTask(this );
082: vendorTools.addElement(tool);
083: }
084:
085: ///////////////////////////////////////////////////////////////////////////
086: //
087: // Execute method
088: //
089: ///////////////////////////////////////////////////////////////////////////
090:
091: /**
092: * Execute the task. <p>This method calls the deploy() method on each of
093: * the vendor-specific tools in the <code>vendorTools</code> collection.
094: * This performs the actual process of deployment on each tool.
095: * @exception org.apache.tools.ant.BuildException if the attributes are
096: * invalid or incomplete, or a failure occurs in the deployment
097: * process.
098: */
099: public void execute() throws BuildException {
100: for (Enumeration e = vendorTools.elements(); e
101: .hasMoreElements();) {
102: HotDeploymentTool tool = (HotDeploymentTool) e
103: .nextElement();
104: tool.validateAttributes();
105: tool.deploy();
106: }
107: }
108:
109: ///////////////////////////////////////////////////////////////////////////
110: //
111: // Set/get methods
112: //
113: ///////////////////////////////////////////////////////////////////////////
114:
115: /**
116: * Returns the action field.
117: * @return A string representing the "action" attribute.
118: */
119: public String getAction() {
120: return action;
121: }
122:
123: /**
124: * The action to be performed, usually "deploy"; required. Some tools
125: * support additional actions, such as "delete", "list", "undeploy",
126: * "update"...
127: * @param action A String representing the "action" attribute.
128: */
129: public void setAction(String action) {
130: this .action = action;
131: }
132:
133: /**
134: * Returns the source field (the path/filename of the component to be
135: * deployed.
136: * @return A File object representing the "source" attribute.
137: */
138: public File getSource() {
139: return source;
140: }
141:
142: /**
143: * The filename of the component to be deployed; optional depending upon the
144: * tool and the action.
145: * @param source String representing the "source" attribute.
146: */
147: public void setSource(File source) {
148: this.source = source;
149: }
150: }
|