001: //$HeadURL: $
002: /*---------------- FILE HEADER ------------------------------------------
003: This file is part of deegree.
004: Copyright (C) 2001-2008 by:
005: Department of Geography, University of Bonn
006: http://www.giub.uni-bonn.de/deegree/
007: lat/lon GmbH
008: http://www.lat-lon.de
009:
010: This library is free software; you can redistribute it and/or
011: modify it under the terms of the GNU Lesser General Public
012: License as published by the Free Software Foundation; either
013: version 2.1 of the License, or (at your option) any later version.
014: This library is distributed in the hope that it will be useful,
015: but WITHOUT ANY WARRANTY; without even the implied warranty of
016: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: Lesser General Public License for more details.
018: You should have received a copy of the GNU Lesser General Public
019: License along with this library; if not, write to the Free Software
020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: Contact:
022:
023: Andreas Poth
024: lat/lon GmbH
025: Aennchenstr. 19
026: 53177 Bonn
027: Germany
028: E-Mail: poth@lat-lon.de
029:
030: Prof. Dr. Klaus Greve
031: Department of Geography
032: University of Bonn
033: Meckenheimer Allee 166
034: 53115 Bonn
035: Germany
036: E-Mail: greve@giub.uni-bonn.de
037: ---------------------------------------------------------------------------*/
038:
039: package org.deegree.ogcwebservices.wcts.operation;
040:
041: import java.util.ArrayList;
042: import java.util.List;
043: import java.util.Map;
044:
045: import org.deegree.framework.util.Pair;
046: import org.deegree.i18n.Messages;
047: import org.deegree.model.crs.CRSFactory;
048: import org.deegree.model.crs.CoordinateSystem;
049: import org.deegree.model.crs.UnknownCRSException;
050: import org.deegree.ogcbase.ExceptionCode;
051: import org.deegree.ogcwebservices.OGCWebServiceException;
052: import org.deegree.ogcwebservices.wcts.WCTSExceptionCode;
053: import org.deegree.ogcwebservices.wcts.WCTService;
054:
055: /**
056: * <code>IsTransformable</code> encapsulates the bean representation of the xml-dom or kvp encoded IsTransformable
057: * request of the wcts 0.4.0
058: *
059: * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
060: *
061: * @author last edited by: $Author:$
062: *
063: * @version $Revision:$, $Date:$
064: *
065: */
066: public class IsTransformable extends WCTSRequestBase {
067:
068: private static final long serialVersionUID = 5834206406155257853L;
069:
070: private final CoordinateSystem sourceCRS;
071:
072: private final CoordinateSystem targetCRS;
073:
074: private final String transformation;
075:
076: private final String method;
077:
078: private final List<Pair<String, String>> geometryTypes;
079:
080: private final List<String> simpleGeometryTypes;
081:
082: private final List<Pair<String, String>> coverageTypes;
083:
084: private final List<Pair<String, String>> interpolationTypes;
085:
086: /**
087: * @param version
088: * @param id
089: * @param sourceCRS if <code>null</code> it is assumed that the sourceCRS is not supported.
090: * @param targetCRS if <code>null</code> it is assumed that the targetCRS is not supported.
091: * @param transformation
092: * @param method
093: * @param geometryTypes
094: * @param coverageTypes
095: * @param interpolationTypes
096: */
097: public IsTransformable(String version, String id,
098: CoordinateSystem sourceCRS, CoordinateSystem targetCRS,
099: String transformation, String method,
100: List<Pair<String, String>> geometryTypes,
101: List<Pair<String, String>> coverageTypes,
102: List<Pair<String, String>> interpolationTypes) {
103:
104: super (version, id, null);
105: this .sourceCRS = sourceCRS;
106: this .targetCRS = targetCRS;
107: this .transformation = transformation;
108: this .method = method;
109: if (coverageTypes != null) {
110: throw new IllegalArgumentException(
111: Messages
112: .getMessage("WCTS_ISTRANSFORMABLE_COVERAGE_NOT_SUPPORTED"));
113: }
114: this .coverageTypes = coverageTypes;
115: if (interpolationTypes != null) {
116: throw new IllegalArgumentException(
117: Messages
118: .getMessage("WCTS_ISTRANSFORMABLE_INTERPOLATION_NOT_SUPPORTED"));
119: }
120: this .interpolationTypes = interpolationTypes;
121: this .geometryTypes = geometryTypes;
122: this .simpleGeometryTypes = null;
123: }
124:
125: /**
126: * @param version
127: * @param requestID
128: * @param sourceCRS if <code>null</code> it is assumed that the sourceCRS is not supported.
129: * @param targetCRS if <code>null</code> it is assumed that the targetCRS is not supported.
130: * @param geometryTypes
131: * a list of simple geometry representations.
132: */
133: public IsTransformable(String version, String requestID,
134: CoordinateSystem sourceCRS, CoordinateSystem targetCRS,
135: List<String> geometryTypes) {
136: super (version, requestID, null);
137: this .sourceCRS = sourceCRS;
138: this .targetCRS = targetCRS;
139: this .transformation = null;
140: this .method = null;
141: this .coverageTypes = null;
142: this .interpolationTypes = null;
143:
144: this .geometryTypes = null;
145: this .simpleGeometryTypes = geometryTypes;
146: }
147:
148: /**
149: * @return the sourceCRS, if <code>null</code> it can be assumed that the sourceCRS is not supported.
150: */
151: public final CoordinateSystem getSourceCRS() {
152: return sourceCRS;
153: }
154:
155: /**
156: * @return the targetCRS, if <code>null</code> it can be assumed that the targetCRS is not supported.
157: */
158: public final CoordinateSystem getTargetCRS() {
159: return targetCRS;
160: }
161:
162: /**
163: * @return the transformation currently <code>null</code>
164: */
165: public final String getTransformation() {
166: return transformation;
167: }
168:
169: /**
170: * @return the method currently <code>null</code>
171: */
172: public final String getMethod() {
173: return method;
174: }
175:
176: /**
177: * @return the geometryTypes as a list of < value, codeSpace > pairs. May be <code>null</code>, if so, check
178: * {@link #getSimpleGeometryTypes()} to see if the request defined geometryTypes by KVP.
179: */
180: public final List<Pair<String, String>> getGeometryTypes() {
181: return geometryTypes;
182: }
183:
184: /**
185: * @return the simpleGeometryTypes. Maybe <code>null</code>, if so check {@link #getGeometryTypes()} to see if
186: * xml encoded geometryTypes were supplied.
187: */
188: public final List<String> getSimpleGeometryTypes() {
189: return simpleGeometryTypes;
190: }
191:
192: /**
193: * @return the coverageTypes currently <code>null</code>.
194: */
195: public final List<Pair<String, String>> getCoverageTypes() {
196: return coverageTypes;
197: }
198:
199: /**
200: * @return the interpolationTypes currently <code>null</code>.
201: */
202: public final List<Pair<String, String>> getInterpolationTypes() {
203: return interpolationTypes;
204: }
205:
206: /**
207: * Create a {@link IsTransformable}-request by extracting the values from the map, and calling the constructor with
208: * these values.
209: *
210: * @param requestID
211: * service internal id for this request.
212: * @param map
213: * to extract requested values from.
214: * @return the bean representation
215: * @throws OGCWebServiceException
216: * if the map is <code>null</code> or has size==0, or the service,request parameters have none
217: * accepted values.
218: */
219: public static IsTransformable create(String requestID,
220: Map<String, String> map) throws OGCWebServiceException {
221: if (map == null || map.size() == 0) {
222: throw new OGCWebServiceException(Messages
223: .getMessage("WCTS_REQUESTMAP_NULL"),
224: ExceptionCode.MISSINGPARAMETERVALUE);
225: }
226: String service = map.get("SERVICE");
227: if (service == null || !"WCTS".equals(service)) {
228: throw new OGCWebServiceException(Messages.getMessage(
229: "WCTS_NO_VERSION_KVP", service),
230: ExceptionCode.MISSINGPARAMETERVALUE);
231: }
232: String request = map.get("REQUEST");
233: if (request == null
234: || !"IsTransformable".equalsIgnoreCase(request)) {
235: throw new OGCWebServiceException(
236: Messages.getMessage("WCTS_NO_REQUEST_KVP",
237: "IsTransformable"),
238: (request == null ? ExceptionCode.MISSINGPARAMETERVALUE
239: : ExceptionCode.OPERATIONNOTSUPPORTED));
240: }
241: String version = map.get("VERSION");
242: if (version == null
243: || !WCTService.version.equalsIgnoreCase(version)) {
244: throw new OGCWebServiceException(Messages.getMessage(
245: "WCTS_NO_VERSION_KVP", version),
246: ExceptionCode.MISSINGPARAMETERVALUE);
247: }
248:
249: String sCRS = map.get("SOURCECRS");
250: String tCRS = map.get("TARGETCRS");
251: if (((sCRS != null && !"".equals(sCRS.trim())) && (tCRS == null || ""
252: .equals(tCRS.trim())))
253: || ((tCRS != null && !"".equals(tCRS.trim())) && (sCRS == null || ""
254: .equals(sCRS.trim())))) {
255: throw new OGCWebServiceException(Messages.getMessage(
256: "WCTS_MISSING_MUTUAL_KEY_KVP",
257: ((sCRS == null) ? "TargetCRS" : "SourceCRS"),
258: ((sCRS == null) ? "SourceCRS" : "TargetCRS")),
259: ExceptionCode.INVALIDPARAMETERVALUE);
260: }
261: if ((sCRS == null || "".equals(sCRS.trim()))
262: && (tCRS == null || "".equals(tCRS.trim()))) {
263: String transformation = map.get("TRANSFORMATION");
264: if (!(transformation == null || "".equals(transformation
265: .trim()))) {
266: throw new OGCWebServiceException(
267: Messages
268: .getMessage(
269: "WCTS_OPERATION_NOT_SUPPORTED",
270: "defining of transformations (Transformation key)"),
271: ExceptionCode.OPERATIONNOTSUPPORTED);
272: }
273:
274: String method = map.get("METHOD");
275: if (!(method == null || "".equals(method.trim()))) {
276: throw new OGCWebServiceException(Messages.getMessage(
277: "WCTS_OPERATION_NOT_SUPPORTED",
278: "transformation method (Method key)"),
279: ExceptionCode.OPERATIONNOTSUPPORTED);
280: }
281: throw new OGCWebServiceException(
282: Messages
283: .getMessage("WCTS_TRANSFORMATION_NO_CRS_OR_TRANSFORM_KVP"),
284: ExceptionCode.MISSINGPARAMETERVALUE);
285:
286: }
287: CoordinateSystem sourceCRS = null;
288: CoordinateSystem targetCRS = null;
289: try {
290: sourceCRS = CRSFactory.create(sCRS);
291: targetCRS = CRSFactory.create(tCRS);
292: } catch (UnknownCRSException e) {
293: throw new OGCWebServiceException(e.getMessage(),
294: WCTSExceptionCode.UNSUPPORTED_COMBINATION);
295: }
296:
297: String tmp = map.get("GEOMETRYTYPES");
298: List<String> geometryTypes = new ArrayList<String>(10);
299: if (tmp != null && !"".equals(tmp.trim())) {
300: String[] splitter = tmp.split(",");
301: for (String split : splitter) {
302: if (split != null && !"".equals(split.trim())) {
303: geometryTypes.add(split.trim());
304: }
305: }
306: }
307:
308: String coverageTypes = map.get("COVERAGETYPES");
309: if (!(coverageTypes == null || "".equals(coverageTypes.trim()))) {
310: throw new OGCWebServiceException(Messages.getMessage(
311: "WCTS_OPERATION_NOT_SUPPORTED",
312: "CoverageTypes (key)"),
313: ExceptionCode.OPERATIONNOTSUPPORTED);
314: }
315:
316: String interPolationType = map.get("INTERPOLATIONTYPES");
317: if (!(interPolationType == null || "".equals(interPolationType
318: .trim()))) {
319: throw new OGCWebServiceException(Messages.getMessage(
320: "WCTS_OPERATION_NOT_SUPPORTED",
321: "InterpolationTypes (key)"),
322: ExceptionCode.OPERATIONNOTSUPPORTED);
323: }
324:
325: return new IsTransformable(version, requestID, sourceCRS,
326: targetCRS, geometryTypes);
327: }
328:
329: }
|