KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.tools.ant.taskdefs.optional.j2ee;
19
20 import java.io.File JavaDoc;
21 import org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.taskdefs.Java;
23 import org.apache.tools.ant.types.Path;
24
25 /**
26  * An Ant wrapper task for the weblogic.deploy tool. This is used
27  * to hot-deploy J2EE applications to a running WebLogic server.
28  * This is <b>not</b> the same as creating the application
29  * archive. This task assumes the archive (EAR, JAR, or WAR) file
30  * has been assembled and is supplied as the "source" attribute.
31  * <p>
32  *
33  * In the end, this task assembles the commadline parameters and
34  * runs the weblogic.deploy tool in a seperate JVM.
35  *
36  *@see org.apache.tools.ant.taskdefs.optional.j2ee.HotDeploymentTool
37  *@see org.apache.tools.ant.taskdefs.optional.j2ee.AbstractHotDeploymentTool
38  *@see org.apache.tools.ant.taskdefs.optional.j2ee.ServerDeploy
39  */

40 public class JonasHotDeploymentTool extends GenericHotDeploymentTool implements HotDeploymentTool {
41
42     /**
43      * Description of the Field
44      */

45     protected static final String JavaDoc DEFAULT_ORB = "RMI";
46
47     /**
48      * The classname of the tool to run *
49      */

50     private static final String JavaDoc JONAS_DEPLOY_CLASS_NAME = "org.objectweb.jonas.adm.JonasAdmin";
51
52     /**
53      * All the valid actions that weblogic.deploy permits *
54      */

55     private static final String JavaDoc[] VALID_ACTIONS
56         = {ACTION_DELETE, ACTION_DEPLOY, ACTION_LIST, ACTION_UNDEPLOY, ACTION_UPDATE};
57
58     /**
59      * Description of the Field
60      */

61     private File JavaDoc jonasroot;
62
63     /**
64      * Description of the Field
65      */

66     private String JavaDoc orb = null;
67
68     /**
69      * Description of the Field
70      */

71     private String JavaDoc davidHost;
72
73     /**
74      * Description of the Field
75      */

76     private int davidPort;
77
78
79     /**
80      * Set the host for the David ORB; required if
81      * ORB==david.
82      *
83      *@param inValue The new davidhost value
84      */

85     public void setDavidhost(final String JavaDoc inValue) {
86         davidHost = inValue;
87     }
88
89
90     /**
91      * Set the port for the David ORB; required if
92      * ORB==david.
93      *
94      *@param inValue The new davidport value
95      */

96     public void setDavidport(final int inValue) {
97         davidPort = inValue;
98     }
99
100
101     /**
102      * set the jonas root directory (-Dinstall.root=). This
103      * element is required.
104      *
105      *@param inValue The new jonasroot value
106      */

107     public void setJonasroot(final File JavaDoc inValue) {
108         jonasroot = inValue;
109     }
110
111
112     /**
113      *
114      * Choose your ORB : RMI, JEREMIE, DAVID, ...; optional.
115      * If omitted, it defaults
116      * to the one present in classpath. The corresponding JOnAS JAR is
117      * automatically added to the classpath. If your orb is DAVID (RMI/IIOP) you must
118      * specify davidhost and davidport properties.
119      *
120      *@param inValue RMI, JEREMIE, DAVID,...
121      */

122     public void setOrb(final String JavaDoc inValue) {
123         orb = inValue;
124     }
125
126
127     /**
128      * gets the classpath field.
129      *
130      *@return A Path representing the "classpath" attribute.
131      */

132     public Path getClasspath() {
133
134         Path aClassPath = super.getClasspath();
135
136         if (aClassPath == null) {
137             aClassPath = new Path(getTask().getProject());
138         }
139         if (orb != null) {
140             String JavaDoc aOrbJar = new File JavaDoc(jonasroot, "lib/" + orb + "_jonas.jar").toString();
141             String JavaDoc aConfigDir = new File JavaDoc(jonasroot, "config/").toString();
142             Path aJOnASOrbPath = new Path(aClassPath.getProject(),
143                     aOrbJar + File.pathSeparator + aConfigDir);
144             aClassPath.append(aJOnASOrbPath);
145         }
146         return aClassPath;
147     }
148
149
150     /**
151      * Validates the passed in attributes. <p>
152      *
153      * The rules are:
154      * <ol>
155      * <li> If action is "deploy" or "update" the "application"
156      * and "source" attributes must be supplied.
157      * <li> If action is "delete" or "undeploy" the
158      * "application" attribute must be supplied.
159      *
160      *@exception BuildException Description
161      * of Exception
162      */

163     public void validateAttributes() throws BuildException {
164         // super.validateAttributes(); // don't want to call this method
165

166         Java java = getJava();
167
168         String JavaDoc action = getTask().getAction();
169         if (action == null) {
170             throw new BuildException("The \"action\" attribute must be set");
171         }
172
173         if (!isActionValid()) {
174             throw new BuildException("Invalid action \"" + action + "\" passed");
175         }
176
177         if (getClassName() == null) {
178             setClassName(JONAS_DEPLOY_CLASS_NAME);
179         }
180
181         if (jonasroot == null || jonasroot.isDirectory()) {
182             java.createJvmarg().setValue("-Dinstall.root=" + jonasroot);
183             java.createJvmarg().setValue("-Djava.security.policy=" + jonasroot
184                 + "/config/java.policy");
185
186             if ("DAVID".equals(orb)) {
187                 java.createJvmarg().setValue("-Dorg.omg.CORBA.ORBClass"
188                     + "=org.objectweb.david.libs.binding.orbs.iiop.IIOPORB");
189                 java.createJvmarg().setValue("-Dorg.omg.CORBA.ORBSingletonClass="
190                     + "org.objectweb.david.libs.binding.orbs.ORBSingletonClass");
191                 java.createJvmarg().setValue("-Djavax.rmi.CORBA.StubClass="
192                     + "org.objectweb.david.libs.stub_factories.rmi.StubDelegate");
193                 java.createJvmarg().setValue("-Djavax.rmi.CORBA.PortableRemoteObjectClass="
194                     + "org.objectweb.david.libs.binding.rmi.ORBPortableRemoteObjectDelegate");
195                 java.createJvmarg().setValue("-Djavax.rmi.CORBA.UtilClass="
196                     + "org.objectweb.david.libs.helpers.RMIUtilDelegate");
197                 java.createJvmarg().setValue("-Ddavid.CosNaming.default_method=0");
198                 java.createJvmarg().setValue("-Ddavid.rmi.ValueHandlerClass="
199                     + "com.sun.corba.se.internal.io.ValueHandlerImpl");
200                 if (davidHost != null) {
201                     java.createJvmarg().setValue("-Ddavid.CosNaming.default_host="
202                         + davidHost);
203                 }
204                 if (davidPort != 0) {
205                     java.createJvmarg().setValue("-Ddavid.CosNaming.default_port="
206                         + davidPort);
207                 }
208             }
209         }
210
211         if (getServer() != null) {
212             java.createArg().setLine("-n " + getServer());
213         }
214
215         if (action.equals(ACTION_DEPLOY)
216             || action.equals(ACTION_UPDATE)
217             || action.equals("redeploy")) {
218             java.createArg().setLine("-a " + getTask().getSource());
219         } else if (action.equals(ACTION_DELETE) || action.equals(ACTION_UNDEPLOY)) {
220             java.createArg().setLine("-r " + getTask().getSource());
221         } else if (action.equals(ACTION_LIST)) {
222             java.createArg().setValue("-l");
223         }
224     }
225
226
227     /**
228      * Determines if the action supplied is valid. <p>
229      *
230      * Valid actions are contained in the static array
231      * VALID_ACTIONS
232      *
233      *@return true if the action attribute is valid, false if
234      * not.
235      */

236     protected boolean isActionValid() {
237         boolean valid = false;
238
239         String JavaDoc action = getTask().getAction();
240
241         for (int i = 0; i < VALID_ACTIONS.length; i++) {
242             if (action.equals(VALID_ACTIONS[i])) {
243                 valid = true;
244                 break;
245             }
246         }
247
248         return valid;
249     }
250 }
251
252
Popular Tags