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.util.OwsUtils;
08: import org.geoserver.platform.Operation;
09: import org.geoserver.platform.ServiceException;
10: import org.vfny.geoserver.Request;
11: import org.vfny.geoserver.Response;
12: import org.vfny.geoserver.global.GeoServer;
13: import java.io.IOException;
14: import java.io.OutputStream;
15: import java.util.ArrayList;
16: import java.util.HashMap;
17: import java.util.List;
18:
19: /**
20: * Wraps an old style {@link Response} in a new {@link org.geoserver.ows.Response}.
21: * <p>
22: * The class binding (see {@link #getBinding()} ), is the implementation of
23: * {@link Response} which will delegated to.
24: * </p>
25: * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
26: *
27: */
28: public class ResponseAdapter extends org.geoserver.ows.Response {
29: GeoServer gs;
30:
31: public ResponseAdapter(Class delegateClass, GeoServer gs) {
32: super (delegateClass);
33:
34: this .gs = gs;
35: }
36:
37: public String getMimeType(Object value, Operation operation)
38: throws ServiceException {
39: //get the delegate
40: Response delegate = (Response) value;
41:
42: //get the requst object from the operation
43: Request request = (Request) OwsUtils.parameter(operation
44: .getParameters(), Request.class);
45:
46: //the old contract specifies that execute must be called before
47: // get content type
48: delegate.execute(request);
49:
50: //return the content type
51: return delegate.getContentType(gs);
52: }
53:
54: public void write(Object value, OutputStream output,
55: Operation operation) throws IOException, ServiceException {
56: //get the delegate
57: Response delegate = (Response) value;
58:
59: //write the response
60: delegate.writeTo(output);
61: }
62:
63: public String[][] getHeaders(Object value, Operation operation)
64: throws ServiceException {
65: Response delegate = (Response) value;
66: HashMap map = delegate.getResponseHeaders();
67: if (map == null || map.isEmpty())
68: return null;
69:
70: String[][] headers = new String[map.size()][2];
71: List keys = new ArrayList(map.keySet());
72: for (int i = 0; i < headers.length; i++) {
73: headers[i][0] = (String) keys.get(i);
74: headers[i][1] = (String) map.get(keys.get(i));
75: }
76: return headers;
77: }
78: }
|