001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/ogcwebservices/wpvs/capabilities/WPVSCapabilities.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.wpvs.capabilities;
037    
038    import org.deegree.ogcwebservices.getcapabilities.Contents;
039    import org.deegree.ogcwebservices.getcapabilities.OperationsMetadata;
040    import org.deegree.ogcwebservices.getcapabilities.ServiceIdentification;
041    import org.deegree.ogcwebservices.getcapabilities.ServiceProvider;
042    import org.deegree.owscommon.OWSCommonCapabilities;
043    
044    /**
045     * This class represents a <code>WPVSCapabilities</code> object.
046     *
047     * @author <a href="mailto:taddei@lat-lon.de">Ugo Taddei</a>
048     * @author last edited by: $Author: mschneider $
049     *
050     * @version 2.0, $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
051     *
052     * @since 2.0
053     */
054    public class WPVSCapabilities extends OWSCommonCapabilities {
055    
056        /**
057         *
058         */
059        private static final long serialVersionUID = 957878718619030101L;
060        private Dataset dataset;
061    
062        /**
063         * Creates a new wpvsCapabilities object from the given parameters.
064         *
065         * @param version
066         * @param updateSequence
067         * @param serviceIdentification
068         * @param serviceProvider
069         * @param operationsMetadata
070         * @param contents
071         *            TODO field not verified! Check spec.
072         * @param dataset
073         */
074        public WPVSCapabilities( String version, String updateSequence,
075                                ServiceIdentification serviceIdentification,
076                                ServiceProvider serviceProvider, OperationsMetadata operationsMetadata,
077                                Contents contents, Dataset dataset ) {
078    
079            super( version, updateSequence, serviceIdentification, serviceProvider, operationsMetadata,
080                   contents );
081            this.dataset = dataset;
082    
083        }
084    
085        /**
086         * @return the root dataset of this wpvs
087         */
088        public Dataset getDataset() {
089            return dataset;
090        }
091    
092        /**
093         * recursion over all layers to find the layer that matches the submitted name. If no layer can
094         * be found that fullfills the condition <code>null</code> will be returned.
095         *
096         * @param name
097         *            name of the layer to be found
098         * @param datasets
099         *            list of searchable layers
100         *
101         * @return a layer object or <code>null</code>
102         */
103        private Dataset findDataset( String name, Dataset[] datasets ) {
104            Dataset dset = null;
105    
106            if ( datasets != null ) {
107                for ( Dataset set : datasets ) {
108                    dset = findDataset( name, set.getDatasets() );
109                    if ( dset != null )
110                        return dset;
111                    if ( name.equals( set.getName() ) ) {
112                        return set;
113                    }
114                }
115            }
116            return dset;
117        }
118    
119        /**
120         * returns a DataSet provided by a WPVS with the given name
121         * @param name the name of the DataSet
122         *
123         * @return a DataSet with a given Name or <code>null</code> if no such DataSet exists.
124         */
125        public Dataset findDataset( String name ) {
126            if ( name == null )
127                return null;
128            if ( dataset.getName() != null && name.equals( dataset.getName() ) ) {
129                return dataset;
130            }
131            return findDataset( name, dataset.getDatasets() );
132        }
133    
134        /**
135         * Finds an <code>ElevationModel</code> in this dataset or in its children. This method return
136         * the first dataset it finds or null, otherwise.
137         *
138         * @param elevationModelName
139         *            the name identifying the <code>ElevationModel</code>
140         * @return the <code>ElevationModel</code> with the given name or null
141         */
142        public ElevationModel findElevationModel( String elevationModelName ) {
143    
144            ElevationModel elevModel = null;
145            Dataset ds = dataset;
146    
147            if ( ds != null ) {
148    
149                ElevationModel em = ds.getElevationModel();
150                if ( elevationModelName == null )
151                    return null;
152                if ( em != null && elevationModelName.equals( em.getName() ) ) {
153                    return em;
154                }
155                Dataset[] datasets = ds.getDatasets();
156                elevModel = findElevationModel( elevationModelName, datasets );
157            }
158            return elevModel;
159        }
160    
161        /**
162         * @param elevationModelName
163         * @param datasets
164         */
165        private ElevationModel findElevationModel( String elevationModelName, Dataset[] datasets ) {
166    
167            if ( elevationModelName == null || datasets == null )
168                return null;
169            for ( Dataset dset : datasets ) {
170                ElevationModel elevModel = findElevationModel( elevationModelName, dset.getDatasets() );
171                if ( elevModel != null )
172                    return elevModel;
173    
174                elevModel = dset.getElevationModel();
175                if ( elevModel != null && elevationModelName.equals( elevModel.getName() ) ) {
176                    return elevModel;
177                }
178            }
179            return null;
180        }
181    
182    }