KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > ejb > WLStop


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.ejb;
19
20
21 import java.io.File JavaDoc;
22 import org.apache.tools.ant.BuildException;
23 import org.apache.tools.ant.Task;
24 import org.apache.tools.ant.taskdefs.Java;
25 import org.apache.tools.ant.types.Path;
26
27 /**
28  * Shuts down a WebLogic server.
29  * To shut down an instance you must supply both a username and
30  * a password.
31  *
32  */

33 public class WLStop extends Task {
34     /**
35      * The classpath to be used. It must contains the weblogic.Admin class.
36      */

37     private Path classpath;
38
39     /**
40      * The weblogic username to use to request the shutdown.
41      */

42     private String JavaDoc username;
43
44     /**
45      * The password to use to shutdown the weblogic server.
46      */

47     private String JavaDoc password;
48
49     /**
50      * The URL which the weblogic server is listening on.
51      */

52     private String JavaDoc serverURL;
53
54     /**
55      * The delay (in seconds) to wait before shutting down.
56      */

57     private int delay = 0;
58
59     /**
60      * The location of the BEA Home under which this server is run.
61      * WL6 only
62      */

63     private File JavaDoc beaHome = null;
64
65     /**
66      * Do the work.
67      *
68      * The work is actually done by creating a separate JVM to run the weblogic admin task
69      * This approach allows the classpath of the helper task to be set.
70      *
71      * @exception BuildException if someting goes wrong with the build
72      */

73     public void execute() throws BuildException {
74         if (username == null || password == null) {
75             throw new BuildException("weblogic username and password must both be set");
76         }
77
78         if (serverURL == null) {
79             throw new BuildException("The url of the weblogic server must be provided.");
80         }
81
82         Java weblogicAdmin = new Java(this);
83         weblogicAdmin.setFork(true);
84         weblogicAdmin.setClassname("weblogic.Admin");
85         String JavaDoc args;
86
87         if (beaHome == null) {
88             args = serverURL + " SHUTDOWN " + username + " " + password + " " + delay;
89         } else {
90             args = " -url " + serverURL
91                     + " -username " + username
92                     + " -password " + password
93                     + " SHUTDOWN " + " " + delay;
94         }
95
96         weblogicAdmin.createArg().setLine(args);
97         weblogicAdmin.setClasspath(classpath);
98         weblogicAdmin.execute();
99     }
100
101     /**
102      * The classpath to be used with the Java Virtual Machine that runs the Weblogic
103      * Shutdown command;
104      *
105      * @param path the classpath to use when executing the weblogic admin task.
106      */

107     public void setClasspath(Path path) {
108         this.classpath = path;
109     }
110
111     /**
112      * The classpath to be used with the Java Virtual Machine that runs the Weblogic
113      * Shutdown command;
114      * @return the path to be configured.
115      */

116     public Path createClasspath() {
117         if (classpath == null) {
118             classpath = new Path(getProject());
119         }
120         return classpath.createPath();
121     }
122
123     /**
124      * The username of the account which will be used to shutdown the server;
125      * required.
126      *
127      * @param s the username.
128      */

129     public void setUser(String JavaDoc s) {
130         this.username = s;
131     }
132
133     /**
134      * The password for the account specified in the
135      * user parameter; required
136      *
137      * @param s the password.
138      */

139     public void setPassword(String JavaDoc s) {
140         this.password = s;
141     }
142
143     /**
144      * Set the URL to which the weblogic server is listening
145      * for T3 connections; required.
146      *
147      * @param s the url.
148      */

149     public void setUrl(String JavaDoc s) {
150         this.serverURL = s;
151     }
152
153
154     /**
155      * Set the delay (in seconds) before shutting down the server;
156      * optional.
157      *
158      * @param s the selay.
159      */

160     public void setDelay(String JavaDoc s) {
161         delay = Integer.parseInt(s);
162     }
163
164     /**
165      * The location of the BEA Home; implicitly
166      * selects Weblogic 6.0 shutdown; optional.
167      *
168      * @param beaHome the BEA Home directory.
169      *
170      */

171     public void setBEAHome(File JavaDoc beaHome) {
172         this.beaHome = beaHome;
173     }
174
175 }
176
Popular Tags