001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/sos/SOService.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 Aennchenstraße 19 030 53177 Bonn 031 Germany 032 E-Mail: poth@lat-lon.de 033 034 Prof. Dr. Klaus Greve 035 lat/lon GmbH 036 Aennchenstraße 19 037 53177 Bonn 038 Germany 039 E-Mail: greve@giub.uni-bonn.de 040 041 ---------------------------------------------------------------------------*/ 042 package org.deegree.ogcwebservices.sos; 043 044 import java.io.IOException; 045 046 import javax.xml.transform.TransformerException; 047 048 import org.deegree.framework.log.ILogger; 049 import org.deegree.framework.log.LoggerFactory; 050 import org.deegree.framework.trigger.TriggerProvider; 051 import org.deegree.framework.xml.XMLParsingException; 052 import org.deegree.ogcwebservices.InvalidParameterValueException; 053 import org.deegree.ogcwebservices.OGCWebService; 054 import org.deegree.ogcwebservices.OGCWebServiceException; 055 import org.deegree.ogcwebservices.OGCWebServiceRequest; 056 import org.deegree.ogcwebservices.getcapabilities.OGCCapabilities; 057 import org.deegree.ogcwebservices.sos.capabilities.SOSGetCapabilities; 058 import org.deegree.ogcwebservices.sos.configuration.SOSConfiguration; 059 import org.deegree.ogcwebservices.sos.configuration.SOSDeegreeParams; 060 import org.deegree.ogcwebservices.sos.describeplatform.DescribePlatformRequest; 061 import org.deegree.ogcwebservices.sos.describeplatform.DescribePlatformResult; 062 import org.deegree.ogcwebservices.sos.describeplatform.PlatformDescriptionDocument; 063 import org.deegree.ogcwebservices.sos.describeplatform.PlatformMetadata; 064 import org.deegree.ogcwebservices.sos.describesensor.DescribeSensorRequest; 065 import org.deegree.ogcwebservices.sos.describesensor.DescribeSensorResult; 066 import org.deegree.ogcwebservices.sos.describesensor.SensorDescriptionDocument; 067 import org.deegree.ogcwebservices.sos.describesensor.SensorMetadata; 068 import org.deegree.ogcwebservices.sos.getobservation.GetObservationDocument; 069 import org.deegree.ogcwebservices.sos.getobservation.GetObservationRequest; 070 import org.deegree.ogcwebservices.sos.getobservation.GetObservationResult; 071 import org.deegree.ogcwebservices.sos.om.ObservationArray; 072 import org.xml.sax.SAXException; 073 074 /** 075 * @author <a href="mailto:mkulbe@lat-lon.de">Matthias Kulbe </a> 076 * @author last edited by: $Author: apoth $ 077 * 078 * @version $Revision: 9345 $, $Date: 2007-12-27 17:22:25 +0100 (Do, 27 Dez 2007) $ 079 */ 080 public class SOService implements OGCWebService { 081 082 private SOSConfiguration serviceConfiguration; 083 084 private static final ILogger LOG = LoggerFactory.getLogger( SOService.class ); 085 086 private static final TriggerProvider TP = TriggerProvider.create( SOService.class ); 087 088 /** 089 * static create method to create a new instance of the SCService 090 * 091 * @param scsConfiguration 092 * 093 */ 094 public static SOService create( SOSConfiguration scsConfiguration ) { 095 return new SOService( scsConfiguration ); 096 097 } 098 099 /** 100 * privater constructor to construct a new SCService instance with the configuration as the only 101 * parameter 102 * 103 * @param scsConfiguration 104 * 105 */ 106 private SOService( SOSConfiguration scsConfiguration ) { 107 this.serviceConfiguration = scsConfiguration; 108 } 109 110 /** 111 * returns the ServiceTypeId from the ServiceIdentification section of the configuration 112 * 113 * @return the ServiceTypeId from the ServiceIdentification section of the configuration 114 */ 115 public String getServiceTypeId() { 116 return this.serviceConfiguration.getServiceIdentification().getServiceType().getCode(); 117 118 } 119 120 /** 121 * returns the Version from the configuration 122 * 123 * @return the Version from the configuration 124 */ 125 public String getVersion() { 126 return serviceConfiguration.getVersion(); 127 } 128 129 /** 130 * returns the serviceConfiguration 131 * 132 * @return the serviceConfiguration 133 */ 134 public OGCCapabilities getCapabilities() { 135 return this.serviceConfiguration; 136 } 137 138 /** 139 * checks the request and do service 140 * 141 * @throws OGCWebServiceException 142 */ 143 public Object doService( OGCWebServiceRequest request ) 144 throws OGCWebServiceException { 145 146 request = (OGCWebServiceRequest) TP.doPreTrigger( this, request )[0]; 147 148 Object response = null; 149 try { 150 if ( request instanceof SOSGetCapabilities ) { 151 LOG.logDebug( "-> GetCapabilities received" ); 152 response = this.getCapabilities(); 153 } else if ( request instanceof DescribePlatformRequest ) { 154 LOG.logDebug( "-> DescribePlatform received" ); 155 response = this.describePlatform( (DescribePlatformRequest) request ); 156 } else if ( request instanceof DescribeSensorRequest ) { 157 LOG.logDebug( "-> DescribeSensor received" ); 158 response = this.describeSensor( (DescribeSensorRequest) request ); 159 } else if ( request instanceof GetObservationRequest ) { 160 LOG.logDebug( "-> GetObservation received" ); 161 response = this.getObservation( (GetObservationRequest) request ); 162 } else { 163 throw new InvalidParameterValueException( "not a valid scs request" ); 164 } 165 } catch ( Exception e ) { 166 LOG.logError( e.getMessage(), e ); 167 throw new OGCWebServiceException( "SOS Failure\n" + e.getMessage() ); 168 } 169 170 return TP.doPostTrigger( this, response )[0]; 171 } 172 173 /** 174 * returns a DescribePlatformResult 175 * 176 * @param request 177 * @return a DescribePlatformResult 178 * @throws InvalidParameterValueException 179 * @throws OGCWebServiceException 180 */ 181 private DescribePlatformResult describePlatform( DescribePlatformRequest request ) 182 throws InvalidParameterValueException, OGCWebServiceException { 183 184 // validate the requested platforms 185 String[] types = request.getTypeNames(); 186 187 for ( int i = 0; i < types.length; i++ ) { 188 if ( serviceConfiguration.getSOSDeegreeParams().getPlatformConfiguration( types[i] ) == null ) { 189 throw new OGCWebServiceException( "InvalidParameterValueException: Platform '" + types[i] 190 + "' not found" ); 191 } 192 } 193 194 PlatformDescriptionDocument pdd = new PlatformDescriptionDocument(); 195 PlatformMetadata[] pm = pdd.getPlatform( serviceConfiguration.getSOSDeegreeParams(), types ); 196 197 return new DescribePlatformResult( request, pm ); 198 } 199 200 /** 201 * returns a DescribeSensorResult 202 * 203 * @param request 204 * @return a DescribeSensorResult 205 * @throws InvalidParameterValueException 206 * @throws OGCWebServiceException 207 */ 208 private DescribeSensorResult describeSensor( DescribeSensorRequest request ) 209 throws InvalidParameterValueException, OGCWebServiceException { 210 211 // validate the requested sensors 212 String[] types = request.getTypeNames(); 213 214 for ( int i = 0; i < types.length; i++ ) { 215 if ( serviceConfiguration.getSOSDeegreeParams().getSensorConfiguration( types[i] ) == null ) { 216 throw new OGCWebServiceException( "InvalidParameterValueException: Sensor '" + types[i] + "' not found" ); 217 } 218 } 219 220 SensorDescriptionDocument sdd = new SensorDescriptionDocument(); 221 SensorMetadata[] sensors = sdd.getSensor( serviceConfiguration.getSOSDeegreeParams(), request.getTypeNames() ); 222 return new DescribeSensorResult( request, sensors ); 223 224 } 225 226 /** 227 * returns a GetObservationResult 228 * 229 * @param request 230 * @return a GetObservationResult 231 * @throws OGCWebServiceException 232 * @throws XMLParsingException 233 * @throws IOException 234 * @throws SAXException 235 * @throws TransformerException 236 */ 237 private GetObservationResult getObservation( GetObservationRequest request ) 238 throws OGCWebServiceException, XMLParsingException, TransformerException, IOException, 239 SAXException { 240 241 SOSDeegreeParams dp = serviceConfiguration.getSOSDeegreeParams(); 242 243 // validate the requested platforms 244 String[] platforms = request.getPlatforms(); 245 for ( int i = 0; i < platforms.length; i++ ) { 246 if ( dp.getPlatformConfiguration( platforms[i] ) == null ) { 247 throw new OGCWebServiceException( "InvalidParameterValueException: Platform '" + platforms[i] 248 + "' not found" ); 249 } 250 } 251 252 // validate the requested sensors 253 String[] sensors = request.getSensors(); 254 for ( int i = 0; i < sensors.length; i++ ) { 255 if ( dp.getSensorConfiguration( sensors[i] ) == null ) { 256 throw new OGCWebServiceException( "InvalidParameterValueException: Sensor '" + sensors[i] 257 + "' not found" ); 258 } 259 } 260 261 GetObservationDocument god = new GetObservationDocument(); 262 ObservationArray[] obAr = god.getObservations( serviceConfiguration.getSOSDeegreeParams(), request ); 263 return new GetObservationResult( request, obAr ); 264 } 265 }