KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > sun > appserv > UndeployTask


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * The Apache Software License, Version 1.1
26  *
27  * Copyright (c) 1999 The Apache Software Foundation. All rights
28  * reserved.
29  *
30  * Redistribution and use in source and binary forms, with or without
31  * modification, are permitted provided that the following conditions
32  * are met:
33  *
34  * 1. Redistributions of source code must retain the above copyright
35  * notice, this list of conditions and the following disclaimer.
36  *
37  * 2. Redistributions in binary form must reproduce the above copyright
38  * notice, this list of conditions and the following disclaimer in
39  * the documentation and/or other materials provided with the
40  * distribution.
41  *
42  * 3. The end-user documentation included with the redistribution, if
43  * any, must include the following acknowlegement:
44  * "This product includes software developed by the
45  * Apache Software Foundation (http://www.apache.org/)."
46  * Alternately, this acknowlegement may appear in the software itself,
47  * if and wherever such third-party acknowlegements normally appear.
48  *
49  * 4. The names "The Jakarta Project", "Ant", and "Apache Software
50  * Foundation" must not be used to endorse or promote products derived
51  * from this software without prior written permission. For written
52  * permission, please contact apache@apache.org.
53  *
54  * 5. Products derived from this software may not be called "Apache"
55  * nor may "Apache" appear in their names without prior written
56  * permission of the Apache Group.
57  *
58  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
59  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
61  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
62  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
63  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
64  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
65  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
66  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
67  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
68  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69  * SUCH DAMAGE.
70  * ====================================================================
71  *
72  * This software consists of voluntary contributions made by many
73  * individuals on behalf of the Apache Software Foundation. For more
74  * information on the Apache Software Foundation, please see
75  * <http://www.apache.org/>.
76  */

77
78 package org.apache.tools.ant.taskdefs.optional.sun.appserv;
79
80 import org.apache.tools.ant.Project;
81 import org.apache.tools.ant.BuildException;
82
83 /**
84  * This task undeploys J2EE components from the Sun ONE Application Server 7.
85  * The following components may be undeployed:
86  * <ul>
87  * <li>Enterprise application
88  * <li>Web application
89  * <li>Enterprise Java Bean
90  * <li>Enterprise connector
91  * <li>Application client
92  * </ul>
93  * <p>
94  * The archive is not required to undeploy a component -- only the component
95  * name and type are required. The component archive may be used, however, as
96  * it implies the component name.
97  *
98  * @see AppServerAdmin
99  * @see ComponentAdmin
100  * @author Greg Nelson <a HREF="mailto:gn@sun.com">gn@sun.com</a>
101  */

102 public class UndeployTask extends ComponentAdmin {
103     private static final String JavaDoc UNDEPLOY_COMMAND = "undeploy";
104     LocalStringsManager lsm = new LocalStringsManager();
105     private boolean droptables; // indicates if drop tables at undeploy of an already
106
// deployed application with unmapped CMP beans.
107
private boolean droptablesIsSet = false;
108     private boolean cascade; // if true, it deletes all the connection pools and
109
// connector resources associated with the resource
110
// adapter. If false, the undeploy fails if any
111
// pools and resources are still associcated with
112
// the resource adapter.
113
private boolean cascadeIsSet = false;
114
115     protected void checkComponentConfig(Server aServer, Component comp)
116             throws BuildException {
117         super.checkComponentConfig(aServer, comp);
118
119         // name must be valid string
120
String JavaDoc theName = comp.getName();
121         if ((theName == null) || (theName.length() == 0)) {
122             final String JavaDoc msg = lsm.getString("InvalidComponentName", new Object JavaDoc [] {theName});
123             throw new BuildException(msg, getLocation());
124         }
125     }
126
127     /**
128      * Drops tables at undeploy of already deployed application with unmapped
129      * CMP beans.
130      *
131      * @param droptables
132      */

133     public void setDroptables(boolean droptables) {
134         this.droptables = droptables;
135         droptablesIsSet = true;
136     }
137
138     /**
139      * Set cascade. If true, it deletse all the connection pools and connector
140      * resources associated with the resource adapter. If false, the undeploy
141      * fails if any pools and resources are still associated with the resource
142      * adapter.
143      *
144      * @param cascade
145      */

146     public void setCascade(boolean casacde) {
147         this.cascade = cascade;
148         cascadeIsSet = true;
149     }
150
151     protected String JavaDoc getCommandString(Server server, Component comp) {
152         StringBuffer JavaDoc cmdString = new StringBuffer JavaDoc(UNDEPLOY_COMMAND);
153         cmdString.append(server.getCommandParameters(true));
154         if (comp.getType() != null) {
155             log(lsm.getString("DeprecatedTypeAttribute"), Project.MSG_WARN);
156         }
157         if (droptablesIsSet) {
158             cmdString.append(" --droptables=").append(droptables);
159             droptablesIsSet = false;
160         }
161         if (cascade) {
162             cmdString.append(" --cascade=").append(cascade);
163             cascadeIsSet = false;
164         }
165
166         // check the value and append target
167
String JavaDoc lTarget = comp.getTarget();
168         if ((lTarget != null) && (lTarget.length() > 0)) {
169                 cmdString.append(" --target ").append(lTarget);
170         }
171
172         cmdString.append(" ").append(comp.getName());
173
174         return cmdString.toString();
175     }
176 }
177
Popular Tags