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. package org.apache.tools.ant.taskdefs.optional.j2ee;
  18. import java.io.File;
  19. import java.util.Enumeration;
  20. import java.util.Vector;
  21. import org.apache.tools.ant.BuildException;
  22. import org.apache.tools.ant.Task;
  23. /**
  24. * Controls hot deployment tools for J2EE servers.
  25. *
  26. * This class is used as a framework for the creation of vendor specific
  27. * hot deployment tools.
  28. *
  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.GenericHotDeploymentTool
  33. * @see org.apache.tools.ant.taskdefs.optional.j2ee.WebLogicHotDeploymentTool
  34. */
  35. public class ServerDeploy extends Task {
  36. /** The action to be performed. IE: "deploy", "delete", etc... **/
  37. private String action;
  38. /** The source (fully-qualified path) to the component being deployed **/
  39. private File source;
  40. /** The vendor specific tool for deploying the component **/
  41. private Vector vendorTools = new Vector();
  42. ///////////////////////////////////////////////////////////////////////////
  43. //
  44. // Place vendor specific tool creations here.
  45. //
  46. ///////////////////////////////////////////////////////////////////////////
  47. /**
  48. * Creates a generic deployment tool.
  49. * <p>Ant calls this method on creation to handle embedded "generic" elements
  50. * in the ServerDeploy task.
  51. * @param tool An instance of GenericHotDeployment tool, passed in by Ant.
  52. */
  53. public void addGeneric(GenericHotDeploymentTool tool) {
  54. tool.setTask(this);
  55. vendorTools.addElement(tool);
  56. }
  57. /**
  58. * Creates a WebLogic deployment tool, for deployment to WebLogic servers.
  59. * <p>Ant calls this method on creation to handle embedded "weblogic" elements
  60. * in the ServerDeploy task.
  61. * @param tool An instance of WebLogicHotDeployment tool, passed in by Ant.
  62. */
  63. public void addWeblogic(WebLogicHotDeploymentTool tool) {
  64. tool.setTask(this);
  65. vendorTools.addElement(tool);
  66. }
  67. /**
  68. * Creates a JOnAS deployment tool, for deployment to JOnAS servers.
  69. * <p>Ant calls this method on creation to handle embedded "jonas" elements
  70. * in the ServerDeploy task.
  71. * @param tool An instance of JonasHotDeployment tool, passed in by Ant.
  72. */
  73. public void addJonas(JonasHotDeploymentTool tool) {
  74. tool.setTask(this);
  75. vendorTools.addElement(tool);
  76. }
  77. ///////////////////////////////////////////////////////////////////////////
  78. //
  79. // Execute method
  80. //
  81. ///////////////////////////////////////////////////////////////////////////
  82. /**
  83. * Execute the task.
  84. * <p>This method calls the deploy() method on each of the vendor-specific tools
  85. * in the <code>vendorTools</code> collection. This performs the actual
  86. * process of deployment on each tool.
  87. * @exception org.apache.tools.ant.BuildException if the attributes
  88. * are invalid or incomplete, or a failure occurs in the deployment process.
  89. */
  90. public void execute() throws BuildException {
  91. for (Enumeration e = vendorTools.elements();
  92. e.hasMoreElements();) {
  93. HotDeploymentTool tool = (HotDeploymentTool) e.nextElement();
  94. tool.validateAttributes();
  95. tool.deploy();
  96. }
  97. }
  98. ///////////////////////////////////////////////////////////////////////////
  99. //
  100. // Set/get methods
  101. //
  102. ///////////////////////////////////////////////////////////////////////////
  103. /**
  104. * Returns the action field.
  105. * @return A string representing the "action" attribute.
  106. */
  107. public String getAction() {
  108. return action;
  109. }
  110. /**
  111. * The action to be performed, usually "deploy"; required.
  112. * Some tools support additional actions, such as "delete", "list", "undeploy", "update"...
  113. * @param action A String representing the "action" attribute.
  114. */
  115. public void setAction(String action) {
  116. this.action = action;
  117. }
  118. /**
  119. * Returns the source field (the path/filename of the component to be
  120. * deployed.
  121. * @return A File object representing the "source" attribute.
  122. */
  123. public File getSource() {
  124. return source;
  125. }
  126. /**
  127. * The filename of the component to be deployed; optional
  128. * depending upon the tool and the action.
  129. * @param source String representing the "source" attribute.
  130. */
  131. public void setSource(File source) {
  132. this.source = source;
  133. }
  134. }