001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/model/coverage/grid/AbstractGridCoverageWriter.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 by:
006: EXSE, Department of Geography, University of Bonn
007: http://www.giub.uni-bonn.de/deegree/
008: lat/lon GmbH
009: http://www.lat-lon.de
010:
011: This library is free software; you can redistribute it and/or
012: modify it under the terms of the GNU Lesser General Public
013: License as published by the Free Software Foundation; either
014: version 2.1 of the License, or (at your option) any later version.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: Contact:
026:
027: Andreas Poth
028: lat/lon GmbH
029: Aennchenstr. 19
030: 53115 Bonn
031: Germany
032: E-Mail: poth@lat-lon.de
033:
034: Klaus Greve
035: Department of Geography
036: University of Bonn
037: Meckenheimer Allee 166
038: 53115 Bonn
039: Germany
040: E-Mail: klaus.greve@uni-bonn.de
041:
042:
043: ---------------------------------------------------------------------------*/
044: package org.deegree.model.coverage.grid;
045:
046: import java.io.IOException;
047: import java.util.HashMap;
048: import java.util.Map;
049:
050: /**
051: * @version $Revision: 9343 $
052: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
053: * @author last edited by: $Author: apoth $
054: *
055: * @version 1.0. $Revision: 9343 $, $Date: 2007-12-27 05:30:32 -0800 (Thu, 27 Dec 2007) $
056: *
057: * @since 2.0
058: */
059:
060: public abstract class AbstractGridCoverageWriter implements
061: GridCoverageWriter {
062:
063: protected Object destination = null;
064:
065: protected Map<String, Object> metadata = new HashMap<String, Object>();
066:
067: private String[] subNames = null;
068:
069: private String currentSubname = null;
070:
071: protected Format format = null;
072:
073: /**
074: * @param destination
075: * @param metadata
076: * @param subNames
077: * @param currentSubname
078: * @param format
079: */
080: public AbstractGridCoverageWriter(Object destination,
081: Map<String, Object> metadata, String[] subNames,
082: String currentSubname, Format format) {
083: this .destination = destination;
084: this .metadata = metadata;
085: this .subNames = subNames;
086: this .currentSubname = currentSubname;
087: this .format = format;
088: }
089:
090: /**
091: * Returns the format handled by this <code>GridCoverageWriter</code>.
092: */
093: public Format getFormat() {
094: return format;
095: }
096:
097: /**
098: * Returns the output destination. This is the object passed to the
099: * {@link org.opengis.coverage.grid.GridCoverageExchange#getWriter} method. It can be a
100: * {@link java.lang.String}, an {@link java.io.OutputStream}, a
101: * {@link java.nio.channels.FileChannel}, etc.
102: */
103: public Object getDestination() {
104: return destination;
105: }
106:
107: /**
108: * Returns the list of metadata keywords associated with the {@linkplain #getDestination output
109: * destination} as a whole (not associated with any particular grid coverage). If no metadata is
110: * allowed, the array will be empty.
111: *
112: * @return The list of metadata keywords for the output destination.
113: *
114: * @revisit This javadoc may not apply thats well in the iterator scheme.
115: */
116: public String[] getMetadataNames() {
117: return metadata.keySet().toArray(new String[metadata.size()]);
118: }
119:
120: /**
121: * Retrieve the metadata value for a given metadata name.
122: *
123: * @param name
124: * Metadata keyword for which to retrieve metadata.
125: * @return The metadata value for the given metadata name. Should be one of the name returned by
126: * {@link #getMetadataNames}.
127: * @throws IOException
128: * if an error occurs during reading.
129: * @throws MetadataNameNotFoundException
130: * if there is no value for the specified metadata name.
131: *
132: * @revisit This javadoc may not apply thats well in the iterator scheme.
133: */
134: public Object getMetadataValue(String name) throws IOException,
135: MetadataNameNotFoundException {
136: return metadata.get(name);
137: }
138:
139: /**
140: * Sets the metadata value for a given metadata name.
141: *
142: * @param name
143: * Metadata keyword for which to set the metadata.
144: * @param value
145: * The metadata value for the given metadata name.
146: * @throws IOException
147: * if an error occurs during writing.
148: * @throws MetadataNameNotFoundException
149: * if the specified metadata name is not handled for this format.
150: *
151: * @revisit This javadoc may not apply thats well in the iterator scheme.
152: */
153: public void setMetadataValue(String name, String value)
154: throws IOException, MetadataNameNotFoundException {
155: metadata.put(name, value);
156: }
157:
158: /**
159: * Retrieve the list of grid coverages contained within the {@linkplain #getDestination() input
160: * source}. Each grid can have a different coordinate system, number of dimensions and grid
161: * geometry. For example, a HDF-EOS file (GRID.HDF) contains 6 grid coverages each having a
162: * different projection. An empty array will be returned if no sub names exist.
163: *
164: * @return The list of grid coverages contained within the input source.
165: * @throws IOException
166: * if an error occurs during reading.
167: *
168: * @revisit The javadoc should also be more explicit about hierarchical format. Should the names
169: * be returned as paths? Explain what to return if the GridCoverage are accessible by
170: * index only. A proposal is to name them "grid1", "grid2", etc.
171: */
172: public String[] listSubNames() throws IOException {
173: return subNames;
174: }
175:
176: /**
177: * Returns the name for the next grid coverage to be read from the
178: * {@linkplain #getDestination() output destination}.
179: *
180: * @throws IOException
181: * if an error occurs during reading.
182: * @revisit Do we need a special method for that, or should it be a metadata?
183: */
184: public String getCurrentSubname() throws IOException {
185: return currentSubname;
186: }
187:
188: /**
189: * Set the name for the next grid coverage to GridCoverageWriter.write(GridCoverage,
190: * GeneralParameterValue[]) within the{@linkplain #getDestination output destination}. The
191: * subname can been fetch later at reading time.
192: *
193: * @throws IOException
194: * if an error occurs during writing.
195: * @revisit Do we need a special method for that, or should it be a metadata?
196: */
197: public void setCurrentSubname(String name) throws IOException {
198: currentSubname = name;
199: }
200:
201: }
|