001    // $HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/ogcwebservices/wcs/configuration/DefaultExtension.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    package org.deegree.ogcwebservices.wcs.configuration;
037    
038    import java.util.ArrayList;
039    import java.util.Iterator;
040    import java.util.List;
041    import java.util.TreeSet;
042    
043    /**
044     * Default implementation of WCS CoverageDescription for handling informations about coverage data
045     * backend.
046     *
047     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
048     * @author last edited by: $Author: mschneider $
049     *
050     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
051     */
052    public class DefaultExtension implements Extension {
053    
054        /**
055         * all resolutions
056         */
057        protected TreeSet<Resolution> resolutions = null;
058    
059        /**
060         *
061         */
062        protected double minScale = 0;
063    
064        /**
065         *
066         */
067        protected double maxScale = 9E99;
068    
069        private String type = null;
070    
071        private double offset = 0;
072    
073        private double scaleFactor = 1;
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, double scaleFactor )
096                                throws UnknownCVExtensionException {
097            this( type );
098            minScale = 9E99;
099            maxScale = 0;
100            for ( int i = 0; i < resolutions.length; i++ ) {
101                this.resolutions.add( resolutions[i] );
102                if ( resolutions[i].getMinScale() < minScale ) {
103                    minScale = resolutions[i].getMinScale();
104                }
105                if ( resolutions[i].getMaxScale() > maxScale ) {
106                    maxScale = resolutions[i].getMaxScale();
107                }
108            }
109            this.offset = offset;
110            this.scaleFactor = scaleFactor;
111        }
112    
113        /**
114         * returns the type of the coverage source that is described be an extension
115         *
116         * @return the type of the coverage source that is described be an extension
117         */
118        public String getType() {
119            return type;
120        }
121    
122        /**
123         * returns the type of the coverage source that is described be an extension. Valid types are:
124         * <ul>
125         * <li>shapeIndexed
126         * <li>nameIndexed
127         * <li>file
128         * </ul>
129         * This list may be extended in future versions of deegree
130         *
131         * @param type
132         * @throws UnknownCVExtensionException
133         */
134        public void setType( String type )
135                                throws UnknownCVExtensionException {
136            if ( type == null
137                 || ( !Extension.SHAPEINDEXED.equals( type ) && !Extension.NAMEINDEXED.equals( type )
138                      && !Extension.FILEBASED.equals( type ) && !Extension.ORACLEGEORASTER.equals( type )
139                      && !Extension.DATABASEINDEXED.equals( type ) && !Extension.SCRIPTBASED.equals( type ) ) ) {
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 defined. Data first must
156         * be divided by the scale factor (@see #getScaleFactor()) before sustracting the offset
157         *
158         * @return the offset
159         */
160        public double getOffset() {
161            return offset;
162        }
163    
164        /**
165         * returns the scale factor of the data. If no scale factor is defined 1 will be returned. Data
166         * first must be divided by the scale factor (@see #getScaleFactor()) before sustracting the
167         * offset
168         *
169         * @return the scale factor
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         * @return <tt>Resolution</tt>s matching the passed scale
189         */
190        public Resolution[] getResolutions() {
191            return resolutions.toArray( new Resolution[resolutions.size()] );
192        }
193    
194        /**
195         * returns the <tt>Resolution</tt>s matching the passed scale. If no <tt>Resolution</tt>
196         * can be found for the passed scale an empty array will be returned.
197         *
198         * @param scale
199         *            scale the returned resolutions must fit
200         *
201         * @return <tt>Resolution</tt>s matching the passed scale
202         */
203        public Resolution[] getResolutions( double scale ) {
204            if ( scale < minScale || scale > maxScale ) {
205                return new Resolution[0];
206            }
207            List<Resolution> list = new ArrayList<Resolution>();
208            Iterator iterator = resolutions.iterator();
209            while ( iterator.hasNext() ) {
210                Resolution res = (Resolution) iterator.next();
211                if ( scale >= res.getMinScale() && scale <= res.getMaxScale() ) {
212                    list.add( res );
213                }
214            }
215            return list.toArray( new Resolution[list.size()] );
216        }
217    
218        /**
219         * @param resolution
220         */
221        public void addResolution( Resolution resolution ) {
222            resolutions.add( resolution );
223        }
224    
225    }