    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/model/coverage/grid/Format.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.Serializable;
    039    import java.util.Arrays;
    040    import java.util.List;
    041
    042    import org.deegree.datatypes.Code;
    043    import org.deegree.datatypes.parameter.GeneralOperationParameterIm;
    044
    045    /**
    046     * This interface is a discovery mechanism to determine the formats supported by a
    047     * {@link "org.opengis.coverage.grid.GridCoverageExchange"} implementation. A
    048     * <code>GC_GridCoverageExchange</code> implementation can support a number of file format or
    049     * resources.
    050     *
    051     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
    052     * @author last edited by: $Author: mschneider $
    053     *
    054     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
    055     */
    056    public class Format implements Serializable {
    057
    058        private static final long serialVersionUID = 3847909077719638612L;
    059
    060        private String name = null;
    061
    062        private String description = null;
    063
    064        private String docURL = null;
    065
    066        private String vendor = null;
    067
    068        private String version = null;
    069
    070        private List<GeneralOperationParameterIm> readParameters = null;
    071
    072        private List<GeneralOperationParameterIm> writeParameters = null;
    073
    074        /**
    075         * Initializes a format with a Code containing a code that will be used as format name and a
    076         * code space (optional) that will be interpreted as format vendor.
    077         *
    078         * @param code
    079         */
    080        public Format( Code code ) {
    081            this.name = code.getCode();
    082            if ( code.getCodeSpace() != null ) {
    083                vendor = code.getCodeSpace().toString();
    084            }
    085        }
    086
    087        /**
    088         * @param description
    089         * @param docURL
    090         * @param name
    091         * @param vendor
    092         * @param version
    093         */
    094        public Format( String name, String description, String docURL, String vendor, String version ) {
    095            this.description = description;
    096            this.docURL = docURL;
    097            this.name = name;
    098            this.vendor = vendor;
    099            this.version = version;
    100        }
    101
    102        /**
    103         * @param description
    104         * @param docURL
    105         * @param name
    106         * @param vendor
    107         * @param version
    108         * @param readParameters
    109         * @param writeParameters
    110         */
    111        public Format( String name, String description, String docURL, String vendor, String version,
    112                       GeneralOperationParameterIm[] readParameters, GeneralOperationParameterIm[] writeParameters ) {
    113            this.description = description;
    114            this.docURL = docURL;
    115            this.name = name;
    116            this.vendor = vendor;
    117            this.version = version;
    118            setReadParameters( readParameters );
    119            setWriteParameters( writeParameters );
    120        }
    121
    122        /**
    123         * @param description
    124         *            The description to set.
    125         *
    126         */
    127        public void setDescription( String description ) {
    128            this.description = description;
    129        }
    130
    131        /**
    132         * @param docURL
    133         *            The docURL to set.
    134         *
    135         */
    136        public void setDocURL( String docURL ) {
    137            this.docURL = docURL;
    138        }
    139
    140        /**
    141         * @param name
    142         *            The name to set.
    143         *
    144         */
    145        public void setName( String name ) {
    146            this.name = name;
    147        }
    148
    149        /**
    150         * @param readParameters
    151         *            The readParameters to set.
    152         */
    153        public void setReadParameters( GeneralOperationParameterIm[] readParameters ) {
    154            if ( readParameters == null )
    155                readParameters = new GeneralOperationParameterIm[0];
    156            this.readParameters = Arrays.asList( readParameters );
    157        }
    158
    159        /**
    160         * @param readParameter
    161         */
    162        public void addReadParameter( GeneralOperationParameterIm readParameter ) {
    163            this.readParameters.add( readParameter );
    164        }
    165
    166        /**
    167         * @param vendor
    168         *            The vendor to set.
    169         *
    170         */
    171        public void setVendor( String vendor ) {
    172            this.vendor = vendor;
    173        }
    174
    175        /**
    176         * @param version
    177         *            The version to set.
    178         *
    179         */
    180        public void setVersion( String version ) {
    181            this.version = version;
    182        }
    183
    184        /**
    185         * @param writeParameters
    186         *            The writeParameters to set.
    187         */
    188        public void setWriteParameters( GeneralOperationParameterIm[] writeParameters ) {
    189            if ( writeParameters == null )
    190                writeParameters = new GeneralOperationParameterIm[0];
    191            this.writeParameters = Arrays.asList( writeParameters );
    192        }
    193
    194        /**
    195         * @param writeParameter
    196         */
    197        public void addWriteParameter( GeneralOperationParameterIm writeParameter ) {
    198            this.readParameters.add( writeParameter );
    199        }
    200
    201        /**
    202         * Name of the file format.
    203         *
    204         * @return the name of the file format.
    205         *
    206         */
    207        public String getName() {
    208            return name;
    209        }
    210
    211        /**
    212         * Description of the file format. If no description, the value will be <code>null</code>.
    213         *
    214         * @return the description of the file format.
    215         */
    216        public String getDescription() {
    217            return description;
    218        }
    219
    220        /**
    221         * Vendor or agency for the format.
    222         *
    223         * @return the vendor or agency for the format.
    224         */
    225        public String getVendor() {
    226            return vendor;
    227        }
    228
    229        /**
    230         * Documentation URL for the format.
    231         *
    232         * @return the documentation URL for the format.
    233         */
    234        public String getDocURL() {
    235            return docURL;
    236        }
    237
    238        /**
    239         * Version number of the format.
    240         *
    241         * @return the version number of the format.
    242         */
    243        public String getVersion() {
    244            return version;
    245        }
    246
    247        /**
    248         * @return the information Retrieve the parameter information for a
    249         *         {@link "org.opengis.coverage.grid.GridCoverageReader#read"} read operation.
    250         */
    251        public GeneralOperationParameterIm[] getReadParameters() {
    252            GeneralOperationParameterIm[] rp = new GeneralOperationParameterIm[readParameters.size()];
    253            return readParameters.toArray( rp );
    254        }
    255
    256        /**
    257         * Retrieve the parameter information for a org.opengis.coverage.grid.GridCoverageWriter#write
    258         * operation.
    259         *
    260         * @return the parameter information for a org.opengis.coverage.grid.GridCoverageWriter#write
    261         *         operation.
    262         *
    263         */
    264        public GeneralOperationParameterIm[] getWriteParameters() {
    265            GeneralOperationParameterIm[] rp = new GeneralOperationParameterIm[writeParameters.size()];
    266            return writeParameters.toArray( rp );
    267        }
    268
    269        /**
    270         * performs a test if the passed Object is equal to this Format. Two Formats are equal if their
    271         * names ar equal and (if not null) their vendors and versions are equal.
    272         *
    273         * @see java.lang.Object#equals(java.lang.Object)
    274         * @param obj
    275         *            object to compare
    276         */
    277        @Override
    278        public boolean equals( Object obj ) {
    279            if ( obj == null || !( obj instanceof Format ) ) {
    280                return false;
    281            }
    282            Format other = (Format) obj;
    283            boolean eq = this.getName().equals( other.getName() );
    284            if ( getVendor() != null && other.getVendor() != null ) {
    285                eq = eq && getVendor().equals( other.getVendor() );
    286            } else if ( getVendor() == null && other.getVendor() != null ) {
    287                return false;
    288            } else if ( getVendor() != null && other.getVendor() == null ) {
    289                return false;
    290            }
    291            if ( getVersion() != null && other.getVersion() != null ) {
    292                eq = eq && getVersion().equals( other.getVersion() );
    293            } else if ( getVersion() == null && other.getVersion() != null ) {
    294                return false;
    295            } else if ( getVersion() != null && other.getVersion() == null ) {
    296                return false;
    297            }
    298            return eq;
    299        }
    300
    301    }