001 //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/portal/standard/sos/control/DescribePlatformListener.java $ 002 003 /*---------------------------------------------------------------------------- 004 This file is part of deegree, http://deegree.org/ 005 Copyright (C) 2001-2009 by: 006 Department of Geography, University of Bonn 007 and 008 lat/lon GmbH 009 010 This library is free software; you can redistribute it and/or modify it under 011 the terms of the GNU Lesser General Public License as published by the Free 012 Software Foundation; either version 2.1 of the License, or (at your option) 013 any later version. 014 This library is distributed in the hope that it will be useful, but WITHOUT 015 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 016 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 017 details. 018 You should have received a copy of the GNU Lesser General Public License 019 along with this library; if not, write to the Free Software Foundation, Inc., 020 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 021 022 Contact information: 023 024 lat/lon GmbH 025 Aennchenstr. 19, 53177 Bonn 026 Germany 027 http://lat-lon.de/ 028 029 Department of Geography, University of Bonn 030 Prof. Dr. Klaus Greve 031 Postfach 1147, 53001 Bonn 032 Germany 033 http://www.geographie.uni-bonn.de/deegree/ 034 035 e-mail: info@deegree.org 036 ----------------------------------------------------------------------------*/ 037 package org.deegree.portal.standard.sos.control; 038 039 import java.util.HashMap; 040 import java.util.Iterator; 041 042 import org.deegree.enterprise.control.RPCMethodCall; 043 import org.deegree.enterprise.control.RPCParameter; 044 import org.deegree.enterprise.control.RPCStruct; 045 import org.deegree.framework.log.ILogger; 046 import org.deegree.framework.log.LoggerFactory; 047 import org.deegree.framework.xml.NamespaceContext; 048 import org.deegree.framework.xml.XMLTools; 049 import org.deegree.ogcbase.CommonNamespaces; 050 import org.deegree.ogcwebservices.sos.describeplatform.PlatformMetadata; 051 import org.deegree.ogcwebservices.sos.sensorml.Classifier; 052 import org.deegree.ogcwebservices.sos.sensorml.ComponentDescription; 053 import org.deegree.ogcwebservices.sos.sensorml.EngineeringCRS; 054 import org.deegree.ogcwebservices.sos.sensorml.GeoPositionModel; 055 import org.deegree.ogcwebservices.sos.sensorml.GeographicCRS; 056 import org.deegree.ogcwebservices.sos.sensorml.Identifier; 057 import org.deegree.ogcwebservices.sos.sensorml.LocationModel; 058 import org.deegree.portal.standard.sos.Constants; 059 import org.deegree.portal.standard.sos.SOSClientException; 060 import org.w3c.dom.Document; 061 import org.w3c.dom.Element; 062 063 /** 064 * Listener for performing DescribePlatform requests against Sensor Observation Services. 065 * 066 * @author <a href="mailto:che@wupperverband.de.de">Christian Heier</a> 067 * @version 0.1 068 */ 069 public class DescribePlatformListener extends AbstractSOSListener { 070 071 private static final NamespaceContext nsContext = CommonNamespaces.getNamespaceContext(); 072 073 private static final ILogger LOG = LoggerFactory.getLogger( DescribePlatformListener.class ); 074 075 /** 076 * validates the request to be performed. 077 * 078 * @param mc 079 * object containing the request to be performed 080 */ 081 @Override 082 protected void validateRequest( RPCMethodCall mc ) 083 throws SOSClientException { 084 RPCParameter[] params = mc.getParameters(); 085 if ( params == null || params.length != 1 ) { 086 throw new SOSClientException( "one rpc parameter containing a struct " 087 + "with requiered parameters must be set" ); 088 } 089 RPCStruct struct = (RPCStruct) params[0].getValue(); 090 if ( struct.getMember( Constants.TYPENAME ) == null ) { 091 // TODO "".equals( type value ) 092 throw new SOSClientException( "TypeName parameter must be set " 093 + "to perform a Sensor Observation Service " + "DescribePlatform request" ); 094 } 095 096 } 097 098 /** 099 * creates a SOS DescribePlatform request from the parameters contained in the passed 100 * <tt>RPCMethodeCall</tt>. 101 * 102 * @param mc 103 * the RPCMethodCall 104 * @return SOS DescribePlatform request 105 * @throws SOSClientException 106 */ 107 @Override 108 protected String createRequest( RPCMethodCall mc ) 109 throws SOSClientException { 110 111 RPCParameter[] params = mc.getParameters(); 112 RPCStruct struct = (RPCStruct) params[0].getValue(); 113 114 StringBuffer sb = new StringBuffer( 1000 ); 115 sb.append( "<sos:DescribePlatform " ); 116 sb.append( "xmlns:sos='http://www.opengis.net/sos' " ); 117 sb.append( "outputFormat='SensorML' " ); 118 sb.append( "service='SOS' " ); 119 sb.append( "version='0.8.0'>" ); 120 sb.append( "<sos:TypeName>" ); 121 sb.append( struct.getMember( Constants.TYPENAME ).getValue() ); 122 sb.append( "</sos:TypeName>" ); 123 sb.append( "</sos:DescribePlatform>" ); 124 return sb.toString(); 125 } 126 127 /** 128 * creates the result object to send to the next page from the parameters contained in the 129 * passed <tt>RPCMethodeCall</tt> and the <tt>Document</tt> array. 130 * 131 * @param mc 132 * the RPCMethodCall 133 * @param map 134 * the Document array 135 * @return the data. 136 */ 137 @Override 138 protected Object createData( RPCMethodCall mc, HashMap<String, Document> map ) 139 throws SOSClientException { 140 141 Identifier[] identifiedAs = null; 142 Classifier[] classifiedAs = null; 143 EngineeringCRS engineerCRS = null; 144 LocationModel[] locatedUsing = null; 145 ComponentDescription describedBy = null; 146 String attachedTo = null; 147 String[] carries = null; 148 149 PlatformMetadata[] platformDescriptions = new PlatformMetadata[map.size()]; 150 151 int i = 0; 152 try { 153 Iterator<String> iterator = map.keySet().iterator(); 154 while ( iterator.hasNext() ) { 155 156 String key = iterator.next(); 157 Element e = map.get( key ).getDocumentElement(); 158 159 String[] ids = XMLTools.getNodesAsStrings( 160 e, 161 "/sml:Platforms/sml:Platform/sml:identifiedAs/sml:Identifier", 162 nsContext ); 163 164 identifiedAs = new Identifier[ids.length]; 165 for ( int j = 0; j < ids.length; j++ ) { 166 identifiedAs[i] = new Identifier( ids[i] ); 167 } 168 169 String srcSRS = XMLTools.getNodeAsString( 170 e, 171 "/sml:Platforms/sml:Platform/sml:locatedUsing/sml:GeoPositionModel/sml:sourceCRS/gml:EngineeringCRS/gml:srsName", 172 nsContext, null ); 173 174 String refSRS = XMLTools.getNodeAsString( 175 e, 176 "/sml:Platforms/sml:Platform/sml:locatedUsing/sml:GeoPositionModel/sml:sourceCRS/gml:GeographicCRS/gml:srsName", 177 nsContext, null ); 178 179 locatedUsing = new LocationModel[1]; 180 locatedUsing[0] = new GeoPositionModel( null, null, null, null, new EngineeringCRS( srcSRS ), 181 new GeographicCRS( refSRS ), new Object[0] ); 182 183 carries = XMLTools.getNodesAsStrings( e, "/sml:Platforms/sml:Platform/sml:carries/sml:Asset", nsContext ); 184 185 platformDescriptions[i] = new PlatformMetadata( identifiedAs, classifiedAs, engineerCRS, locatedUsing, 186 describedBy, attachedTo, carries ); 187 188 i++; 189 } 190 191 } catch ( Exception e ) { 192 LOG.logError( "Error creating platform descriptions: " + e.getMessage() ); 193 throw new SOSClientException( "Couldn't create platform descriptions", e ); 194 } 195 return platformDescriptions; 196 } 197 198 @Override 199 protected void setNextPageData( Object o ) { 200 this.getRequest().setAttribute( Constants.PLATFORMDESCRIPTION, o ); 201 } 202 203 }