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;
006:
007: import org.vfny.geoserver.ServiceException;
008: import org.vfny.geoserver.config.WMSConfig;
009: import org.vfny.geoserver.global.WMS;
010: import org.vfny.geoserver.wms.GetMapProducer;
011: import org.vfny.geoserver.wms.GetMapProducerFactorySpi;
012: import org.vfny.geoserver.wms.WMSMapContext;
013: import org.vfny.geoserver.wms.WmsException;
014: import java.io.IOException;
015: import java.io.OutputStream;
016: import java.util.Collections;
017: import java.util.Map;
018: import java.util.Set;
019:
020: /**
021: * A GetMapProducerFactorySpi just for testing GetMapResponse without depending
022: * on a real one.
023: *
024: * @author Gabriel Roldan, Axios Engineering
025: * @version $Id: TestMapProducerFactory.java 7467 2007-08-28 22:29:03Z afabiani $
026: */
027: public class TestMapProducerFactory implements GetMapProducerFactorySpi {
028: /** a fictional image format mime type this factory claims to support */
029: public static final String TESTING_MIME_TYPE = "image/unit+testing";
030:
031: /**
032: * whether an instance returns it is available or not. Set from inside
033: * GetMapResponseTest.
034: */
035: public static boolean available = true;
036:
037: /**
038: * DOCUMENT ME!
039: *
040: * @return DOCUMENT ME!
041: */
042: public String getName() {
043: return "GetMapProducerFactorySpi for unit testing GetMapResponse only";
044: }
045:
046: /**
047: * DOCUMENT ME!
048: *
049: * @return DOCUMENT ME!
050: */
051: public Set getSupportedFormats() {
052: return Collections.singleton(TESTING_MIME_TYPE);
053: }
054:
055: /**
056: * DOCUMENT ME!
057: *
058: * @return DOCUMENT ME!
059: */
060: public boolean isAvailable() {
061: return true;
062: }
063:
064: /**
065: * DOCUMENT ME!
066: *
067: * @param mapFormat DOCUMENT ME!
068: *
069: * @return DOCUMENT ME!
070: */
071: public boolean canProduce(String mapFormat) {
072: return TESTING_MIME_TYPE.equals(mapFormat);
073: }
074:
075: /**
076: * DOCUMENT ME!
077: *
078: * @param mapFormat DOCUMENT ME!
079: *
080: * @return DOCUMENT ME!
081: *
082: * @throws IllegalArgumentException DOCUMENT ME!
083: */
084: public GetMapProducer createMapProducer(String mapFormat, WMS wms)
085: throws IllegalArgumentException {
086: if (!canProduce(mapFormat)) {
087: throw new IllegalArgumentException();
088: }
089:
090: return new TestingMapProducer();
091: }
092:
093: /**
094: * DOCUMENT ME!
095: *
096: * @author Gabriel Roldan, Axios Engineering
097: * @version $Id: TestMapProducerFactory.java 7467 2007-08-28 22:29:03Z afabiani $
098: */
099: private class TestingMapProducer extends AbstractGetMapProducer
100: implements GetMapProducer {
101: /**
102: * DOCUMENT ME!
103: *
104: * @param map DOCUMENT ME!
105: *
106: * @throws WmsException DOCUMENT ME!
107: */
108: public void produceMap() throws WmsException {
109: }
110:
111: /**
112: * DOCUMENT ME!
113: *
114: * @param out DOCUMENT ME!
115: *
116: * @throws ServiceException DOCUMENT ME!
117: * @throws IOException DOCUMENT ME!
118: */
119: public void writeTo(OutputStream out) throws ServiceException,
120: IOException {
121: }
122:
123: /**
124: * DOCUMENT ME!
125: *
126: * @return DOCUMENT ME!
127: *
128: * @throws IllegalStateException DOCUMENT ME!
129: */
130: public String getContentType() throws IllegalStateException {
131: return TestMapProducerFactory.TESTING_MIME_TYPE;
132: }
133:
134: /**
135: * DOCUMENT ME!
136: */
137: public void abort() {
138: }
139:
140: public String getContentDisposition() {
141: // can be null
142: return null;
143: }
144: }
145:
146: /* (non-Javadoc)
147: * @see org.geotools.factory.Factory#getImplementationHints()
148: * This just returns java.util.Collections.EMPTY_MAP
149: */
150: public Map getImplementationHints() {
151: return java.util.Collections.EMPTY_MAP;
152: }
153: }
|