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