KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > iplanet > ComponentTask


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 package org.apache.tools.ant.taskdefs.optional.iplanet;
25
26 import org.apache.tools.ant.BuildException;
27
28 import java.util.Map JavaDoc;
29 import java.util.HashMap JavaDoc;
30
31 public class ComponentTask extends ComponentAdmin {
32     private String JavaDoc action;
33
34     private static final String JavaDoc ACTION_ENABLE = "enable";
35     private static final String JavaDoc ACTION_DISABLE = "disable";
36
37     private static final Map JavaDoc ACTION_MAP = new HashMap JavaDoc(2);
38     static {
39         ACTION_MAP.put(ACTION_ENABLE, "enable");
40         ACTION_MAP.put(ACTION_DISABLE, "disable");
41     };
42
43     public void setAction(String JavaDoc action) {
44         this.action = action;
45     }
46
47     protected void checkComponentConfig(Component comp) throws BuildException {
48         super.checkComponentConfig(comp);
49
50         if (action == null) {
51             String JavaDoc msg = "The action command must be specified.";
52             throw new BuildException(msg, getLocation());
53         }
54
55         if (!ACTION_MAP.containsKey(action)) {
56
57             String JavaDoc msg = "The action command (\"" + action + "\") is invalid.";
58             throw new BuildException(msg, getLocation());
59         }
60
61         // name must be valid string
62
String JavaDoc theName = comp.getName();
63         if ((theName == null) || (theName.length() == 0)) {
64             String JavaDoc msg = "The component name (\"" + theName + "\") is not valid";
65             throw new BuildException(msg, getLocation());
66         }
67     }
68
69     protected String JavaDoc getCommandString(Server server, Component comp) {
70         StringBuffer JavaDoc cmdString = new StringBuffer JavaDoc();
71         cmdString.append(ACTION_MAP.get(action));
72         cmdString.append(server.getCommandParameters(true));
73         if (comp.getType() != null) {
74             cmdString.append(" --type ").append(comp.getType());
75         }
76         cmdString.append(" ").append(comp.getName());
77
78         return cmdString.toString();
79     }
80 }
Popular Tags