1 23 24 package org.apache.tools.ant.taskdefs.optional.iplanet; 25 26 import org.apache.tools.ant.BuildException; 27 28 import java.util.Map ; 29 import java.util.HashMap ; 30 31 public class ComponentTask extends ComponentAdmin { 32 private String action; 33 34 private static final String ACTION_ENABLE = "enable"; 35 private static final String ACTION_DISABLE = "disable"; 36 37 private static final Map ACTION_MAP = new HashMap (2); 38 static { 39 ACTION_MAP.put(ACTION_ENABLE, "enable"); 40 ACTION_MAP.put(ACTION_DISABLE, "disable"); 41 }; 42 43 public void setAction(String 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 msg = "The action command must be specified."; 52 throw new BuildException(msg, getLocation()); 53 } 54 55 if (!ACTION_MAP.containsKey(action)) { 56 57 String msg = "The action command (\"" + action + "\") is invalid."; 58 throw new BuildException(msg, getLocation()); 59 } 60 61 String theName = comp.getName(); 63 if ((theName == null) || (theName.length() == 0)) { 64 String msg = "The component name (\"" + theName + "\") is not valid"; 65 throw new BuildException(msg, getLocation()); 66 } 67 } 68 69 protected String getCommandString(Server server, Component comp) { 70 StringBuffer cmdString = new StringBuffer (); 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 |