001    // $HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/wcs/configuration/DefaultExtension.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003    
004     This file is part of deegree.
005     Copyright (C) 2001-2006 by:
006     EXSE, Department of Geography, University of Bonn
007     http://www.giub.uni-bonn.de/deegree/
008     lat/lon GmbH
009     http://www.lat-lon.de
010    
011     This library is free software; you can redistribute it and/or
012     modify it under the terms of the GNU Lesser General Public
013     License as published by the Free Software Foundation; either
014     version 2.1 of the License, or (at your option) any later version.
015    
016     This library is distributed in the hope that it will be useful,
017     but WITHOUT ANY WARRANTY; without even the implied warranty of
018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
019     Lesser General Public License for more details.
020    
021     You should have received a copy of the GNU Lesser General Public
022     License along with this library; if not, write to the Free Software
023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
024    
025     Contact:
026    
027     Andreas Poth
028     lat/lon GmbH
029     Aennchenstr. 19
030     53115 Bonn
031     Germany
032     E-Mail: poth@lat-lon.de
033    
034     Prof. Dr. Klaus Greve
035     Department of Geography
036     University of Bonn
037     Meckenheimer Allee 166
038     53115 Bonn
039     Germany
040     E-Mail: greve@giub.uni-bonn.de
041    
042     
043     ---------------------------------------------------------------------------*/
044    package org.deegree.ogcwebservices.wcs.configuration;
045    
046    import java.util.ArrayList;
047    import java.util.Iterator;
048    import java.util.List;
049    import java.util.TreeSet;
050    
051    /**
052     * Default implementation of WCS CoverageDescription for handling informations about coverage data
053     * backend.
054     * 
055     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
056     * @author last edited by: $Author: apoth $
057     * 
058     * @version $Revision: 6582 $, $Date: 2007-04-11 11:44:24 +0200 (Mi, 11 Apr 2007) $
059     */
060    public class DefaultExtension implements Extension {
061    
062        protected TreeSet<Resolution> resolutions = null;
063    
064        protected double minScale = 0;
065    
066        protected double maxScale = 9E99;
067    
068        private String type = null;
069        
070        private double offset = 0;
071        
072        private double scaleFactor = 1;
073        
074    
075        /**
076         * constructor initializing an empty <tt>Extension</tt>
077         * 
078         * @param type
079         * @throws UnknownCVExtensionException
080         */
081        public DefaultExtension( String type ) throws UnknownCVExtensionException {
082            resolutions = new TreeSet<Resolution>();
083            setType( type );
084        }
085    
086        /**
087         * initializing the <tt>Extension</tt> with the passed <tt>Resolution</tt>s
088         * 
089         * @param type
090         * @param resolutions
091         * @param offset
092         * @param scaleFactor
093         * @throws UnknownCVExtensionException
094         */
095        public DefaultExtension( String type, Resolution[] resolutions, double offset, 
096                                 double scaleFactor )
097                                throws UnknownCVExtensionException {
098            this( type );
099            minScale = 9E99;
100            maxScale = 0;
101            for ( int i = 0; i < resolutions.length; i++ ) {
102                this.resolutions.add( resolutions[i] );
103                if ( resolutions[i].getMinScale() < minScale ) {
104                    minScale = resolutions[i].getMinScale();
105                }
106                if ( resolutions[i].getMaxScale() > maxScale ) {
107                    maxScale = resolutions[i].getMaxScale();
108                }
109            }
110            this.offset = offset;
111            this.scaleFactor = scaleFactor;
112        }
113    
114        /**
115         * returns the type of the coverage source that is described be an extension
116         * 
117         * @return the type of the coverage source that is described be an extension
118         */
119        public String getType() {
120            return type;
121        }
122    
123        /**
124         * returns the type of the coverage source that is described be an extension. Valid types are:
125         * <ul>
126         * <li>shapeIndexed
127         * <li>nameIndexed
128         * <li>file
129         * </ul>
130         * This list may be extended in future versions of deegree
131         * 
132         * @param type
133         * @throws UnknownCVExtensionException
134         */
135        public void setType( String type )
136                                throws UnknownCVExtensionException {
137            if ( type == null
138                 || ( !type.equals( "shapeIndexed" ) && !type.equals( "nameIndexed" )
139                      && !type.equals( "file" ) && !type.equals( "OracleGeoRaster" ) ) ) {
140                throw new UnknownCVExtensionException( "unknown extension type: " + type );
141            }
142            this.type = type;
143        }
144    
145        /**
146         * returns the minimum scale of objects that are described by an <tt>Extension</tt> object
147         * 
148         * @return the minimum scale of objects that are described by an <tt>Extension</tt> object
149         */
150        public double getMinScale() {
151            return minScale;
152        }    
153        
154        /**
155         * returns the offset of the data. 0 will be returned if no offset is
156         * defined. Data first must be divided by the scale factor (@see #getScaleFactor()) 
157         * before sustracting the offset
158         * 
159         * @return
160         */
161        public double getOffset() {
162            return offset;
163        }
164    
165        /**
166         * returns the scale factor of the data. If no scale factor is defined
167         * 1 will be returned. Data first must be divided by the scale factor 
168         * (@see #getScaleFactor()) before sustracting the offset
169         * @return
170         */
171        public double getScaleFactor() {
172            return scaleFactor;
173        }
174    
175        /**
176         * returns the maximum scale of objects that are described by an <tt>Extension</tt> object
177         * 
178         * @return the maximum scale of objects that are described by an <tt>Extension</tt> object
179         */
180        public double getMaxScale() {
181            return maxScale;
182        }
183    
184        /**
185         * returns all <tt>Resolution</tt>s . If no <tt>Resolution</tt> can be found for the passed
186         * scale an empty array will be returned.
187         * 
188         * @param scale
189         *            scale the returned resolutions must fit
190         * 
191         * @return <tt>Resolution</tt>s matching the passed scale
192         */
193        public Resolution[] getResolutions() {
194            return resolutions.toArray( new Resolution[resolutions.size()] );
195        }
196    
197        /**
198         * returns the <tt>Resolution</tt>s matching the passed scale. If no <tt>Resolution</tt>
199         * can be found for the passed scale an empty array will be returned.
200         * 
201         * @param scale
202         *            scale the returned resolutions must fit
203         * 
204         * @return <tt>Resolution</tt>s matching the passed scale
205         */
206        public Resolution[] getResolutions( double scale ) {
207            if ( scale < minScale || scale > maxScale ) {
208                return new Resolution[0];
209            }
210            List<Resolution> list = new ArrayList<Resolution>();
211            Iterator iterator = resolutions.iterator();
212            while ( iterator.hasNext() ) {
213                Resolution res = (Resolution) iterator.next();
214                if ( scale >= res.getMinScale() && scale <= res.getMaxScale() ) {
215                    list.add( res );
216                }
217            }
218            return list.toArray( new Resolution[list.size()] );
219        }
220    
221        /**
222         * @param resolution
223         */
224        public void addResolution( Resolution resolution ) {
225            resolutions.add( resolution );
226        }
227    
228    }