001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/wms/capabilities/WMSCapabilities.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003    
004     This file is part of deegree.
005     Copyright (C) 2001-2006 by:
006     EXSE, Department of Geography, University of Bonn
007     http://www.giub.uni-bonn.de/deegree/
008     lat/lon GmbH
009     http://www.lat-lon.de
010    
011     This library is free software; you can redistribute it and/or
012     modify it under the terms of the GNU Lesser General Public
013     License as published by the Free Software Foundation; either
014     version 2.1 of the License, or (at your option) any later version.
015    
016     This library is distributed in the hope that it will be useful,
017     but WITHOUT ANY WARRANTY; without even the implied warranty of
018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
019     Lesser General Public License for more details.
020    
021     You should have received a copy of the GNU Lesser General Public
022     License along with this library; if not, write to the Free Software
023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
024    
025     Contact:
026    
027     Andreas Poth
028     lat/lon GmbH
029     Aennchenstr. 19
030     53115 Bonn
031     Germany
032     E-Mail: poth@lat-lon.de
033    
034     Prof. Dr. Klaus Greve
035     Department of Geography
036     University of Bonn
037     Meckenheimer Allee 166
038     53115 Bonn
039     Germany
040     E-Mail: greve@giub.uni-bonn.de
041    
042     
043     ---------------------------------------------------------------------------*/
044    package org.deegree.ogcwebservices.wms.capabilities;
045    
046    import java.util.HashSet;
047    import java.util.Set;
048    
049    import org.deegree.framework.log.ILogger;
050    import org.deegree.framework.log.LoggerFactory;
051    import org.deegree.i18n.Messages;
052    import org.deegree.ogcwebservices.getcapabilities.OGCCapabilities;
053    import org.deegree.owscommon_new.OperationsMetadata;
054    import org.deegree.owscommon_new.ServiceIdentification;
055    import org.deegree.owscommon_new.ServiceProvider;
056    
057    /**
058     * <code>WMSCapabilities</code> is the data class for the WMS version of capabilities. Since
059     * WMS is not yet using the OWS commons implementation, it is more or less just a copy of the old
060     * version.
061     * 
062     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
063     * @version $Revision: 6259 $
064     */
065    public class WMSCapabilities extends OGCCapabilities {
066    
067        private static final long serialVersionUID = -6040994669604563061L;
068        
069        private static final ILogger LOG = LoggerFactory.getLogger( WMSCapabilities.class );
070    
071        private ServiceIdentification serviceIdentification = null;
072    
073        private ServiceProvider serviceProvider = null;
074    
075        private UserDefinedSymbolization userDefinedSymbolization = null;
076    
077        private OperationsMetadata operationMetadata = null;
078    
079        private Layer layer = null;
080    
081        /**
082         * constructor initializing the class with the <code>WMSCapabilities</code>
083         * @param version
084         * @param updateSequence
085         * @param serviceIdentification
086         * @param serviceProvider
087         * @param metadata
088         * @param layer
089         */
090        protected WMSCapabilities( String version, String updateSequence,
091                                  ServiceIdentification serviceIdentification,
092                                  ServiceProvider serviceProvider,
093                                  UserDefinedSymbolization userDefinedSymbolization,
094                                  OperationsMetadata metadata, Layer layer ) {
095            super( version, updateSequence );
096    
097            setServiceProvider( serviceProvider );
098            setServiceIdentification( serviceIdentification );
099            setUserDefinedSymbolization( userDefinedSymbolization );
100            setOperationMetadata( metadata );
101            setLayer( layer );
102        }
103    
104        /**
105         *
106         * @return the service description section
107         */
108        public ServiceIdentification getServiceIdentification() {
109            return serviceIdentification;
110        }
111    
112        /**
113         * sets the service description section
114         * @param serviceIdentification
115         */
116        public void setServiceIdentification( ServiceIdentification serviceIdentification ) {
117            this.serviceIdentification = serviceIdentification;
118        }
119    
120        /**
121         *
122         * @return the root layer provided by a WMS
123         */
124        public Layer getLayer() {
125            return layer;
126        }
127    
128        /**
129         * 
130         * @param name the layer name
131         * @return the root layer provided by a WMS
132         */
133        public Layer getLayer( String name ) {
134            Layer lay = null;
135            if ( layer.getName() != null && name.equals( layer.getName() ) ) {
136                lay = layer;
137            } else {
138                lay = getLayer( name, layer.getLayer() );
139            }
140            return lay;
141        }
142    
143        /**
144         * recursion over all layers to find the layer that matches the submitted
145         * name. If no layer can be found that fullfills the condition <tt>null</tt>
146         * will be returned.
147         *
148         * @param name name of the layer to be found
149         * @param layers list of searchable layers
150         *
151         * @return a layer object or <tt>null</tt>
152         */
153        private Layer getLayer( String name, Layer[] layers ) {
154            Layer lay = null;
155    
156            if ( layers != null ) {
157                for ( int i = 0; i < layers.length; i++ ) {
158                    if ( name.equals( layers[i].getName() ) ) {
159                        lay = layers[i];
160                        break;
161                    }
162                    lay = getLayer( name, layers[i].getLayer() );
163                    if ( lay != null )
164                        break;
165                }
166            }
167    
168            return lay;
169        }
170    
171        /**
172         * returns the @see Layer identified by its title. If no 
173         * layer matching the passed title can be found <code>null</code>
174         * will be returned.  
175         * 
176         * @param title
177         * @return the layer
178         */
179        public Layer getLayerByTitle( String title ) {
180            Layer lay = null;
181            if ( title.equals( layer.getTitle() ) ) {
182                lay = layer;
183            } else {
184                lay = getLayerByTitle( title, layer.getLayer() );
185            }
186            return lay;
187        }
188    
189        /**
190         * recursion over all layers to find the layer that matches the passed
191         * title. If no layer can be found that fullfills the condition <tt>null</tt>
192         * will be returned.
193         *
194         * @param name name of the layer to be found
195         * @param layers list of searchable layers
196         *
197         * @return a layer object or <tt>null</tt>
198         */
199        private Layer getLayerByTitle( String title, Layer[] layers ) {
200            Layer lay = null;
201    
202            if ( layers != null ) {
203                for ( int i = 0; i < layers.length; i++ ) {
204                    if ( title.equals( layers[i].getTitle() ) ) {
205                        lay = layers[i];
206                        break;
207                    }
208                    lay = getLayer( title, layers[i].getLayer() );
209                    if ( lay != null )
210                        break;
211                }
212            }
213    
214            return lay;
215        }
216    
217        /**
218         * @param layer
219         * @param layers
220         * @return a layer name, if a layer has been defined two times with the same name, null otherwise
221         */
222        public static String hasDoubleLayers( Layer layer, Set<String> layers ) {
223    
224            if ( layers.contains( layer.getName() ) ) {
225                return layer.getName();
226            }
227    
228            layers.add( layer.getName() );
229    
230            for ( Layer lay : layer.getLayer() ) {
231                String dl = hasDoubleLayers( lay, layers );
232                if ( dl != null ) {
233                    return dl;
234                }
235            }
236            return null;
237    
238        }
239    
240        /**
241         * sets the root layer provided by a WMS
242         * @param layer
243         */
244        public void setLayer( Layer layer ) {
245            String dl = hasDoubleLayers( layer, new HashSet<String>() );
246            if ( dl != null ) {
247                LOG.logWarning( Messages.getMessage( "WMS_REDEFINED_LAYER", dl ) );
248    //            throw new IllegalArgumentException( Messages.getMessage( "WMS_REDEFINED_LAYER", dl ) );
249            }
250            this.layer = layer;
251        }
252    
253        /**
254         * 
255         * @return metadata about the offered access methods like GetMap or 
256         * GetCapabilities
257         */
258        public OperationsMetadata getOperationMetadata() {
259            return operationMetadata;
260        }
261    
262        /**
263         * sets metadata for the offered access methods like GetMap or 
264         * GetCapabiliites
265         * @param operationMetadata
266         */
267        public void setOperationMetadata( OperationsMetadata operationMetadata ) {
268            this.operationMetadata = operationMetadata;
269        }
270    
271        /**
272         * 
273         * @return informations about the provider of a WMS
274         */
275        public ServiceProvider getServiceProvider() {
276            return serviceProvider;
277        }
278    
279        /**
280         * sets informations about the provider of a WMS
281         * @param serviceProvider
282         */
283        public void setServiceProvider( ServiceProvider serviceProvider ) {
284            this.serviceProvider = serviceProvider;
285        }
286    
287        /**
288         * @return the user defined symbolization
289         */
290        public UserDefinedSymbolization getUserDefinedSymbolization() {
291            return userDefinedSymbolization;
292        }
293    
294        /**
295         * @param userDefinedSymbolization
296         */
297        public void setUserDefinedSymbolization( UserDefinedSymbolization userDefinedSymbolization ) {
298            this.userDefinedSymbolization = userDefinedSymbolization;
299        }
300    }
301    /* ********************************************************************
302     Changes to this class. What the people have been up to:
303     $Log$
304     Revision 1.14  2006/11/29 15:09:05  schmitz
305     Moved more messages to central location, added warning message if double layers are defined.
306    
307     Revision 1.13  2006/08/23 07:10:22  schmitz
308     Renamed the owscommon_neu package to owscommon_new.
309    
310     Revision 1.12  2006/08/22 10:25:01  schmitz
311     Updated the WMS to use the new OWS common package.
312     Updated the rest of deegree to use the new data classes returned
313     by the updated WMS methods/capabilities.
314    
315     Revision 1.11  2006/07/11 14:08:37  schmitz
316     Fixed some documentation warnings.
317    
318     Revision 1.10  2006/05/29 06:37:29  poth
319     supported for requesting named layer groups are added (layers which include layers which include layers ... see WMS spec)
320    
321    
322     ********************************************************************** */