KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tomcat5 > progress > ProgressEventSupport


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tomcat5.progress;
21
22 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
23 import javax.enterprise.deploy.spi.status.DeploymentStatus JavaDoc;
24 import javax.enterprise.deploy.spi.status.ProgressEvent JavaDoc;
25 import javax.enterprise.deploy.spi.status.ProgressListener JavaDoc;
26 import org.netbeans.modules.tomcat5.TomcatFactory;
27 import org.openide.ErrorManager;
28
29 /**
30  * This is a utility class that can be used by ProgressObject's,
31  * You can use an instance of this class as a member field
32  * of your ProgressObject and delegate various work to it.
33  *
34  * @author Radim Kubacki
35  */

36 public class ProgressEventSupport {
37
38     /** Source object. */
39     private Object JavaDoc obj;
40     
41     private java.util.Vector JavaDoc listeners;
42     
43     private DeploymentStatus JavaDoc status;
44     
45     /**
46      * Constructs a <code>ProgressEventSupport</code> object.
47      *
48      * @param o Source for any events.
49      */

50     public ProgressEventSupport (Object JavaDoc o) {
51         if (o == null) {
52             throw new NullPointerException JavaDoc ();
53         }
54         obj = o;
55     }
56     
57     /** Add a ProgressListener to the listener list. */
58     public synchronized void addProgressListener (ProgressListener JavaDoc lsnr) {
59         if (listeners == null) {
60             listeners = new java.util.Vector JavaDoc();
61         }
62         listeners.addElement(lsnr);
63     }
64     
65     /** Remove a ProgressListener from the listener list. */
66     public synchronized void removeProgressListener (ProgressListener JavaDoc lsnr) {
67         if (listeners == null) {
68             return;
69         }
70         listeners.removeElement(lsnr);
71     }
72
73     /** Report event to any registered listeners. */
74     public void fireHandleProgressEvent (TargetModuleID JavaDoc targetModuleID, DeploymentStatus JavaDoc sCode) {
75         if (TomcatFactory.getEM ().isLoggable (ErrorManager.INFORMATIONAL)) {
76             TomcatFactory.getEM ().log ("progress event from "+obj+" status "+sCode); // NOI18N
77
}
78         synchronized (this) {
79             status = sCode;
80         }
81         ProgressEvent JavaDoc evt = new ProgressEvent JavaDoc (obj, targetModuleID, sCode);
82     java.util.Vector JavaDoc targets = null;
83     synchronized (this) {
84         if (listeners != null) {
85             targets = (java.util.Vector JavaDoc) listeners.clone();
86         }
87     }
88
89     if (targets != null) {
90         for (int i = 0; i < targets.size(); i++) {
91             ProgressListener JavaDoc target = (ProgressListener JavaDoc)targets.elementAt(i);
92             target.handleProgressEvent (evt);
93         }
94     }
95     }
96     
97     /** Returns last DeploymentStatus notified by {@link fireHandleProgressEvent}
98      */

99     public synchronized DeploymentStatus JavaDoc getDeploymentStatus () {
100         return status;
101     }
102 }
103
Popular Tags