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 InstanceTask extends IasAdmin { 32 private String action; 33 34 private static final String ACTION_START = "start"; 35 private static final String ACTION_STOP = "stop"; 36 private static final String ACTION_RESTART = "restart"; 37 private static final String ACTION_CREATE = "create"; 38 private static final String ACTION_DESTROY = "destroy"; 39 40 private static final Map ACTION_MAP = new HashMap (5); 41 static { 42 ACTION_MAP.put(ACTION_START, "start-instance"); 43 ACTION_MAP.put(ACTION_STOP, "stop-instance"); 44 ACTION_MAP.put(ACTION_RESTART, null); 45 ACTION_MAP.put(ACTION_CREATE, "create-instance"); 46 ACTION_MAP.put(ACTION_DESTROY, "delete-instance"); 47 }; 48 49 public void setAction(String action) { 50 this.action = action; 51 } 52 53 protected void checkConfiguration() throws BuildException { 54 super.checkConfiguration(); 55 56 if (action == null) { 57 String msg = "The action command must be specified."; 58 throw new BuildException(msg, getLocation()); 59 } 60 61 if (!ACTION_MAP.containsKey(action)) { 62 63 String msg = "The action command (\"" + action + "\") is invalid."; 64 throw new BuildException(msg, getLocation()); 65 } 66 } 67 68 protected void checkConfiguration(Server aServer) throws BuildException { 69 super.checkConfiguration(aServer); 70 if ((action.equals(ACTION_CREATE) || action.equals(ACTION_DESTROY)) && 71 (aServer.getInstance() == null)) { 72 String msg = "When creating or destroying an application server " 73 + "instance, the \"instance\" attribute is required."; 74 throw new BuildException(msg, getLocation()); 75 } 76 } 77 78 protected void execute(Server aServer) throws BuildException { 79 if (action.equals(ACTION_RESTART)) { 80 execute(ACTION_STOP, aServer); 81 execute(ACTION_START, aServer); 82 } else { 83 execute(action, aServer); 84 } 85 } 86 87 private void execute(String anAction, Server aServer) throws BuildException { 88 String cmdString = (String ) ACTION_MAP.get(anAction); 89 cmdString +=aServer.getCommandParameters(false); 90 if (anAction.equals(ACTION_CREATE)) { 91 cmdString += " --instanceport " + aServer.getInstanceport(); 92 } 93 if (aServer.getInstance() != null) { 94 cmdString += " " + aServer.getInstance(); 95 } 96 execIasCommand(cmdString); 97 } 98 } | Popular Tags |