KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > ant > JonasHotDeploymentTool


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer: Florent BENOIT
22  * --------------------------------------------------------------------------
23  * $Id: JonasHotDeploymentTool.java,v 1.1 2004/05/05 14:19:30 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.ant;
28
29 import org.apache.tools.ant.BuildException;
30 import org.apache.tools.ant.Project;
31 import org.apache.tools.ant.taskdefs.Java;
32
33 /**
34  * Class used to manage deployment on JOnAS (with ant and ServerDeploy task)
35  * @author Florent Benoit
36  */

37 public class JonasHotDeploymentTool extends BootstrapTask implements HotDeploymentTool {
38
39     /**
40      * Admin class (JonasAdmin class)
41      */

42     private static final String JavaDoc ADMIN_CLASS = "org.objectweb.jonas.adm.JonasAdmin";
43
44     /**
45      * The parent task
46      */

47     private ServerDeploy task;
48
49     /**
50      * All actions supported by JOnAS
51      */

52     private static final String JavaDoc[] VALID_ACTIONS = {ACTION_DELETE, ACTION_DEPLOY, ACTION_LIST, ACTION_UNDEPLOY,
53             ACTION_UPDATE};
54
55     /**
56      * Validates the passed in attributes. Subclasses should chain to this
57      * super-method to insure validation of boilerplate attributes. <p>Only the
58      * "action" attribute is required in the base class. Subclasses should check
59      * attributes accordingly.
60      * @exception org.apache.tools.ant.BuildException if the attributes are
61      * invalid or incomplete.
62      */

63     public void validateAttributes() throws BuildException {
64         if (task.getAction() == null) {
65             throw new BuildException("The \"action\" attribute must be set");
66         }
67
68         if (!isActionValid()) {
69             throw new BuildException("Invalid action \"" + task.getAction() + "\" passed");
70         }
71
72     }
73
74     /**
75      * Sets the parent task.
76      * @param task a ServerDeploy object representing the parent task.
77      * @ant.attribute ignore="true"
78      */

79     public void setTask(ServerDeploy task) {
80         this.task = task;
81     }
82
83     /**
84      * Returns the task field, a ServerDeploy object.
85      * @return An ServerDeploy representing the parent task.
86      */

87     protected ServerDeploy getTask() {
88         return task;
89     }
90
91     /**
92      * Determines if the "action" attribute defines a valid action. <p>
93      * Subclasses should determine if the action passed in is supported by the
94      * vendor's deployment tool. <p>Actions may by "deploy", "delete", etc...
95      * It all depends on the tool.
96      * @return true if the "action" attribute is valid, false if not.
97      */

98     protected boolean isActionValid() {
99
100         String JavaDoc action = getTask().getAction();
101
102         for (int i = 0; i < VALID_ACTIONS.length; i++) {
103             if (action.equals(VALID_ACTIONS[i])) {
104                 return true;
105             }
106         }
107
108         return false;
109     }
110
111     /**
112      * Perform the actual deployment. It's up to the subclasses to implement the
113      * actual behavior.
114      * @exception org.apache.tools.ant.BuildException if the attributes are
115      * invalid or incomplete.
116      */

117     public void deploy() throws BuildException {
118
119         String JavaDoc action = getTask().getAction();
120         Java bootstrapTask = getBootstraptask(ADMIN_CLASS);
121         String JavaDoc fileName = getTask().getSource().getPath();
122
123         if (action.equals(ACTION_DEPLOY) || action.equals(ACTION_UPDATE)) {
124             bootstrapTask.setTaskName("JOnAS/Deploy");
125             bootstrapTask.createArg().setValue("-a");
126             bootstrapTask.createArg().setValue(fileName);
127             bootstrapTask.log("Deploying '" + fileName + "'...", Project.MSG_INFO);
128         } else if (action.equals(ACTION_DELETE) || action.equals(ACTION_UNDEPLOY)) {
129             bootstrapTask.setTaskName("JOnAS/Undeploy");
130             bootstrapTask.createArg().setValue("-r");
131             bootstrapTask.createArg().setValue(fileName);
132             bootstrapTask.log("Undeploying '" + fileName + "'...", Project.MSG_INFO);
133         } else if (action.equals(ACTION_LIST)) {
134             bootstrapTask.setTaskName("JOnAS/List");
135             bootstrapTask.createArg().setValue("-l");
136             getTask().log("Listing beans ...", Project.MSG_INFO);
137         } else {
138             throw new BuildException("Invalid action \"" + action + "\" passed");
139         }
140
141         bootstrapTask.createArg().setValue("-n");
142         bootstrapTask.createArg().setValue(getServerName());
143         bootstrapTask.executeJava();
144     }
145
146 }
Popular Tags