1 23 24 77 78 package org.apache.tools.ant.taskdefs.optional.sun.appserv; 79 80 import org.apache.tools.ant.BuildException; 81 82 import java.util.Map ; 83 import java.util.HashMap ; 84 85 113 public class ComponentTask extends ComponentAdmin { 114 private String action; 116 LocalStringsManager lsm = new LocalStringsManager(); 117 118 122 private static final String ACTION_ENABLE = "enable"; 123 private static final String ACTION_DISABLE = "disable"; 124 125 private static final Map ACTION_MAP = new HashMap (2); 126 static { 127 ACTION_MAP.put(ACTION_ENABLE, "enable"); 128 ACTION_MAP.put(ACTION_DISABLE, "disable"); 129 }; 130 131 136 public void setAction(String action) { 137 this.action = action; 138 } 139 140 protected void checkComponentConfig(Server aServer, Component comp) 141 throws BuildException { 142 super.checkComponentConfig(aServer, comp); 143 144 if (action == null) { 145 final String msg = lsm.getString("ActionCommandMustBeSpecified"); 146 throw new BuildException(msg, getLocation()); 147 } 148 149 if (!ACTION_MAP.containsKey(action)) { 150 final String msg = lsm.getString("InvalidActionCommand", new Object [] {action}); 151 throw new BuildException(msg, getLocation()); 152 } 153 154 String theName = comp.getName(); 156 if ((theName == null) || (theName.length() == 0)) { 157 final String msg = lsm.getString("InvalidComponentName", new Object [] {theName}); 158 throw new BuildException(msg, getLocation()); 159 } 160 } 161 162 protected String getCommandString(Server server, Component comp) { 163 StringBuffer cmdString = new StringBuffer (); 164 cmdString.append(ACTION_MAP.get(action)); 165 cmdString.append(server.getCommandParameters(true)); 166 if (comp.getType() != null) { 167 cmdString.append(" --type ").append(comp.getType()); 168 } 169 170 String lTarget = comp.getTarget(); 172 if ((lTarget != null) && (lTarget.length() > 0)) { 173 cmdString.append(" --target ").append(lTarget); 174 } 175 176 cmdString.append(" ").append(comp.getName()); 177 178 return cmdString.toString(); 179 } 180 } 181 | Popular Tags |