001 //$HeadURL: $
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.ogcwebservices.wcts.operation;
038
039 import static org.deegree.framework.xml.XMLTools.getElements;
040 import static org.deegree.framework.xml.XMLTools.getNodeAsString;
041 import static org.deegree.framework.xml.XMLTools.getStringValue;
042
043 import java.util.ArrayList;
044 import java.util.List;
045
046 import org.deegree.framework.log.ILogger;
047 import org.deegree.framework.log.LoggerFactory;
048 import org.deegree.framework.util.Pair;
049 import org.deegree.framework.xml.XMLParsingException;
050 import org.deegree.i18n.Messages;
051 import org.deegree.model.crs.CRSFactory;
052 import org.deegree.model.crs.CoordinateSystem;
053 import org.deegree.model.crs.UnknownCRSException;
054 import org.deegree.ogcbase.CommonNamespaces;
055 import org.deegree.ogcbase.ExceptionCode;
056 import org.deegree.ogcwebservices.OGCWebServiceException;
057 import org.deegree.ogcwebservices.wcts.WCTService;
058 import org.w3c.dom.Element;
059
060 /**
061 * <code>IsTransformableDocument</code> is a helper class which is able to parse wcts isTransformable requests version
062 * 0.4.0
063 *
064 * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
065 *
066 * @author last edited by: $Author:$
067 *
068 * @version $Revision:$, $Date:$
069 *
070 */
071 public class IsTransformableDocument extends WCTSRequestBaseDocument {
072
073 private static ILogger LOG = LoggerFactory.getLogger( IsTransformableDocument.class );
074
075 private static final long serialVersionUID = 241071726326354269L;
076
077 private IsTransformable isTransformable;
078
079 /**
080 * @param id
081 * @param rootElement
082 * @throws OGCWebServiceException
083 * if an {@link XMLParsingException} occurred or a mandatory element/attribute is missing.
084 */
085 public IsTransformableDocument( String id, Element rootElement ) throws OGCWebServiceException {
086 super( rootElement );
087 String version = parseVersion();
088
089 // check for valid request.
090 parseService();
091 try {
092 String sCRS = getNodeAsString( getRootElement(), PRE + "SourceCRS", nsContext, null );
093 String tCRS = getNodeAsString( getRootElement(), PRE + "TargetCRS", nsContext, null );
094 CoordinateSystem sourceCRS = null;
095 CoordinateSystem targetCRS = null;
096 String transformation = null;
097 String method = null;
098 if ( ( sCRS != null && tCRS == null ) || ( sCRS == null && tCRS != null ) ) {
099 throw new OGCWebServiceException(
100 Messages.getMessage(
101 "WCTS_ISTRANSFORMABLE_MISSING_CRS",
102 ( ( sCRS == null ) ? "TargetCRS" : "SourceCRS" ),
103 ( ( sCRS == null ) ? "SourceCRS" : "TargetCRS" ) ),
104 ExceptionCode.INVALIDPARAMETERVALUE );
105 }
106 if ( sCRS == null && tCRS == null ) {
107 transformation = getNodeAsString( getRootElement(), PRE + "Transformation", nsContext, null );
108
109 method = getNodeAsString( getRootElement(), PRE + "Method", nsContext, null );
110 } else {
111 // handle the creation of the crs's separately because if one fails the other may still be valid.
112 try {
113 targetCRS = CRSFactory.create( WCTService.CRS_PROVIDER, tCRS );
114 } catch ( UnknownCRSException e ) {
115 // LOG.logError( e.getMessage(), e );
116 // here an ogc webservice exception should (could) be thrown, but since the 'spec' defines an other
117 // response, we have to ignore it and handle it later.
118 // throw new OGCWebServiceException( e.getMessage(), ExceptionCode.NOAPPLICABLECODE );
119 }
120
121 try {
122 sourceCRS = CRSFactory.create( WCTService.CRS_PROVIDER, sCRS );
123 } catch ( UnknownCRSException e ) {
124 // LOG.logError( e.getMessage(), e );
125 }
126 }
127
128 // Check for not supported values.
129 if ( transformation != null ) {
130 throw new OGCWebServiceException( Messages.getMessage( "WCTS_ISTRANSFORMABLE_NOT_KNOWN",
131 "transformation" ),
132 ExceptionCode.INVALIDPARAMETERVALUE );
133 }
134 if ( method != null ) {
135 throw new OGCWebServiceException( Messages.getMessage( "WCTS_ISTRANSFORMABLE_NOT_KNOWN", "Method" ),
136 ExceptionCode.INVALIDPARAMETERVALUE );
137 }
138
139 List<Pair<String, String>> geometryTypes = parseGeometryTypes();
140 // just do a check if the coverageTypes were requested.
141 List<Pair<String, String>> coverageTypes = parseCoverageTypes();
142 // just do a check if the interpolationTypes were requested.
143 List<Pair<String, String>> interpolationTypes = parseInterpolationTypes();
144 this.isTransformable = new IsTransformable( version, id, sourceCRS, targetCRS, transformation, method,
145 geometryTypes, coverageTypes, interpolationTypes );
146 } catch ( XMLParsingException e ) {
147 LOG.logError( e.getMessage(), e );
148 throw new OGCWebServiceException( e.getMessage(), ExceptionCode.NOAPPLICABLECODE );
149 }
150
151 }
152
153 /**
154 * @return a list containing <value, codeSpace > pairs. If codeSpace, was not set it will contain the default
155 * value: <code>http://schemas.opengis.net/wcts/0.0.0/geometryType.xml</code>. The result can be empty
156 * but never <code>null</code>.
157 * @throws XMLParsingException
158 * if an error occurs while getting all elements of type geometryType.
159 */
160 protected List<Pair<String, String>> parseGeometryTypes()
161 throws XMLParsingException {
162 List<Element> geometryTypes = getElements( getRootElement(), PRE + "GeometryType", nsContext );
163 List<Pair<String, String>> result = new ArrayList<Pair<String, String>>();
164 if ( geometryTypes != null && geometryTypes.size() > 0 ) {
165 for ( Element geomType : geometryTypes ) {
166 if ( geomType != null ) {
167 String geom = getStringValue( geomType );
168 String codeSpace = geomType.getAttribute( "codeSpace" );
169 if ( "".equals( codeSpace ) ) {
170 codeSpace = "http://schemas.opengis.net/wcts/0.0.0/geometryType.xml";
171 }
172 result.add( new Pair<String, String>( geom, codeSpace ) );
173 }
174 }
175 }
176 return result;
177 }
178
179 /**
180 * @return always <code>null</code>, because this operation is not supported by the wcts.
181 * @throws XMLParsingException
182 * if an error occurs while getting all elements of type coverageType.
183 * @throws OGCWebServiceException
184 * if coverageType elements were found.
185 */
186 protected List<Pair<String, String>> parseCoverageTypes()
187 throws XMLParsingException, OGCWebServiceException {
188 List<Element> coverageTypes = getElements( getRootElement(), PRE + "CoverageType", nsContext );
189 if ( coverageTypes != null && coverageTypes.size() > 0 ) {
190 throw new OGCWebServiceException( Messages.getMessage( "WCTS_OPERATION_NOT_SUPPORTED",
191 "transformation of coverages" ),
192 ExceptionCode.OPERATIONNOTSUPPORTED );
193 }
194 return null;
195 }
196
197 /**
198 * @return always <code>null</code>, because this operation is not supported by the wcts.
199 * @throws XMLParsingException
200 * if an error occurs while getting all elements of type interpolationType.
201 * @throws OGCWebServiceException
202 * if interpolationType elements were found.
203 */
204 protected List<Pair<String, String>> parseInterpolationTypes()
205 throws XMLParsingException, OGCWebServiceException {
206 List<Element> interpolationTypes = getElements( getRootElement(), CommonNamespaces.WCS_1_2_0_PREFIX
207 + ":InterpolationType", nsContext );
208 if ( interpolationTypes != null && interpolationTypes.size() > 0 ) {
209 throw new OGCWebServiceException( Messages.getMessage( "WCTS_OPERATION_NOT_SUPPORTED",
210 "interpolation of coverages" ),
211 ExceptionCode.OPERATIONNOTSUPPORTED );
212 }
213 return null;
214 }
215
216 /**
217 * @return the isTransformable.
218 */
219 public final IsTransformable getIsTransformable() {
220 return isTransformable;
221 }
222
223 }