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.vfny.geoserver.wcs.responses;
06:
07: import org.vfny.geoserver.wcs.responses.coverage.AscCoverageResponseDelegate;
08: import org.vfny.geoserver.wcs.responses.coverage.GTopo30CoverageResponseDelegate;
09: import org.vfny.geoserver.wcs.responses.coverage.GeoTIFFCoverageResponseDelegate;
10: import org.vfny.geoserver.wcs.responses.coverage.IMGCoverageResponseDelegate;
11: import java.util.Iterator;
12: import java.util.LinkedList;
13: import java.util.List;
14: import java.util.NoSuchElementException;
15:
16: /**
17: * DOCUMENT ME!
18: *
19: * @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $ (last
20: * modification)
21: * @author $Author: Simone Giannecchini (simboss1@gmail.com) $ (last
22: * modification)
23: */
24: public class CoverageResponseDelegateFactory {
25: /** DOCUMENT ME! */
26: private static final List encoders = new LinkedList();
27:
28: static {
29: encoders.add(new AscCoverageResponseDelegate());
30: encoders.add(new IMGCoverageResponseDelegate());
31: encoders.add(new GTopo30CoverageResponseDelegate());
32: encoders.add(new GeoTIFFCoverageResponseDelegate());
33: }
34:
35: private CoverageResponseDelegateFactory() {
36: }
37:
38: /**
39: * Creates an encoder for a specific getfeature results output format
40: *
41: * @param outputFormat
42: * DOCUMENT ME!
43: *
44: * @return DOCUMENT ME!
45: *
46: * @throws NoSuchElementException
47: * DOCUMENT ME!
48: */
49: public static CoverageResponseDelegate encoderFor(
50: String outputFormat) throws NoSuchElementException {
51: CoverageResponseDelegate encoder = null;
52:
53: for (Iterator it = encoders.iterator(); it.hasNext();) {
54: encoder = (CoverageResponseDelegate) it.next();
55:
56: if (encoder.canProduce(outputFormat)) {
57: try {
58: if (encoder != null) {
59: return (CoverageResponseDelegate) encoder
60: .getClass().newInstance();
61: }
62: } catch (IllegalAccessException ex) {
63: final NoSuchElementException e = new NoSuchElementException(
64: new StringBuffer(
65: "Can't create the encoder ")
66: .append(
67: encoder.getClass()
68: .getName())
69: .toString());
70: e.initCause(ex);
71: throw e;
72: } catch (InstantiationException ex) {
73: final NoSuchElementException e = new NoSuchElementException(
74: new StringBuffer(
75: "Can't create the encoder ")
76: .append(
77: encoder.getClass()
78: .getName())
79: .toString());
80: e.initCause(ex);
81: throw e;
82: }
83: }
84: }
85:
86: throw new NoSuchElementException(new StringBuffer(
87: "Can't create the encoder ").append(
88: encoder.getClass().getName()).toString());
89: }
90: }
|