1 19 20 package org.netbeans.modules.j2ee.deployment.plugins.api; 21 22 import javax.enterprise.deploy.spi.status.ProgressObject ; 23 import javax.enterprise.deploy.spi.status.ProgressListener ; 24 import javax.enterprise.deploy.spi.status.DeploymentStatus ; 25 import javax.enterprise.deploy.spi.TargetModuleID ; 26 import javax.enterprise.deploy.spi.status.ClientConfiguration ; 27 import javax.enterprise.deploy.spi.status.ProgressEvent ; 28 import javax.enterprise.deploy.shared.ActionType ; 29 import javax.enterprise.deploy.shared.CommandType ; 30 import javax.enterprise.deploy.shared.StateType ; 31 import javax.enterprise.deploy.spi.exceptions.*; 32 33 import java.util.Iterator ; 34 35 48 49 public class ServerProgress implements ProgressObject { 50 private Object server; 51 private java.util.Vector listeners = new java.util.Vector (); 52 private DeploymentStatus status; 53 54 55 public ServerProgress(Object server) { 56 this.server = server; 57 createRunningProgressEvent(CommandType.START, ""); } 59 60 public static final Command START_SERVER = new Command(25, "START SERVER"); public static final Command STOP_SERVER = new Command(26, "STOP SERVER"); 63 public static class Command extends CommandType { 64 String commandString; 65 public Command(int val, String commandString) { 66 super(val); 67 this.commandString = commandString; 68 } 69 public String toString() { 70 return commandString; 71 } 72 } 73 74 public void setStatusStartRunning(String message) { 75 notify(createRunningProgressEvent(START_SERVER, message)); 76 } 77 public void setStatusStartFailed(String message) { 78 notify(createFailedProgressEvent(START_SERVER, message)); 79 } 80 public void setStatusStartCompleted(String message) { 81 notify(createCompletedProgressEvent(START_SERVER, message)); 82 } 83 public void setStatusStopRunning(String message) { 84 notify(createRunningProgressEvent(STOP_SERVER, message)); 85 } 86 public void setStatusStopFailed(String message) { 87 notify(createFailedProgressEvent(STOP_SERVER, message)); 88 } 89 public void setStatusStopCompleted(String message) { 90 notify(createCompletedProgressEvent(CommandType.STOP, message)); 91 } 92 protected synchronized void notify(ProgressEvent pe) { 93 for (Iterator i=listeners.iterator(); i.hasNext();) { 94 ProgressListener pol = (ProgressListener ) i.next(); 95 pol.handleProgressEvent(pe); 96 } 97 } 98 99 protected DeploymentStatus createDeploymentStatus(final CommandType comtype, final String msg, final StateType state) { 100 return new DeploymentStatus () { 101 public ActionType getAction() { return ActionType.EXECUTE; } 102 public CommandType getCommand() { return comtype; } 103 public String getMessage() { return msg; } 104 public StateType getState() { return state; } 105 106 public boolean isCompleted () { 107 return StateType.COMPLETED.equals(state); 108 } 109 110 public boolean isFailed () { 111 return StateType.FAILED.equals(state); 112 } 113 114 public boolean isRunning () { 115 return StateType.RUNNING.equals(state); 116 } 117 }; 118 } 119 protected ProgressEvent createCompletedProgressEvent(CommandType command, String message) { 120 status = createDeploymentStatus(command, message, StateType.COMPLETED); 121 return new ProgressEvent (server, null, status); 122 } 123 124 protected ProgressEvent createFailedProgressEvent(CommandType command, String message) { 125 status = createDeploymentStatus(command, message, StateType.FAILED); 126 return new ProgressEvent (server, null, status); 127 } 128 129 protected ProgressEvent createRunningProgressEvent(CommandType command, String message) { 130 status = createDeploymentStatus(command, message, StateType.RUNNING); 131 return new ProgressEvent (server, null, status); 132 } 133 public synchronized void addProgressListener(ProgressListener pol) { 135 listeners.add(pol); 136 } 137 public synchronized void removeProgressListener(ProgressListener pol) { 138 142 listeners.remove(pol); 143 } 144 145 public boolean isCancelSupported() { return true; } 146 public void cancel() throws OperationUnsupportedException { 147 } 149 public boolean isStopSupported() { return false; } 150 public void stop() throws OperationUnsupportedException { 151 } 153 public ClientConfiguration getClientConfiguration(TargetModuleID targetModuleID) { 154 return null; 155 } 156 public DeploymentStatus getDeploymentStatus() { 157 return status; 158 } 159 public TargetModuleID [] getResultTargetModuleIDs() { 160 return new TargetModuleID [0]; 161 } 162 } 163 164 | Popular Tags |