001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/portal/owswatch/Status.java $
002    /*----------------------------------------------------------------------------
003     This file is part of deegree, http://deegree.org/
004     Copyright (C) 2001-2009 by:
005       Department of Geography, University of Bonn
006     and
007       lat/lon GmbH
008    
009     This library is free software; you can redistribute it and/or modify it under
010     the terms of the GNU Lesser General Public License as published by the Free
011     Software Foundation; either version 2.1 of the License, or (at your option)
012     any later version.
013     This library is distributed in the hope that it will be useful, but WITHOUT
014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016     details.
017     You should have received a copy of the GNU Lesser General Public License
018     along with this library; if not, write to the Free Software Foundation, Inc.,
019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020    
021     Contact information:
022    
023     lat/lon GmbH
024     Aennchenstr. 19, 53177 Bonn
025     Germany
026     http://lat-lon.de/
027    
028     Department of Geography, University of Bonn
029     Prof. Dr. Klaus Greve
030     Postfach 1147, 53001 Bonn
031     Germany
032     http://www.geographie.uni-bonn.de/deegree/
033    
034     e-mail: info@deegree.org
035    ----------------------------------------------------------------------------*/
036    
037    package org.deegree.portal.owswatch;
038    
039    /**
040     * Enum to hold the different states of a response to the tests made on different services
041     *
042     * @author <a href="mailto:elmasry@lat-lon.de">Moataz Elmasry</a>
043     * @author last edited by: $Author: jmays $
044     *
045     * @version $Revision: 20271 $, $Date: 2009-10-21 13:07:15 +0200 (Mi, 21. Okt 2009) $
046     */
047    public enum Status {
048    
049        /**
050         * If the Service is available
051         */
052        RESULT_STATE_AVAILABLE,
053    
054        /**
055         * If the Service has not yet been tested
056         */
057        RESULT_STATE_WAITING,
058    
059        /**
060         * ************************************ The next list is for critical errors
061         */
062    
063        /**
064         * If the page is unavailable at all
065         */
066        RESULT_STATE_PAGE_UNAVAILABLE,
067    
068        /**
069         * Timeout has occured while executing the request
070         */
071        RESULT_STATE_TIMEOUT,
072    
073        /**
074         * The requested service is not implemented
075         */
076        RESULT_STATE_NOT_IMPLEMENTED,
077    
078        /**
079         * ***************************************** The next ist is for non critical errors
080         */
081        /**
082         * If the response stream is null or can not be read
083         */
084        RESULT_STATE_BAD_RESPONSE,
085    
086        /**
087         * In case the page is available but the request returned no response
088         */
089        RESULT_STATE_SERVICE_UNAVAILABLE,
090    
091        /**
092         * The returned xml document can not be parsed
093         */
094        RESULT_STATE_INVALID_XML,
095    
096        /**
097         * A general use error
098         */
099        RESULT_STATE_ERROR_UNKNOWN,
100    
101        /**
102         *
103         */
104        RESULT_STATE_UNEXPECTED_CONTENT;
105    
106        /**
107         * @return true if the service is available, false otherwise
108         */
109        public boolean isAvailable() {
110    
111            if ( this == RESULT_STATE_AVAILABLE ) {
112                return true;
113            }
114            return false;
115        }
116    
117        /**
118         * @return true if the state is waiting, false otherwise
119         */
120        public boolean isWaiting() {
121    
122            if ( this == RESULT_STATE_WAITING ) {
123                return true;
124            }
125            return false;
126        }
127    
128        /**
129         * @return true if the error is critical, false otherwise
130         */
131        public boolean isCriticalError() {
132    
133            if ( this == RESULT_STATE_PAGE_UNAVAILABLE || this == RESULT_STATE_TIMEOUT
134                 || this == RESULT_STATE_NOT_IMPLEMENTED ) {
135                return true;
136            }
137            return false;
138        }
139    
140        /**
141         * @return true if the error is nonCritical, false otherwise
142         */
143        public boolean isNonCriticalError() {
144    
145            if ( this == RESULT_STATE_SERVICE_UNAVAILABLE || this == RESULT_STATE_INVALID_XML
146                 || this == RESULT_STATE_ERROR_UNKNOWN || this == RESULT_STATE_UNEXPECTED_CONTENT
147                 || this == RESULT_STATE_BAD_RESPONSE ) {
148                return true;
149            }
150            return false;
151        }
152    
153        /**
154         * @return String representation of the error code
155         */
156        public String getStatusMessage() {
157    
158            if ( isAvailable() ) {
159                return "Service is available";
160            } else if ( isWaiting() ) {
161                return "Service has not yet been tested";
162            } else if ( isCriticalError() ) {
163                return translateCriticalErrorMessage();
164            } else if ( isNonCriticalError() ) {
165                return translateNoncriticalErrorMessage();
166            }
167            return "Unknown state";
168        }
169    
170        private String translateNoncriticalErrorMessage() {
171    
172            if ( this == Status.RESULT_STATE_PAGE_UNAVAILABLE ) {
173                return "Page is unavailable";
174            } else if ( this == Status.RESULT_STATE_TIMEOUT ) {
175                return "Server Timeout";
176            } else if ( this == Status.RESULT_STATE_NOT_IMPLEMENTED ) {
177                return "This functionality is not implemented";
178            } else if ( this == Status.RESULT_STATE_BAD_RESPONSE ) {
179                return "The response is null or empty";
180            }
181            return "Unknown non critical error";
182    
183        }
184    
185        private String translateCriticalErrorMessage() {
186    
187            if ( this == Status.RESULT_STATE_SERVICE_UNAVAILABLE ) {
188                return "The service is currently unavailable";
189            } else if ( this == Status.RESULT_STATE_INVALID_XML ) {
190                return "The response xml could not be parsed";
191            } else if ( this == Status.RESULT_STATE_ERROR_UNKNOWN ) {
192                return "Unknown uncritical error";
193            } else if ( this == Status.RESULT_STATE_UNEXPECTED_CONTENT ) {
194                return "Content type is not what was expected";
195            }
196            return "Unknown critical error";
197    
198        }
199    }