001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/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 14:30:32 +0100 (Do, 27 Dez 2007) $
056 *
057 * @since 2.0
058 */
059
060 public abstract class AbstractGridCoverageWriter implements GridCoverageWriter {
061
062 protected Object destination = null;
063
064 protected Map<String, Object> metadata = new HashMap<String, Object>();
065
066 private String[] subNames = null;
067
068 private String currentSubname = null;
069
070 protected Format format = null;
071
072 /**
073 * @param destination
074 * @param metadata
075 * @param subNames
076 * @param currentSubname
077 * @param format
078 */
079 public AbstractGridCoverageWriter( Object destination, Map<String, Object> metadata, String[] subNames,
080 String currentSubname, Format format ) {
081 this.destination = destination;
082 this.metadata = metadata;
083 this.subNames = subNames;
084 this.currentSubname = currentSubname;
085 this.format = format;
086 }
087
088 /**
089 * Returns the format handled by this <code>GridCoverageWriter</code>.
090 */
091 public Format getFormat() {
092 return format;
093 }
094
095 /**
096 * Returns the output destination. This is the object passed to the
097 * {@link org.opengis.coverage.grid.GridCoverageExchange#getWriter} method. It can be a
098 * {@link java.lang.String}, an {@link java.io.OutputStream}, a
099 * {@link java.nio.channels.FileChannel}, etc.
100 */
101 public Object getDestination() {
102 return destination;
103 }
104
105 /**
106 * Returns the list of metadata keywords associated with the {@linkplain #getDestination output
107 * destination} as a whole (not associated with any particular grid coverage). If no metadata is
108 * allowed, the array will be empty.
109 *
110 * @return The list of metadata keywords for the output destination.
111 *
112 * @revisit This javadoc may not apply thats well in the iterator scheme.
113 */
114 public String[] getMetadataNames() {
115 return metadata.keySet().toArray( new String[metadata.size()] );
116 }
117
118 /**
119 * Retrieve the metadata value for a given metadata name.
120 *
121 * @param name
122 * Metadata keyword for which to retrieve metadata.
123 * @return The metadata value for the given metadata name. Should be one of the name returned by
124 * {@link #getMetadataNames}.
125 * @throws IOException
126 * if an error occurs during reading.
127 * @throws MetadataNameNotFoundException
128 * if there is no value for the specified metadata name.
129 *
130 * @revisit This javadoc may not apply thats well in the iterator scheme.
131 */
132 public Object getMetadataValue( String name )
133 throws IOException, MetadataNameNotFoundException {
134 return metadata.get( name );
135 }
136
137 /**
138 * Sets the metadata value for a given metadata name.
139 *
140 * @param name
141 * Metadata keyword for which to set the metadata.
142 * @param value
143 * The metadata value for the given metadata name.
144 * @throws IOException
145 * if an error occurs during writing.
146 * @throws MetadataNameNotFoundException
147 * if the specified metadata name is not handled for this format.
148 *
149 * @revisit This javadoc may not apply thats well in the iterator scheme.
150 */
151 public void setMetadataValue( String name, String value )
152 throws IOException, MetadataNameNotFoundException {
153 metadata.put( name, value );
154 }
155
156 /**
157 * Retrieve the list of grid coverages contained within the {@linkplain #getDestination() input
158 * source}. Each grid can have a different coordinate system, number of dimensions and grid
159 * geometry. For example, a HDF-EOS file (GRID.HDF) contains 6 grid coverages each having a
160 * different projection. An empty array will be returned if no sub names exist.
161 *
162 * @return The list of grid coverages contained within the input source.
163 * @throws IOException
164 * if an error occurs during reading.
165 *
166 * @revisit The javadoc should also be more explicit about hierarchical format. Should the names
167 * be returned as paths? Explain what to return if the GridCoverage are accessible by
168 * index only. A proposal is to name them "grid1", "grid2", etc.
169 */
170 public String[] listSubNames()
171 throws IOException {
172 return subNames;
173 }
174
175 /**
176 * Returns the name for the next grid coverage to be read from the
177 * {@linkplain #getDestination() output destination}.
178 *
179 * @throws IOException
180 * if an error occurs during reading.
181 * @revisit Do we need a special method for that, or should it be a metadata?
182 */
183 public String getCurrentSubname()
184 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 )
198 throws IOException {
199 currentSubname = name;
200 }
201
202 }