KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployapi > SimpleProgressObjectImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25   * ProgressObjectIimplWithError.java
26   *
27   * Created on August 13, 2004, 9:53 AM
28   */

29
30 package com.sun.enterprise.deployapi;
31
32 import java.util.Vector JavaDoc;
33 import java.util.Iterator JavaDoc;
34
35 import javax.enterprise.deploy.spi.status.DeploymentStatus JavaDoc;
36 import javax.enterprise.deploy.spi.status.ProgressObject JavaDoc;
37 import javax.enterprise.deploy.spi.status.ProgressEvent JavaDoc;
38 import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException JavaDoc;
39 import javax.enterprise.deploy.spi.status.ProgressListener JavaDoc;
40 import javax.enterprise.deploy.shared.StateType JavaDoc;
41
42 /**
43   *Implements a progress object primarily intended to report an error during a DeploymentManager
44   *method invocation.
45   * @author tjquinn
46   */

47 public class SimpleProgressObjectImpl implements ProgressObject JavaDoc {
48     
49     /** Records registered listeners */
50     private Vector JavaDoc listeners = new Vector JavaDoc();
51
52     /**
53      *Records all events delivered so late-registering listeners will be informed of all past events
54      *as well as future ones.
55      */

56     protected Vector JavaDoc deliveredEvents = new Vector JavaDoc();
57     
58     /** Records the deployment status. Normally of type DeploymentStatusWithError */
59     private DeploymentStatus JavaDoc deploymentStatus = null;
60     
61     /** Creates a new instance of ProgressObjectIimplWithError */
62     public SimpleProgressObjectImpl(DeploymentStatus JavaDoc deploymentStatus) {
63         this.deploymentStatus = deploymentStatus;
64     }
65
66     /**
67      *Registers a listener for progress events.
68      *@param new progress listener
69      */

70     public void addProgressListener(javax.enterprise.deploy.spi.status.ProgressListener JavaDoc progressListener) {
71     synchronized (listeners) {
72             listeners.add(progressListener);
73         if (deliveredEvents.size() > 0) {
74             for (Iterator JavaDoc i = deliveredEvents.iterator(); i.hasNext();) {
75             progressListener.handleProgressEvent((ProgressEvent JavaDoc)i.next());
76             }
77         }
78     }
79     }
80     
81     public void cancel() throws javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException JavaDoc {
82         throw new OperationUnsupportedException JavaDoc("cancel not supported");
83     }
84     
85     public javax.enterprise.deploy.spi.status.ClientConfiguration JavaDoc getClientConfiguration(javax.enterprise.deploy.spi.TargetModuleID JavaDoc targetModuleID) {
86         return null;
87     }
88     
89     public javax.enterprise.deploy.spi.status.DeploymentStatus JavaDoc getDeploymentStatus() {
90         return deploymentStatus;
91     }
92     
93     public javax.enterprise.deploy.spi.TargetModuleID JavaDoc[] getResultTargetModuleIDs() {
94         return new javax.enterprise.deploy.spi.TargetModuleID JavaDoc[0];
95     }
96     
97     public boolean isCancelSupported() {
98         return false;
99     }
100     
101     public boolean isStopSupported() {
102         return false;
103     }
104
105     /**
106      *Unregister a previously-registered event listener.
107      *@param the listener to unregister
108      */

109     public void removeProgressListener(javax.enterprise.deploy.spi.status.ProgressListener JavaDoc progressListener) {
110     synchronized (listeners) {
111             listeners.remove(progressListener);
112     }
113     }
114     
115     public void stop() throws javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException JavaDoc {
116         throw new OperationUnsupportedException JavaDoc("stop not supported");
117     }
118     
119     /**
120      * Notifies all listeners that have registered interest for ProgressEvent notification.
121      */

122     protected void fireProgressEvent(ProgressEvent JavaDoc progressEvent) {
123     Vector JavaDoc currentListeners = null;
124         synchronized (listeners) {
125             currentListeners = (Vector JavaDoc) listeners.clone();
126             deliveredEvents.add(progressEvent);
127         }
128
129         for (Iterator JavaDoc listenersItr = currentListeners.iterator(); listenersItr.hasNext();) {
130             ((ProgressListener JavaDoc)listenersItr.next()).handleProgressEvent(progressEvent);
131         }
132         currentListeners = null;
133     }
134
135
136 }
137
Popular Tags