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