01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.geoserver.ows.adapters;
06:
07: import org.geoserver.ows.HttpServletRequestAware;
08: import org.vfny.geoserver.servlets.AbstractService;
09: import org.vfny.geoserver.util.requests.readers.XmlRequestReader;
10: import java.io.Reader;
11: import java.lang.reflect.Constructor;
12: import java.util.Map;
13: import javax.servlet.http.HttpServletRequest;
14: import javax.xml.namespace.QName;
15:
16: public class XmlRequestReaderAdapter extends
17: org.geoserver.ows.XmlRequestReader implements
18: HttpServletRequestAware {
19: Class delegateClass;
20: AbstractService service;
21: HttpServletRequest httpRequest;
22:
23: public XmlRequestReaderAdapter(QName element,
24: AbstractService service, Class delegate) {
25: super (element);
26: this .service = service;
27: this .delegateClass = delegate;
28: }
29:
30: public XmlRequestReaderAdapter(String namespace, String local,
31: AbstractService service, Class delegate) {
32: this (new QName(namespace, local), service, delegate);
33: }
34:
35: public void setHttpRequest(HttpServletRequest request) {
36: this .httpRequest = request;
37: }
38:
39: public Object read(Object request, Reader reader, Map kvp)
40: throws Exception {
41: //look for a constructor, may have to walk up teh class hierachy
42: Class clazz = service.getClass();
43: Constructor constructor = null;
44:
45: while (clazz != null) {
46: try {
47: constructor = delegateClass
48: .getConstructor(new Class[] { clazz });
49:
50: break;
51: } catch (NoSuchMethodException e) {
52: clazz = clazz.getSuperclass();
53: }
54: }
55:
56: if (constructor == null) {
57: throw new IllegalStateException(
58: "No appropriate constructor");
59: }
60:
61: XmlRequestReader delegate = (XmlRequestReader) constructor
62: .newInstance(new Object[] { service });
63:
64: return delegate.read(reader, httpRequest);
65: }
66: }
|