1 26 27 package org.objectweb.jonas.ant; 28 29 import org.apache.tools.ant.BuildException; 30 import org.apache.tools.ant.Project; 31 import org.apache.tools.ant.taskdefs.Java; 32 33 37 public class JonasHotDeploymentTool extends BootstrapTask implements HotDeploymentTool { 38 39 42 private static final String ADMIN_CLASS = "org.objectweb.jonas.adm.JonasAdmin"; 43 44 47 private ServerDeploy task; 48 49 52 private static final String [] VALID_ACTIONS = {ACTION_DELETE, ACTION_DEPLOY, ACTION_LIST, ACTION_UNDEPLOY, 53 ACTION_UPDATE}; 54 55 63 public void validateAttributes() throws BuildException { 64 if (task.getAction() == null) { 65 throw new BuildException("The \"action\" attribute must be set"); 66 } 67 68 if (!isActionValid()) { 69 throw new BuildException("Invalid action \"" + task.getAction() + "\" passed"); 70 } 71 72 } 73 74 79 public void setTask(ServerDeploy task) { 80 this.task = task; 81 } 82 83 87 protected ServerDeploy getTask() { 88 return task; 89 } 90 91 98 protected boolean isActionValid() { 99 100 String action = getTask().getAction(); 101 102 for (int i = 0; i < VALID_ACTIONS.length; i++) { 103 if (action.equals(VALID_ACTIONS[i])) { 104 return true; 105 } 106 } 107 108 return false; 109 } 110 111 117 public void deploy() throws BuildException { 118 119 String action = getTask().getAction(); 120 Java bootstrapTask = getBootstraptask(ADMIN_CLASS); 121 String fileName = getTask().getSource().getPath(); 122 123 if (action.equals(ACTION_DEPLOY) || action.equals(ACTION_UPDATE)) { 124 bootstrapTask.setTaskName("JOnAS/Deploy"); 125 bootstrapTask.createArg().setValue("-a"); 126 bootstrapTask.createArg().setValue(fileName); 127 bootstrapTask.log("Deploying '" + fileName + "'...", Project.MSG_INFO); 128 } else if (action.equals(ACTION_DELETE) || action.equals(ACTION_UNDEPLOY)) { 129 bootstrapTask.setTaskName("JOnAS/Undeploy"); 130 bootstrapTask.createArg().setValue("-r"); 131 bootstrapTask.createArg().setValue(fileName); 132 bootstrapTask.log("Undeploying '" + fileName + "'...", Project.MSG_INFO); 133 } else if (action.equals(ACTION_LIST)) { 134 bootstrapTask.setTaskName("JOnAS/List"); 135 bootstrapTask.createArg().setValue("-l"); 136 getTask().log("Listing beans ...", Project.MSG_INFO); 137 } else { 138 throw new BuildException("Invalid action \"" + action + "\" passed"); 139 } 140 141 bootstrapTask.createArg().setValue("-n"); 142 bootstrapTask.createArg().setValue(getServerName()); 143 bootstrapTask.executeJava(); 144 } 145 146 } | Popular Tags |