1 19 20 package org.netbeans.modules.j2ee.sun.ws7.util; 21 22 import java.util.Vector ; 23 24 import javax.enterprise.deploy.spi.TargetModuleID ; 25 import javax.enterprise.deploy.spi.status.DeploymentStatus ; 26 import javax.enterprise.deploy.spi.status.ProgressEvent ; 27 import javax.enterprise.deploy.spi.status.ProgressListener ; 28 29 import org.openide.ErrorManager; 30 import org.openide.util.RequestProcessor; 31 41 public class ProgressEventSupport { 42 43 44 private Object obj; 45 46 private Vector listeners; 47 48 private DeploymentStatus status; 49 50 private TargetModuleID tmID; 51 52 57 public ProgressEventSupport(Object o) { 58 if (o == null) { 59 throw new NullPointerException (); 60 } 61 62 obj = o; 63 } 64 65 66 public synchronized void addProgressListener(ProgressListener lsnr) { 67 boolean notify = false; 68 69 if (listeners == null) { 70 listeners = new Vector (); 71 } 72 73 listeners.addElement(lsnr); 74 75 if (status != null && !status.isRunning()) { 76 notify = true; 77 } 78 79 if (notify) { 80 RequestProcessor.getDefault().post(new Runnable () { 82 public void run() { 83 fireHandleProgressEvent(tmID, status); 84 } 85 }); 86 } 87 } 88 89 90 public synchronized void removeProgressListener(ProgressListener lsnr) { 91 if (listeners == null) { 92 return; 93 } 94 95 listeners.removeElement(lsnr); 96 } 97 98 99 public void fireHandleProgressEvent(TargetModuleID targetModuleID, 100 DeploymentStatus sCode) { 101 ErrorManager err = ErrorManager.getDefault().getInstance("org.netbeans.modules.j2ee.sun.ws7"); 102 if (err.isLoggable(ErrorManager.INFORMATIONAL)) { 103 err.log("progress event from " + obj + 105 " status " + sCode); 107 } 108 109 ProgressEvent evt = new ProgressEvent (obj, targetModuleID, sCode); 110 status = sCode; 111 tmID = targetModuleID; 112 113 Vector targets = null; 114 synchronized (this) { 115 if (listeners != null) { 116 targets = (Vector )listeners.clone(); 117 } 118 } 119 120 if (targets != null) { 121 for (int i = 0; i < targets.size(); i++) { 122 ProgressListener target = (ProgressListener )targets.elementAt(i); 123 target.handleProgressEvent (evt); 124 } 125 } 126 } 127 128 130 public DeploymentStatus getDeploymentStatus() { 131 return status; 132 } 133 } 134 | Popular Tags |