KickJava   Java API By Example, From Geeks To Geeks.

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


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
21 package org.netbeans.modules.tomcat5.progress;
22
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25 import javax.enterprise.deploy.shared.StateType JavaDoc;
26 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
27 import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException JavaDoc;
28 import javax.enterprise.deploy.spi.status.ClientConfiguration JavaDoc;
29 import javax.enterprise.deploy.spi.status.DeploymentStatus JavaDoc;
30 import javax.enterprise.deploy.spi.status.ProgressEvent JavaDoc;
31 import javax.enterprise.deploy.spi.status.ProgressListener JavaDoc;
32 import javax.enterprise.deploy.spi.status.ProgressObject JavaDoc;
33
34 /**
35  * MultiProgressObjectWrapper wraps multiple progress objects into a single one.
36  *
37  * @author herolds
38  */

39 public class MultiProgressObjectWrapper implements ProgressObject JavaDoc, ProgressListener JavaDoc {
40     
41     /** Support for progress notifications. */
42     private ProgressEventSupport pes;
43     
44     private ProgressObject JavaDoc[] progObjs;
45     
46     private String JavaDoc message = ""; // NOI18N
47

48     private int completedCounter;
49     
50     private StateType JavaDoc state = StateType.RUNNING;
51     
52     /** Creates a new instance of MultipleOpsProgressObject */
53     public MultiProgressObjectWrapper(ProgressObject JavaDoc[] progObjs) {
54         if (progObjs == null) {
55             throw new NullPointerException JavaDoc("The progObjs argument must not be null."); // NOI18N
56
}
57         if (progObjs.length == 0) {
58             throw new IllegalArgumentException JavaDoc("At least one progress object must be passed."); // NOI18N
59
}
60         pes = new ProgressEventSupport(this);
61         this.progObjs = progObjs;
62         for(int i = 0; i < progObjs.length; i++) {
63             ProgressObject JavaDoc po = progObjs[i];
64             po.addProgressListener(this);
65         }
66     }
67     
68     /** JSR88 method. */
69     public ClientConfiguration JavaDoc getClientConfiguration(TargetModuleID JavaDoc targetModuleID) {
70         return null; // PENDING
71
}
72     
73     /** JSR88 method. */
74     public DeploymentStatus JavaDoc getDeploymentStatus() {
75         DeploymentStatus JavaDoc ds = progObjs[0].getDeploymentStatus();
76         // all deployment objects are supposed to be of the same action and command type
77
return new Status(ds.getAction(), ds.getCommand(), message, state);
78     }
79     
80     /** JSR88 method. */
81     public TargetModuleID JavaDoc[] getResultTargetModuleIDs() {
82         List JavaDoc returnVal = new ArrayList JavaDoc();
83         for (int i = 0; i < progObjs.length; i++) {
84             ProgressObject JavaDoc po = progObjs[i];
85             if (po.getDeploymentStatus().isCompleted()) {
86                 returnVal.add(po.getResultTargetModuleIDs()[0]);
87             }
88         }
89         return (TargetModuleID JavaDoc[])returnVal.toArray(new TargetModuleID JavaDoc[returnVal.size()]);
90     }
91     
92     /** JSR88 method. */
93     public boolean isCancelSupported() {
94         return false;
95     }
96     
97     /** JSR88 method. */
98     public void cancel()
99     throws OperationUnsupportedException JavaDoc {
100         throw new OperationUnsupportedException JavaDoc("cancel not supported in Tomcat deployment"); // NOI18N
101
}
102     
103     /** JSR88 method. */
104     public boolean isStopSupported() {
105         return false;
106     }
107     
108     /** JSR88 method. */
109     public void stop() throws OperationUnsupportedException JavaDoc {
110         throw new OperationUnsupportedException JavaDoc("stop not supported in Tomcat deployment"); // NOI18N
111
}
112     
113     /** JSR88 method. */
114     public void addProgressListener(ProgressListener JavaDoc l) {
115         pes.addProgressListener(l);
116     }
117     
118     /** JSR88 method. */
119     public void removeProgressListener(ProgressListener JavaDoc l) {
120         pes.removeProgressListener(l);
121     }
122
123     public void handleProgressEvent(ProgressEvent JavaDoc progressEvent) {
124         message = progressEvent.getDeploymentStatus().getMessage();
125         StateType JavaDoc 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