001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/ogcwebservices/wms/capabilities/WMSCapabilities.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.wms.capabilities;
037    
038    import java.util.Collections;
039    import java.util.HashSet;
040    import java.util.LinkedList;
041    import java.util.List;
042    import java.util.Set;
043    
044    import org.deegree.framework.log.ILogger;
045    import org.deegree.framework.log.LoggerFactory;
046    import org.deegree.i18n.Messages;
047    import org.deegree.ogcwebservices.getcapabilities.OGCCapabilities;
048    import org.deegree.owscommon_new.OperationsMetadata;
049    import org.deegree.owscommon_new.ServiceIdentification;
050    import org.deegree.owscommon_new.ServiceProvider;
051    
052    /**
053     * <code>WMSCapabilities</code> is the data class for the WMS version of capabilities. Since WMS is not yet using the
054     * OWS commons implementation, it is more or less just a copy of the old version.
055     *
056     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
057     * @version $Revision: 18195 $
058     */
059    public class WMSCapabilities extends OGCCapabilities {
060    
061        private static final long serialVersionUID = -6040994669604563061L;
062    
063        private static final ILogger LOG = LoggerFactory.getLogger( WMSCapabilities.class );
064    
065        private ServiceIdentification serviceIdentification = null;
066    
067        private ServiceProvider serviceProvider = null;
068    
069        private UserDefinedSymbolization userDefinedSymbolization = null;
070    
071        private OperationsMetadata operationMetadata = null;
072    
073        private Layer layer = null;
074    
075        protected List<String> exceptions;
076    
077        /**
078         * constructor initializing the class with the <code>WMSCapabilities</code>
079         *
080         * @param version
081         * @param updateSequence
082         * @param serviceIdentification
083         * @param serviceProvider
084         * @param userDefinedSymbolization
085         * @param metadata
086         * @param layer
087         */
088        protected WMSCapabilities( String version, String updateSequence, ServiceIdentification serviceIdentification,
089                                   ServiceProvider serviceProvider, UserDefinedSymbolization userDefinedSymbolization,
090                                   OperationsMetadata metadata, Layer layer ) {
091            super( version, updateSequence );
092    
093            setServiceProvider( serviceProvider );
094            setServiceIdentification( serviceIdentification );
095            setUserDefinedSymbolization( userDefinedSymbolization );
096            setOperationMetadata( metadata );
097            setLayer( layer );
098            exceptions = new LinkedList<String>();
099            if ( version.equals( "1.3.0" ) ) {
100                exceptions.add( "XML" );
101            } else {
102                exceptions.add( "application/vnd.ogc.se_xml" );
103            }
104        }
105    
106        /**
107         * @param version
108         * @param updateSequence
109         * @param serviceIdentification
110         * @param serviceProvider
111         * @param userDefinedSymbolization
112         * @param metadata
113         * @param layer
114         * @param exceptions
115         */
116        protected WMSCapabilities( String version, String updateSequence, ServiceIdentification serviceIdentification,
117                                   ServiceProvider serviceProvider, UserDefinedSymbolization userDefinedSymbolization,
118                                   OperationsMetadata metadata, Layer layer, List<String> exceptions ) {
119            this( version, updateSequence, serviceIdentification, serviceProvider, userDefinedSymbolization, metadata,
120                  layer );
121            this.exceptions = exceptions;
122        }
123    
124        /**
125         *
126         * @return the service description section
127         */
128        public ServiceIdentification getServiceIdentification() {
129            return serviceIdentification;
130        }
131    
132        /**
133         * sets the service description section
134         *
135         * @param serviceIdentification
136         */
137        public void setServiceIdentification( ServiceIdentification serviceIdentification ) {
138            this.serviceIdentification = serviceIdentification;
139        }
140    
141        /**
142         *
143         * @return the root layer provided by a WMS
144         */
145        public Layer getLayer() {
146            return layer;
147        }
148    
149        /**
150         *
151         * @param name
152         *            the layer name
153         * @return the layer provided by a WMS, or null, if there is no such layer
154         */
155        public Layer getLayer( String name ) {
156            Layer lay = null;
157            if ( layer.getName() != null && name.equals( layer.getName() ) ) {
158                lay = layer;
159            } else {
160                lay = getLayer( name, layer.getLayer() );
161            }
162            return lay;
163        }
164    
165        /**
166         * recursion over all layers to find the layer that matches the submitted name. If no layer can be found that
167         * fullfills the condition <tt>null</tt> will be returned.
168         *
169         * @param name
170         *            name of the layer to be found
171         * @param layers
172         *            list of searchable layers
173         *
174         * @return a layer object or <tt>null</tt>
175         */
176        private Layer getLayer( String name, Layer[] layers ) {
177            Layer lay = null;
178    
179            if ( layers != null ) {
180                for ( int i = 0; i < layers.length; i++ ) {
181                    if ( name.equals( layers[i].getName() ) ) {
182                        lay = layers[i];
183                        break;
184                    }
185                    lay = getLayer( name, layers[i].getLayer() );
186                    if ( lay != null )
187                        break;
188                }
189            }
190    
191            return lay;
192        }
193    
194        /**
195         * returns the
196         *
197         * @see Layer identified by its title. If no layer matching the passed title can be found <code>null</code> will
198         *      be returned.
199         *
200         * @param title
201         * @return the layer
202         */
203        public Layer getLayerByTitle( String title ) {
204            Layer lay = null;
205            if ( title.equals( layer.getTitle() ) ) {
206                lay = layer;
207            } else {
208                lay = getLayerByTitle( title, layer.getLayer() );
209            }
210            return lay;
211        }
212    
213        /**
214         * recursion over all layers to find the layer that matches the passed title. If no layer can be found that
215         * fullfills the condition <tt>null</tt> will be returned.
216         *
217         * @param title
218         *            of the layer to be found
219         * @param layers
220         *            list of searchable layers
221         *
222         * @return a layer object or <tt>null</tt>
223         */
224        private Layer getLayerByTitle( String title, Layer[] layers ) {
225            Layer lay = null;
226    
227            if ( layers != null ) {
228                for ( int i = 0; i < layers.length; i++ ) {
229                    if ( title.equals( layers[i].getTitle() ) ) {
230                        lay = layers[i];
231                        break;
232                    }
233                    lay = getLayer( title, layers[i].getLayer() );
234                    if ( lay != null )
235                        break;
236                }
237            }
238    
239            return lay;
240        }
241    
242        /**
243         * @param layer
244         * @param layers
245         * @return a layer name, if a layer has been defined two times with the same name, null otherwise
246         */
247        public static String hasDoubleLayers( Layer layer, Set<String> layers ) {
248    
249            if ( layers.contains( layer.getName() ) ) {
250                return layer.getName();
251            }
252    
253            layers.add( layer.getName() );
254    
255            for ( Layer lay : layer.getLayer() ) {
256                String dl = hasDoubleLayers( lay, layers );
257                if ( dl != null ) {
258                    return dl;
259                }
260            }
261            return null;
262    
263        }
264    
265        /**
266         * sets the root layer provided by a WMS
267         *
268         * @param layer
269         */
270        public void setLayer( Layer layer ) {
271            String dl = hasDoubleLayers( layer, new HashSet<String>() );
272            if ( dl != null ) {
273                LOG.logWarning( Messages.getMessage( "WMS_REDEFINED_LAYER", dl ) );
274                // throw new IllegalArgumentException( Messages.getMessage( "WMS_REDEFINED_LAYER", dl )
275                // );
276            }
277            this.layer = layer;
278        }
279    
280        /**
281         *
282         * @return metadata about the offered access methods like GetMap or GetCapabilities
283         */
284        public OperationsMetadata getOperationMetadata() {
285            return operationMetadata;
286        }
287    
288        /**
289         * sets metadata for the offered access methods like GetMap or GetCapabiliites
290         *
291         * @param operationMetadata
292         */
293        public void setOperationMetadata( OperationsMetadata operationMetadata ) {
294            this.operationMetadata = operationMetadata;
295        }
296    
297        /**
298         * @return the list of exceptions
299         */
300        public List<String> getExceptions() {
301            return Collections.unmodifiableList( exceptions );
302        }
303    
304        /**
305         *
306         * @return informations about the provider of a WMS
307         */
308        public ServiceProvider getServiceProvider() {
309            return serviceProvider;
310        }
311    
312        /**
313         * sets informations about the provider of a WMS
314         *
315         * @param serviceProvider
316         */
317        public void setServiceProvider( ServiceProvider serviceProvider ) {
318            this.serviceProvider = serviceProvider;
319        }
320    
321        /**
322         * @return the user defined symbolization
323         */
324        public UserDefinedSymbolization getUserDefinedSymbolization() {
325            return userDefinedSymbolization;
326        }
327    
328        /**
329         * @param userDefinedSymbolization
330         */
331        public void setUserDefinedSymbolization( UserDefinedSymbolization userDefinedSymbolization ) {
332            this.userDefinedSymbolization = userDefinedSymbolization;
333        }
334    }