001 // $HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/wcs/configuration/DefaultExtension.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001-2008 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: 9345 $, $Date: 2007-12-27 17:22:25 +0100 (Do, 27 Dez 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 * constructor initializing an empty <tt>Extension</tt>
076 *
077 * @param type
078 * @throws UnknownCVExtensionException
079 */
080 public DefaultExtension( String type ) throws UnknownCVExtensionException {
081 resolutions = new TreeSet<Resolution>();
082 setType( type );
083 }
084
085 /**
086 * initializing the <tt>Extension</tt> with the passed <tt>Resolution</tt>s
087 *
088 * @param type
089 * @param resolutions
090 * @param offset
091 * @param scaleFactor
092 * @throws UnknownCVExtensionException
093 */
094 public DefaultExtension( String type, Resolution[] resolutions, double offset, double scaleFactor )
095 throws UnknownCVExtensionException {
096 this( type );
097 minScale = 9E99;
098 maxScale = 0;
099 for ( int i = 0; i < resolutions.length; i++ ) {
100 this.resolutions.add( resolutions[i] );
101 if ( resolutions[i].getMinScale() < minScale ) {
102 minScale = resolutions[i].getMinScale();
103 }
104 if ( resolutions[i].getMaxScale() > maxScale ) {
105 maxScale = resolutions[i].getMaxScale();
106 }
107 }
108 this.offset = offset;
109 this.scaleFactor = scaleFactor;
110 }
111
112 /**
113 * returns the type of the coverage source that is described be an extension
114 *
115 * @return the type of the coverage source that is described be an extension
116 */
117 public String getType() {
118 return type;
119 }
120
121 /**
122 * returns the type of the coverage source that is described be an extension. Valid types are:
123 * <ul>
124 * <li>shapeIndexed
125 * <li>nameIndexed
126 * <li>file
127 * </ul>
128 * This list may be extended in future versions of deegree
129 *
130 * @param type
131 * @throws UnknownCVExtensionException
132 */
133 public void setType( String type )
134 throws UnknownCVExtensionException {
135 if ( type == null
136 || ( !Extension.SHAPEINDEXED.equals( type ) && !Extension.NAMEINDEXED.equals( type )
137 && !Extension.FILEBASED.equals( type ) && !Extension.ORACLEGEORASTER.equals( type ) &&
138 !Extension.DATABASEINDEXED.equals( type ) ) ) {
139 throw new UnknownCVExtensionException( "unknown extension type: " + type );
140 }
141 this.type = type;
142 }
143
144 /**
145 * returns the minimum scale of objects that are described by an <tt>Extension</tt> object
146 *
147 * @return the minimum scale of objects that are described by an <tt>Extension</tt> object
148 */
149 public double getMinScale() {
150 return minScale;
151 }
152
153 /**
154 * returns the offset of the data. 0 will be returned if no offset is defined. Data first must
155 * be divided by the scale factor (@see #getScaleFactor()) before sustracting the offset
156 *
157 * @return
158 */
159 public double getOffset() {
160 return offset;
161 }
162
163 /**
164 * returns the scale factor of the data. If no scale factor is defined 1 will be returned. Data
165 * first must be divided by the scale factor (@see #getScaleFactor()) before sustracting the
166 * offset
167 *
168 * @return
169 */
170 public double getScaleFactor() {
171 return scaleFactor;
172 }
173
174 /**
175 * returns the maximum scale of objects that are described by an <tt>Extension</tt> object
176 *
177 * @return the maximum scale of objects that are described by an <tt>Extension</tt> object
178 */
179 public double getMaxScale() {
180 return maxScale;
181 }
182
183 /**
184 * returns all <tt>Resolution</tt>s . If no <tt>Resolution</tt> can be found for the passed
185 * scale an empty array will be returned.
186 *
187 * @param scale
188 * scale the returned resolutions must fit
189 *
190 * @return <tt>Resolution</tt>s matching the passed scale
191 */
192 public Resolution[] getResolutions() {
193 return resolutions.toArray( new Resolution[resolutions.size()] );
194 }
195
196 /**
197 * returns the <tt>Resolution</tt>s matching the passed scale. If no <tt>Resolution</tt>
198 * can be found for the passed scale an empty array will be returned.
199 *
200 * @param scale
201 * scale the returned resolutions must fit
202 *
203 * @return <tt>Resolution</tt>s matching the passed scale
204 */
205 public Resolution[] getResolutions( double scale ) {
206 if ( scale < minScale || scale > maxScale ) {
207 return new Resolution[0];
208 }
209 List<Resolution> list = new ArrayList<Resolution>();
210 Iterator iterator = resolutions.iterator();
211 while ( iterator.hasNext() ) {
212 Resolution res = (Resolution) iterator.next();
213 if ( scale >= res.getMinScale() && scale <= res.getMaxScale() ) {
214 list.add( res );
215 }
216 }
217 return list.toArray( new Resolution[list.size()] );
218 }
219
220 /**
221 * @param resolution
222 */
223 public void addResolution( Resolution resolution ) {
224 resolutions.add( resolution );
225 }
226
227 }