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