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; 33 import java.util.Iterator; 34 35 import javax.enterprise.deploy.spi.status.DeploymentStatus; 36 import javax.enterprise.deploy.spi.status.ProgressObject; 37 import javax.enterprise.deploy.spi.status.ProgressEvent; 38 import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException; 39 import javax.enterprise.deploy.spi.status.ProgressListener; 40 import javax.enterprise.deploy.shared.StateType; 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 { 48 49 /** Records registered listeners */ 50 private Vector listeners = new Vector(); 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 deliveredEvents = new Vector(); 57 58 /** Records the deployment status. Normally of type DeploymentStatusWithError */ 59 private DeploymentStatus deploymentStatus = null; 60 61 /** Creates a new instance of ProgressObjectIimplWithError */ 62 public SimpleProgressObjectImpl(DeploymentStatus 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 progressListener) { 71 synchronized (listeners) { 72 listeners.add(progressListener); 73 if (deliveredEvents.size() > 0) { 74 for (Iterator i = deliveredEvents.iterator(); i.hasNext();) { 75 progressListener.handleProgressEvent((ProgressEvent)i.next()); 76 } 77 } 78 } 79 } 80 81 public void cancel() throws javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException { 82 throw new OperationUnsupportedException("cancel not supported"); 83 } 84 85 public javax.enterprise.deploy.spi.status.ClientConfiguration getClientConfiguration(javax.enterprise.deploy.spi.TargetModuleID targetModuleID) { 86 return null; 87 } 88 89 public javax.enterprise.deploy.spi.status.DeploymentStatus getDeploymentStatus() { 90 return deploymentStatus; 91 } 92 93 public javax.enterprise.deploy.spi.TargetModuleID[] getResultTargetModuleIDs() { 94 return new javax.enterprise.deploy.spi.TargetModuleID[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 progressListener) { 110 synchronized (listeners) { 111 listeners.remove(progressListener); 112 } 113 } 114 115 public void stop() throws javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException { 116 throw new OperationUnsupportedException("stop not supported"); 117 } 118 119 /** 120 * Notifies all listeners that have registered interest for ProgressEvent notification. 121 */ 122 protected void fireProgressEvent(ProgressEvent progressEvent) { 123 Vector currentListeners = null; 124 synchronized (listeners) { 125 currentListeners = (Vector) listeners.clone(); 126 deliveredEvents.add(progressEvent); 127 } 128 129 for (Iterator listenersItr = currentListeners.iterator(); listenersItr.hasNext();) { 130 ((ProgressListener)listenersItr.next()).handleProgressEvent(progressEvent); 131 } 132 currentListeners = null; 133 } 134 135 136 } 137