001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/ogcwebservices/wpvs/WPVService.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: Department of Geography
036: University of Bonn
037: Meckenheimer Allee 166
038: 53115 Bonn
039: Germany
040: E-Mail: greve@giub.uni-bonn.de
041:
042: ---------------------------------------------------------------------------*/
043:
044: package org.deegree.ogcwebservices.wpvs;
045:
046: import java.lang.reflect.Constructor;
047: import java.lang.reflect.InvocationTargetException;
048: import java.util.HashMap;
049: import java.util.Set;
050: import java.util.concurrent.ConcurrentHashMap;
051:
052: import org.deegree.framework.log.ILogger;
053: import org.deegree.framework.log.LoggerFactory;
054: import org.deegree.framework.trigger.TriggerProvider;
055: import org.deegree.ogcwebservices.OGCWebService;
056: import org.deegree.ogcwebservices.OGCWebServiceException;
057: import org.deegree.ogcwebservices.OGCWebServiceRequest;
058: import org.deegree.ogcwebservices.getcapabilities.OGCCapabilities;
059: import org.deegree.ogcwebservices.wpvs.configuration.WPVSConfiguration;
060: import org.deegree.ogcwebservices.wpvs.operation.Get3DFeatureInfo;
061: import org.deegree.ogcwebservices.wpvs.operation.GetView;
062: import org.deegree.ogcwebservices.wpvs.operation.WPVSGetCapabilities;
063:
064: /**
065: * A <code>WPVService</code> deligates the clients Requests. If the rquest is an instance of
066: * GetView a (configured) GetViewHandler is instantiated to create an perspective image.
067: *
068: * @author <a href="mailto:taddei@lat-lon.de">Ugo Taddei</a>
069: * @author last edited by: $Author: rbezema $
070: *
071: * $Revision: 10559 $, $Date: 2008-03-12 01:35:07 -0700 (Wed, 12 Mar 2008) $
072: *
073: */
074: public class WPVService implements OGCWebService {
075:
076: private static final TriggerProvider TP = TriggerProvider
077: .create(WPVService.class);
078:
079: private static final ILogger LOG = LoggerFactory
080: .getLogger(WPVService.class);
081:
082: private WPVSConfiguration configuration;
083:
084: private ConcurrentHashMap<String, GetViewHandler> getViewHandlers;
085:
086: private String defaultSplitter;
087:
088: /**
089: * Creates a new instance of <code>WPVService</code> from the configuration.
090: *
091: * @param configuration
092: */
093: WPVService(WPVSConfiguration configuration) {
094: this .configuration = configuration;
095: HashMap<String, String> configuredHandlers = HandlerMapping
096: .getConfiguredGetViewHandlers();
097: Set<String> keys = configuredHandlers.keySet();
098: defaultSplitter = configuration.getDeegreeParams()
099: .getDefaultSplitter();
100: // if no defaulthandler in the configuration QUAD will be the Defaultsplitter
101: getViewHandlers = new ConcurrentHashMap<String, GetViewHandler>();
102: for (String key : keys) {
103: try {
104: getViewHandlers.put(key,
105: createHandler(configuredHandlers.get(key)));
106: } catch (OGCWebServiceException e) {
107: LOG.logError(e.getLocalizedMessage(), e);
108: }
109: }
110: // an error occurred while instantiating or no handlers in the bundle or the defaultsplitter
111: // was not in the bundle
112: if (getViewHandlers.isEmpty()
113: || !getViewHandlers.containsKey(defaultSplitter)) {
114: getViewHandlers.put(defaultSplitter,
115: new DefaultGetViewHandler(this ));
116: }
117:
118: }
119:
120: /**
121: * Returns the capabilities of this service.
122: *
123: * @return the capabilities, this is an instance of <code>WPVSCapabilities</code>
124: */
125: public OGCCapabilities getCapabilities() {
126: return this .configuration;
127: }
128:
129: /**
130: * Performs the handling of the passed OGCWebServiceEvent directly and returns the result to the
131: * calling class/ method.
132: *
133: * @param request
134: * WFS request to perform
135: *
136: * @throws OGCWebServiceException
137: */
138: public Object doService(OGCWebServiceRequest request)
139: throws OGCWebServiceException {
140:
141: request = (OGCWebServiceRequest) TP.doPreTrigger(this , request)[0];
142:
143: Object response = null;
144:
145: if (request instanceof WPVSGetCapabilities) {
146: // TODO implement partial responses (if only certain sections are requested)
147: response = getCapabilities();
148: } else if (request instanceof GetView) {
149:
150: String splitter = ((GetView) request)
151: .getVendorSpecificParameter("SPLITTER");
152: if (splitter == null || splitter.trim().equals(""))
153: splitter = defaultSplitter;
154: GetViewHandler gvh = getViewHandlers.get(splitter);
155: if (gvh == null) {
156: gvh = getViewHandlers.get(defaultSplitter);
157: }
158: // if ( "QUAD".equals( ) {
159: // gvh = createHandler( HandlerMapping.getString( "WPVService.GETVIEW.QUAD" ) );
160: // } else {
161: // gvh = createHandler( HandlerMapping.getString( "WPVService.GETVIEW.BOX" ) );
162: // }
163: response = gvh.handleRequest((GetView) request);
164:
165: } else if (request instanceof Get3DFeatureInfo) {
166: Get3DFeatureInfoHandler get3DFeatureInfoHandler = new DefaultGet3DFeatureInfoHandler(
167: this );
168: response = get3DFeatureInfoHandler
169: .handleRequest((Get3DFeatureInfo) request);
170:
171: } else {
172:
173: throw new OGCWebServiceException(getClass().getName(),
174: "Unknown request type: "
175: + request.getClass().getName());
176: }
177:
178: return TP.doPostTrigger(this , response)[0];
179: }
180:
181: @SuppressWarnings("unchecked")
182: private GetViewHandler createHandler(String className)
183: throws OGCWebServiceException {
184:
185: // describes the signature of the required constructor
186: // Class[] cl = new Class[1];
187: // cl[0] = WPVService.class;
188:
189: // set parameter to submitt to the constructor
190: // Object[] o = new Object[1];
191: // o[0] = this;
192:
193: GetViewHandler handler = null;
194:
195: try {
196: // get constructor
197: Class creator = Class.forName(className);
198: Constructor<GetViewHandler> con = creator
199: .getConstructor(WPVService.class);
200:
201: // call constructor and instantiate a new DataStore
202: handler = con.newInstance(this );
203: } catch (ClassCastException cce) {
204: throw new OGCWebServiceException("The requested class "
205: + className + " is not of type GetViewHandler! \n"
206: + cce.toString());
207: } catch (ClassNotFoundException cce) {
208: throw new OGCWebServiceException("Couldn't instantiate "
209: + className + "! \n" + cce.toString());
210: } catch (NoSuchMethodException nsme) {
211: throw new OGCWebServiceException("Couldn't instantiate "
212: + className + "! \n" + nsme.toString());
213: } catch (InstantiationException ie) {
214: throw new OGCWebServiceException("Couldn't instantiate "
215: + className + "! \n" + ie.toString());
216: } catch (IllegalAccessException iae) {
217: throw new OGCWebServiceException("Couldn't instantiate "
218: + className + "! \n" + iae.toString());
219: } catch (InvocationTargetException ite) {
220: throw (OGCWebServiceException) ite.getCause();
221: } catch (Exception e) {
222: throw new OGCWebServiceException("Couldn't instantiate "
223: + className + "! \n" + e.toString());
224: }
225:
226: return handler;
227: }
228:
229: /**
230: * Returns a GetViewHandler which is configured to handle the given kind of splitter.
231: *
232: * @param splitter
233: * the name of the splitter (supported are QUAD and BBOX)
234: * @return the configured GetViewHandler or the default GetViewHandler if the given String is
235: * null or empty or not known.
236: */
237: public GetViewHandler getGetViewHandler(String splitter) {
238: if (splitter == null || splitter.trim().equals(""))
239: return getViewHandlers.get(defaultSplitter);
240: GetViewHandler gvh = getViewHandlers.get(splitter);
241: if (gvh == null) {
242: gvh = getViewHandlers.get(defaultSplitter);
243: }
244: return gvh;
245: }
246:
247: protected WPVSConfiguration getConfiguration() {
248: return configuration;
249: }
250:
251: }
|