1 19 20 21 package org.netbeans.modules.tomcat5.progress; 22 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import javax.enterprise.deploy.shared.StateType ; 26 import javax.enterprise.deploy.spi.TargetModuleID ; 27 import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException ; 28 import javax.enterprise.deploy.spi.status.ClientConfiguration ; 29 import javax.enterprise.deploy.spi.status.DeploymentStatus ; 30 import javax.enterprise.deploy.spi.status.ProgressEvent ; 31 import javax.enterprise.deploy.spi.status.ProgressListener ; 32 import javax.enterprise.deploy.spi.status.ProgressObject ; 33 34 39 public class MultiProgressObjectWrapper implements ProgressObject , ProgressListener { 40 41 42 private ProgressEventSupport pes; 43 44 private ProgressObject [] progObjs; 45 46 private String message = ""; 48 private int completedCounter; 49 50 private StateType state = StateType.RUNNING; 51 52 53 public MultiProgressObjectWrapper(ProgressObject [] progObjs) { 54 if (progObjs == null) { 55 throw new NullPointerException ("The progObjs argument must not be null."); } 57 if (progObjs.length == 0) { 58 throw new IllegalArgumentException ("At least one progress object must be passed."); } 60 pes = new ProgressEventSupport(this); 61 this.progObjs = progObjs; 62 for(int i = 0; i < progObjs.length; i++) { 63 ProgressObject po = progObjs[i]; 64 po.addProgressListener(this); 65 } 66 } 67 68 69 public ClientConfiguration getClientConfiguration(TargetModuleID targetModuleID) { 70 return null; } 72 73 74 public DeploymentStatus getDeploymentStatus() { 75 DeploymentStatus ds = progObjs[0].getDeploymentStatus(); 76 return new Status(ds.getAction(), ds.getCommand(), message, state); 78 } 79 80 81 public TargetModuleID [] getResultTargetModuleIDs() { 82 List returnVal = new ArrayList (); 83 for (int i = 0; i < progObjs.length; i++) { 84 ProgressObject po = progObjs[i]; 85 if (po.getDeploymentStatus().isCompleted()) { 86 returnVal.add(po.getResultTargetModuleIDs()[0]); 87 } 88 } 89 return (TargetModuleID [])returnVal.toArray(new TargetModuleID [returnVal.size()]); 90 } 91 92 93 public boolean isCancelSupported() { 94 return false; 95 } 96 97 98 public void cancel() 99 throws OperationUnsupportedException { 100 throw new OperationUnsupportedException ("cancel not supported in Tomcat deployment"); } 102 103 104 public boolean isStopSupported() { 105 return false; 106 } 107 108 109 public void stop() throws OperationUnsupportedException { 110 throw new OperationUnsupportedException ("stop not supported in Tomcat deployment"); } 112 113 114 public void addProgressListener(ProgressListener l) { 115 pes.addProgressListener(l); 116 } 117 118 119 public void removeProgressListener(ProgressListener l) { 120 pes.removeProgressListener(l); 121 } 122 123 public void handleProgressEvent(ProgressEvent progressEvent) { 124 message = progressEvent.getDeploymentStatus().getMessage(); 125 StateType stateType = progressEvent.getDeploymentStatus().getState(); 126 if (stateType == StateType.FAILED) { 127 state = StateType.FAILED; 128 } else if (stateType == StateType.RELEASED) { 129 state = StateType.RELEASED; 130 } else if (stateType == StateType.COMPLETED) { 131 if (++completedCounter == progObjs.length) { 132 state = StateType.COMPLETED; 133 } 134 } 135 pes.fireHandleProgressEvent(progressEvent.getTargetModuleID(), progressEvent.getDeploymentStatus()); 136 } 137 } 138 | Popular Tags |