    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/ogcwebservices/wcs/describecoverage/CoverageDescription.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.ogcwebservices.wcs.describecoverage;
    037
    038    import java.io.IOException;
    039    import java.net.URL;
    040    import java.util.HashMap;
    041    import java.util.Map;
    042
    043    import org.deegree.framework.util.NetWorker;
    044    import org.deegree.model.crs.UnknownCRSException;
    045    import org.xml.sax.SAXException;
    046
    047    /**
    048     * @version $Revision: 18195 $
    049     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
    050     * @author last edited by: $Author: mschneider $
    051     *
    052     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
    053     */
    054
    055    public class CoverageDescription {
    056
    057        private CoverageOffering[] coverageOffering = new CoverageOffering[0];
    058
    059        private Map<String, CoverageOffering> map = new HashMap<String, CoverageOffering>( 100 );
    060
    061        private String version = "1.0.0";
    062
    063        /**
    064         * creates a <tt>CoverageDescription</tt> from a DOM document assigen by the passed URL
    065         *
    066         * @return created <tt>CoverageDescription</tt>
    067         * @exception IOException
    068         * @exception SAXException
    069         * @exception InvalidCoverageDescriptionExcpetion
    070         */
    071        public static CoverageDescription createCoverageDescription( URL url )
    072                                throws IOException, SAXException, InvalidCoverageDescriptionExcpetion {
    073            CoverageDescriptionDocument covDescDoc = new CoverageDescriptionDocument();
    074            if ( url == null ) {
    075                throw new InvalidCoverageDescriptionExcpetion( "location URL for a coverage description document is null" );
    076            }
    077            if ( !NetWorker.existsURL( url ) ) {
    078                throw new InvalidCoverageDescriptionExcpetion( "location URL: " + url
    079                                                               + "for a coverage description document doesn't exist" );
    080            }
    081            covDescDoc.load( url );
    082            return new CoverageDescription( covDescDoc );
    083        }
    084
    085        /**
    086         * @param covDescDoc
    087         * @exception InvalidCoverageDescriptionExcpetion
    088         */
    089        public CoverageDescription( CoverageDescriptionDocument covDescDoc ) throws InvalidCoverageDescriptionExcpetion {
    090            setVersion( covDescDoc.getVersion() );
    091            try {
    092                setCoverageOfferings( covDescDoc.getCoverageOfferings() );
    093            } catch ( UnknownCRSException e ) {
    094                throw new InvalidCoverageDescriptionExcpetion( e.getMessage() );
    095            }
    096        }
    097
    098        /**
    099         * @param coverageOffering
    100         */
    101        public CoverageDescription( CoverageOffering[] coverageOffering, String version ) {
    102            setVersion( version );
    103            setCoverageOfferings( coverageOffering );
    104        }
    105
    106        /**
    107         * @return Returns the coverageOffering.
    108         */
    109        public CoverageOffering[] getCoverageOfferings() {
    110            return coverageOffering;
    111        }
    112
    113        /**
    114         * returns a <tt>CoverageOffering</tt> identified by its name. if no <tt>CoverageOffering</tt>
    115         * is known by a <tt>CoverageDescription</tt> with the passed name, <tt>null</tt> will be
    116         * returned.
    117         *
    118         * @param name
    119         * @return a <tt>CoverageOffering</tt> identified by its name.
    120         */
    121        public CoverageOffering getCoverageOffering( String name ) {
    122            return map.get( name );
    123        }
    124
    125        /**
    126         * @param coverageOffering
    127         *            The coverageOffering to set.
    128         */
    129        public void setCoverageOfferings( CoverageOffering[] coverageOffering ) {
    130            if ( coverageOffering == null ) {
    131                coverageOffering = new CoverageOffering[0];
    132            }
    133            map.clear();
    134            for ( int i = 0; i < coverageOffering.length; i++ ) {
    135                map.put( coverageOffering[i].getName(), coverageOffering[i] );
    136            }
    137            this.coverageOffering = coverageOffering;
    138        }
    139
    140        /**
    141         * @return version
    142         */
    143        public String getVersion() {
    144            return version;
    145        }
    146
    147        /**
    148         * @param version
    149         */
    150        public void setVersion( String version ) {
    151            this.version = version;
    152        }
    153
    154    }