001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/graphics/sld/Geometry.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.graphics.sld;
037    
038    import java.util.List;
039    
040    import org.deegree.framework.xml.Marshallable;
041    import org.deegree.model.spatialschema.GMLGeometryAdapter;
042    import org.deegree.model.spatialschema.GeometryException;
043    import org.deegree.ogcbase.PropertyPath;
044    import org.deegree.ogcbase.PropertyPathStep;
045    
046    /**
047     * The Geometry element is optional and if it is absent then the default geometry property of the feature type that is
048     * used in the containing FeatureStyleType is used. The precise meaning of default geometry property is
049     * system-dependent. Most frequently, feature types will have only a single geometry property.
050     * <p>
051     * ----------------------------------------------------------------------
052     * </p>
053     *
054     * @author <a href="mailto:k.lupp@web.de">Katharina Lupp</a>
055     * @version $Revision: 18195 $ $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
056     */
057    
058    public class Geometry implements Marshallable {
059    
060        private org.deegree.model.spatialschema.Geometry geometry = null;
061    
062        private PropertyPath propertyPath = null;
063    
064        /**
065         * @param propertyPath
066         * @param geometry
067         */
068        public Geometry( PropertyPath propertyPath, org.deegree.model.spatialschema.Geometry geometry ) {
069            this.propertyPath = propertyPath;
070            this.geometry = geometry;
071        }
072    
073        /**
074         * returns xpath information of the geometry property
075         *
076         * @return xpath information of the geometry property
077         */
078        public PropertyPath getPropertyPath() {
079            return propertyPath;
080        }
081    
082        /**
083         * In principle, a fixed geometry could be defined using GML or operators could be defined for computing a geometry
084         * from references or literals. This enbales the calling client to submitt the geometry to be rendered by the WMS
085         * directly. (This is not part of the SLD XML-schema)
086         *
087         * @return the Geometry
088         *
089         */
090        public org.deegree.model.spatialschema.Geometry getGeometry() {
091            return geometry;
092        }
093    
094        /**
095         * exports the content of the Geometry as XML formated String
096         *
097         * @return xml representation of the Geometry
098         */
099        public String exportAsXML() {
100    
101            StringBuffer sb = new StringBuffer( 1000 );
102            sb.append( "<Geometry>" );
103            if ( propertyPath != null ) {
104                int c = propertyPath.getSteps();
105                List<PropertyPathStep> list = propertyPath.getAllSteps();
106                sb.append( "<ogc:PropertyName" );
107                for ( int i = 0; i < c; i++ ) {
108                    sb.append( " xmlns:" ).append( list.get( i ).getPropertyName().getPrefix() );
109                    sb.append( "='" ).append( list.get( i ).getPropertyName().getNamespace().toASCIIString() );
110                    sb.append( "'" );
111                }
112                sb.append( ">" );
113                sb.append( propertyPath.getAsString() );
114                sb.append( "</ogc:PropertyName>" );
115            } else {
116                try {
117                    sb.append( GMLGeometryAdapter.export( geometry ) );
118                } catch ( GeometryException e ) {
119                    e.printStackTrace();
120                }
121            }
122    
123            sb.append( "</Geometry>" );
124    
125            return sb.toString();
126        }
127    }