    001    //$HeadURL: https://sushibar/svn/deegree/base/trunk/resources/eclipse/svn_classfile_header_template.xml $
    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
    037    package org.deegree.ogcwebservices.wms;
    038
    039    import java.util.LinkedList;
    040
    041    import org.deegree.datatypes.QualifiedName;
    042    import org.deegree.framework.xml.XMLFragment;
    043    import org.deegree.framework.xml.XMLTools;
    044    import org.deegree.i18n.Messages;
    045    import org.deegree.ogcwebservices.OGCWebServiceException;
    046    import org.deegree.ogcwebservices.wms.capabilities.Layer;
    047    import org.deegree.ogcwebservices.wms.configuration.AbstractDataSource;
    048    import org.deegree.ogcwebservices.wms.configuration.LocalWFSDataSource;
    049    import org.deegree.ogcwebservices.wms.configuration.WMSConfigurationType;
    050    import org.deegree.ogcwebservices.wms.operation.DescribeLayer;
    051    import org.deegree.ogcwebservices.wms.operation.DescribeLayerResult;
    052    import org.w3c.dom.Element;
    053
    054    /**
    055     * <code>DescribeLayerHandler</code>
    056     *
    057     * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a>
    058     * @author last edited by: $Author:$
    059     *
    060     * @version $Revision:$, $Date:$
    061     */
    062    public class DescribeLayerHandler {
    063
    064        /**
    065         * @param request
    066         * @param configuration
    067         * @return a result object with the XML result
    068         * @throws OGCWebServiceException
    069         */
    070        public DescribeLayerResult perform( DescribeLayer request, WMSConfigurationType configuration )
    071                                throws OGCWebServiceException {
    072            String[] layers = request.getLayers();
    073
    074            LinkedList<Layer> ls = new LinkedList<Layer>();
    075            // check layers for existance
    076            for ( String l : layers ) {
    077                Layer layer = configuration.getLayer( l );
    078                if ( layer == null ) {
    079                    throw new OGCWebServiceException( Messages.getMessage( "WMS_UNKNOWNLAYER", l ) );
    080                }
    081                ls.add( layer );
    082            }
    083
    084            XMLFragment doc = new XMLFragment( new QualifiedName( "WMS_DescribeLayerResponse" ) );
    085            Element root = doc.getRootElement();
    086            root.setAttribute( "version", "1.1.1" );
    087
    088            for ( Layer l : ls ) {
    089                Element lay = XMLTools.appendElement( root, null, "LayerDescription" );
    090                lay.setAttribute( "name", l.getName() );
    091                AbstractDataSource[] ds = l.getDataSource();
    092                if ( ds != null ) {
    093                    for ( AbstractDataSource d : ds ) {
    094                        if ( d instanceof LocalWFSDataSource ) {
    095                            // lay.setAttribute( "wfs", "unknown" );
    096                            LocalWFSDataSource wfsds = (LocalWFSDataSource) d;
    097                            Element e = XMLTools.appendElement( lay, null, "Query" );
    098                            QualifiedName qn = wfsds.getName();
    099                            e.setAttribute( "xmlns:" + qn.getPrefix(), qn.getNamespace().toASCIIString() );
    100                            e.setAttribute( "typeName", qn.getPrefixedName() );
    101                        }
    102                    }
    103                }
    104            }
    105
    106            return new DescribeLayerResult( request, doc );
    107        }
    108
    109    }