001    /*
002    
003      $Id: ResponseCollection.java,v 1.5 2003/04/30 20:49:17 culdesac Exp $
004    
005    */
006    
007    package sharpster.common;
008    
009    import java.util.LinkedList;
010    import sharpster.common.Response;
011    import java.io.Serializable;
012    
013    /**
014     * A general collection of responses which is used by modules in the local
015     * client and in the daemon. A ResponseCollection can contain serveral
016     * Response objects of different types.
017     */
018    public class ResponseCollection implements Serializable {
019    
020        /**
021         * Contains the response objects.
022         */
023        private LinkedList responses;
024    
025        /**
026         * The number of response objects in the collection.
027         */
028        private boolean error;
029    
030        /**
031         * Constructor
032         */
033        public ResponseCollection() {
034            error = false;
035            responses = new LinkedList();
036        }
037    
038        /**
039         * Returns true if this response colletion contains
040         * responses that has error.
041         */
042        public boolean hasError() {
043            return error;
044        }
045    
046        /**
047         * Returns the number of Response objects in the collection.
048         */
049        public int getResponseCount() {
050            return responses.size();
051        }
052       
053        /**
054         * Adds a new Response object to the collection.
055         */
056        public void addResponse(Response response) {
057            if(response.isError()) error = true;
058            responses.add(response);
059        }
060       
061        /**
062         *Appends a ResponseCollection to this collection.
063         */
064        public void appendCollection(ResponseCollection collection) {
065            if(collection.hasError()) error = true;
066            responses.addAll(collection.responses);
067        }
068        
069        /**
070         * Returns a specified response.
071         */
072        public Response getResponse(int index) {
073            Response retval = null;
074            try {
075                retval = (Response)responses.get(index);
076            } catch (Exception e) {
077                retval = null;
078            }
079            return retval;
080        }
081        
082        /**
083         * Prints the file collection to a readable string.
084         */
085        public String toString() {
086            String msg = new String();
087            for(int i=0;i<responses.size();i++) {
088                Response resp = (Response)responses.get(i);
089                msg += resp.toString() + "\n";
090            }
091            return msg;
092        }
093    }
094    
095    
096    
097    
098    
099    
100    
101    
102