001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_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: 25849 $ $Date: 2010-08-11 17:51:26 +0200 (Mi, 11 Aug 2010) $
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                    if ( list.get( i ).getPropertyName().getNamespace() != null ) {
109                        sb.append( " xmlns:" ).append( list.get( i ).getPropertyName().getPrefix() );
110                        sb.append( "='" ).append( list.get( i ).getPropertyName().getNamespace().toASCIIString() );
111                        sb.append( "'" );
112                    }
113                }
114                sb.append( ">" );
115                sb.append( propertyPath.getAsString() );
116                sb.append( "</ogc:PropertyName>" );
117            } else {
118                try {
119                    sb.append( GMLGeometryAdapter.export( geometry ) );
120                } catch ( GeometryException e ) {
121                    e.printStackTrace();
122                }
123            }
124    
125            sb.append( "</Geometry>" );
126    
127            return sb.toString();
128        }
129    }