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