001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/crs/exceptions/TransformationException.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.crs.exceptions;
038    
039    import java.util.HashMap;
040    import java.util.List;
041    import java.util.Map;
042    
043    import javax.vecmath.Point3d;
044    
045    import org.deegree.crs.coordinatesystems.CoordinateSystem;
046    
047    /**
048     * The <code>TransformationException</code> class can be thrown if a transformation exception
049     * occurs. For example in the process of creating a transformation step.
050     *
051     * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
052     *
053     * @author last edited by: $Author: mschneider $
054     *
055     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
056     *
057     */
058    
059    public class TransformationException extends Exception {
060    
061        /**
062         *
063         */
064        private static final long serialVersionUID = 1475176551325426832L;
065    
066        private Map<Integer, String> transformErrors = new HashMap<Integer, String>();
067    
068        private List<Point3d> transformedPoints = null;
069    
070        /**
071         * Initializes the error message map with the given size.
072         *
073         * @param numberOfCoordinates
074         *            in the list of coordinates which will be transformed.
075         */
076        public TransformationException( int numberOfCoordinates ) {
077            if ( numberOfCoordinates < 0 ) {
078                numberOfCoordinates = 0;
079            }
080            transformErrors = new HashMap<Integer, String>( numberOfCoordinates );
081        }
082    
083        /**
084         * @param message
085         */
086        public TransformationException( String message ) {
087            super( message );
088        }
089    
090        /**
091         * @param cause
092         */
093        public TransformationException( Throwable cause ) {
094            super( cause );
095        }
096    
097        /**
098         * @param message
099         * @param cause
100         */
101        public TransformationException( String message, Throwable cause ) {
102            super( message, cause );
103        }
104    
105        /**
106         * @param sourceCS
107         *            from which crs
108         * @param targetCS
109         *            to which crs
110         * @param cause
111         *            for the exception.
112         */
113        public TransformationException( CoordinateSystem sourceCS, CoordinateSystem targetCS, String cause ) {
114            super(
115                   new StringBuilder( "Can't transform from: " ).append( sourceCS.getIdentifier() ).append( " into " ).append(
116                                                                                                                               targetCS.getIdentifier() ).append(
117                                                                                                                                                                  " because: " ).append(
118                                                                                                                                                                                         cause ).toString() );
119        }
120    
121        /**
122         * @return the transformErrors may be empty but will never be <code>null</code>.
123         */
124        public final Map<Integer, String> getTransformErrors() {
125            return transformErrors;
126        }
127    
128        /**
129         * @param coordinateNumber
130         *            the position of the coordinate-tuple/triple which were responsible for the
131         *            transformationexception.
132         * @param errorMessage
133         *            the error message for given coordinate pair (in the array of coordinates).
134         */
135        public final void setTransformError( int coordinateNumber, String errorMessage ) {
136            String value = "";
137            Integer key = new Integer( coordinateNumber );
138            if ( transformErrors.containsKey( key ) && transformErrors.get( key ) != null ) {
139                value = transformErrors.get( key ) + ";";
140            }
141            value += errorMessage;
142            transformErrors.put( key, value );
143        }
144    
145        /**
146         * @return the transformedPoints, which are the points that were (successfully or
147         *         unsuccessfully) transformed or <code>null</code> if no points were set.
148         */
149        public final List<Point3d> getTransformedPoints() {
150            return transformedPoints;
151        }
152    
153        /**
154         * @param transformedPoints
155         *            which were (successfully or unsuccessfully) transformed until the exception(s)
156         *            occurred.
157         */
158        public final void setTransformedPoints( List<Point3d> transformedPoints ) {
159            this.transformedPoints = transformedPoints;
160        }
161    
162    }