001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.vfny.geoserver.wms.responses.featureInfo;
006:
007: import java.util.List;
008:
009: import org.opengis.filter.Filter;
010: import org.vfny.geoserver.Request;
011: import org.vfny.geoserver.Response;
012: import org.vfny.geoserver.ServiceException;
013: import org.vfny.geoserver.global.MapLayerInfo;
014: import org.vfny.geoserver.global.Service;
015: import org.vfny.geoserver.wms.WmsException;
016: import org.vfny.geoserver.wms.requests.GetFeatureInfoRequest;
017:
018: /**
019: * Base class for GetFeatureInfo delegates responsible of creating
020: * GetFeatureInfo responses in different formats.
021: *
022: * <p>
023: * Subclasses should implement one or more output formats, wich will be
024: * returned in a list of mime type strings in
025: * <code>getSupportedFormats</code>. For example, a subclass can be created to
026: * write one of the following output formats:
027: *
028: * <ul>
029: * <li>
030: * text/plain
031: * </li>
032: * <li>
033: * text/html
034: * </li>
035: * </ul>
036: * </p>
037: *
038: * <p>
039: * This abstract class takes care of executing the request in the sense of
040: * taking the GetFeatureInfo request parameters such as query_layers, bbox, x,
041: * y, etc., create the gt2 query objects for each featuretype and executing
042: * it. This process leads to a set of FeatureResults objects and its metadata,
043: * wich will be given to the <code>execute(FeatureTypeInfo[] ,
044: * FeatureResults[])</code> method, that a subclass should implement as a
045: * matter of setting up any resource/state it needs to later encoding.
046: * </p>
047: *
048: * <p>
049: * So, it should be enough to a subclass to implement the following methods in
050: * order to produce the requested output format:
051: *
052: * <ul>
053: * <li>
054: * execute(FeatureTypeInfo[], FeatureResults[], int, int)
055: * </li>
056: * <li>
057: * canProduce(String mapFormat)
058: * </li>
059: * <li>
060: * getSupportedFormats()
061: * </li>
062: * <li>
063: * writeTo(OutputStream)
064: * </li>
065: * </ul>
066: * </p>
067: *
068: * @author Gabriel Roldan, Axios Engineering
069: * @author Chris Holmes
070: * @version $Id: GetFeatureInfoDelegate.java 8418 2008-02-18 14:47:17Z aaime $
071: */
072: public abstract class GetFeatureInfoDelegate implements Response {
073: /** DOCUMENT ME! */
074: private GetFeatureInfoRequest request;
075:
076: /**
077: * Creates a new GetMapDelegate object.
078: */
079: public GetFeatureInfoDelegate() {
080: }
081:
082: /**
083: * Executes a Request, which must be a GetMapRequest. Any other will cause
084: * a class cast exception.
085: *
086: * @param request A valid GetMapRequest.
087: *
088: * @throws ServiceException If the request can not be executed.
089: */
090: public void execute(Request request) throws ServiceException {
091: execute((GetFeatureInfoRequest) request);
092: }
093:
094: /**
095: * Executes a GetFeatureInfo request. Builds the proper objects from the
096: * request names.
097: *
098: * @param request A valid GetMapRequest.
099: *
100: * @throws WmsException If anything goes wrong.
101: */
102: protected void execute(GetFeatureInfoRequest request)
103: throws WmsException {
104: this .request = request;
105:
106: //use the layer of the QUERY_LAYERS parameter, not the LAYERS one
107: MapLayerInfo[] layers = request.getQueryLayers();
108:
109: List filterList = request.getGetMapRequest().getFilter();
110: Filter[] filters;
111:
112: if (filterList != null) {
113: filters = (Filter[]) filterList
114: .toArray(new Filter[filterList.size()]);
115: } else {
116: filters = new Filter[layers.length];
117: }
118:
119: int x = request.getXPixel();
120: int y = request.getYPixel();
121: execute(layers, filters, x, y);
122: }
123:
124: /**
125: * DOCUMENT ME!
126: *
127: * @param gs DOCUMENT ME!
128: */
129: public void abort(Service gs) {
130: }
131:
132: /**
133: * Execute method for concrete children to implement. Each param is an
134: * array in the order things should be processed.
135: *
136: * @param requestedLayers Array of config information of the FeatureTypes
137: * to be processed.
138: * @param queries Matching array of layer definition filters
139: * @param x the X coordinate in pixels where the identification must be
140: * done relative to the image dimensions
141: * @param y the Y coordinate in pixels where the identification must be
142: * done relative to the image dimensions
143: *
144: * @throws WmsException For any problems executing.
145: */
146: protected abstract void execute(MapLayerInfo[] requestedLayers,
147: Filter[] filters, int x, int y) throws WmsException;
148:
149: /**
150: * Gets the map request. Used by delegate children to find out more
151: * information about the request.
152: *
153: * @return The request to be processed.
154: */
155: protected GetFeatureInfoRequest getRequest() {
156: return this .request;
157: }
158:
159: /**
160: * Evaluates if this GetFeatureInfo producer can generate the map format
161: * specified by <code>mapFormat</code>, where <code>mapFormat</code> is
162: * the MIME type of the requested response.
163: *
164: * @param mapFormat the MIME type of the output map format requiered
165: *
166: * @return true if class can produce a map in the passed format
167: */
168: public boolean canProduce(String mapFormat) {
169: return getSupportedFormats().contains(mapFormat);
170: }
171:
172: /**
173: * Gets A list of the formats this delegate supports.
174: *
175: * @return A list of strings of the formats supported.
176: */
177: public abstract List getSupportedFormats();
178: }
|