    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/graphics/sld/AbstractLayer.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.ArrayList;
    039    import java.util.Arrays;
    040    import java.util.List;
    041
    042    import org.deegree.framework.xml.Marshallable;
    043
    044    /**
    045     * <p>
    046     * ----------------------------------------------------------------------
    047     * </p>
    048     *
    049     * @author <a href="mailto:k.lupp@web.de">Katharina Lupp</a>
    050     * @version $Revision: 18195 $ $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
    051     */
    052
    053    public abstract class AbstractLayer implements Marshallable {
    054
    055        /**
    056         * The feature contrains
    057         */
    058        protected LayerFeatureConstraints layerFeatureConstraints = null;
    059
    060        /**
    061         * the styles
    062         */
    063        protected List<AbstractStyle> styles = null;
    064
    065        /**
    066         * name of the layer.
    067         */
    068        protected String name = null;
    069
    070        /**
    071         * constructor initializing the class with the <NamedLayer>
    072         * @param name
    073         * @param layerFeatureConstraints
    074         * @param styles
    075         */
    076        AbstractLayer( String name, LayerFeatureConstraints layerFeatureConstraints, AbstractStyle[] styles ) {
    077            this.styles = new ArrayList<AbstractStyle>();
    078            setName( name );
    079            setLayerFeatureConstraints( layerFeatureConstraints );
    080            setStyles( styles );
    081        }
    082
    083        /**
    084         * The Name element identifies the well-known name of the layer being referenced, and is
    085         * required. All possible well-known names are usually identified in the capabilities document
    086         * for a server.
    087         *
    088         * @return the name of the layer
    089         *
    090         */
    091        public String getName() {
    092            return name;
    093        }
    094
    095        /**
    096         * sets the <Name>
    097         *
    098         * @param name
    099         *            the name of the layer
    100         *
    101         */
    102        public void setName( String name ) {
    103            this.name = name;
    104        }
    105
    106        /**
    107         * The LayerFeatureConstraints element is optional in a NamedLayer and allows the user to
    108         * specify constraints on what features of what feature types are to be selected by the
    109         * named-layer reference. It is essentially a filter that allows the selection of fewer features
    110         * than are present in the named layer.
    111         *
    112         * @return the LayerFeatureConstraints
    113         *
    114         */
    115        public LayerFeatureConstraints getLayerFeatureConstraints() {
    116            return layerFeatureConstraints;
    117        }
    118
    119        /**
    120         * sets the <LayerFeatureConstraints>
    121         *
    122         * @param layerFeatureConstraints
    123         *            the LayerFeatureConstraints
    124         *
    125         */
    126        public void setLayerFeatureConstraints( LayerFeatureConstraints layerFeatureConstraints ) {
    127            this.layerFeatureConstraints = layerFeatureConstraints;
    128        }
    129
    130        /**
    131         * Returns the styles associated to the Layer. This may be UserStyles or NamedStyles
    132         * <p>
    133         * </p>
    134         * A UserStyle is at the same semantic level as a NamedStyle used in the context of a WMS. In a
    135         * sense, a named style can be thought of as a reference to a hidden UserStyle that is stored
    136         * inside of a map server.
    137         *
    138         * @return the Styles of the Layer as ArrayList
    139         *
    140         */
    141        public AbstractStyle[] getStyles() {
    142            return styles.toArray( new AbstractStyle[styles.size()] );
    143        }
    144
    145        /**
    146         * Adds styles to the Layer.
    147         *
    148         * @param styles
    149         *            the styles for the layer as Array
    150         */
    151        public void setStyles( AbstractStyle[] styles ) {
    152            this.styles.clear();
    153
    154            if ( styles != null ) {
    155                this.styles = Arrays.asList( styles );
    156            }
    157        }
    158
    159        /**
    160         * @see org.deegree.graphics.sld.AbstractLayer#getStyles()
    161         * @param style
    162         *            a style to add
    163         */
    164        public void addStyle( AbstractStyle style ) {
    165            styles.add( style );
    166        }
    167
    168        /**
    169         * @see org.deegree.graphics.sld.AbstractLayer#getStyles()
    170         * @param style
    171         *            a style to remove
    172         */
    173        public void removeStyle( AbstractStyle style ) {
    174            styles.remove( styles.indexOf( style ) );
    175        }
    176
    177        /**
    178         * returns a STring-Representation of the layer
    179         *
    180         * @return the layer as String
    181         */
    182        @Override
    183        public String toString() {
    184            String ret = getClass().getName() + "\n";
    185            ret = "name = " + name + "\n";
    186            ret += ( "layerFeatureConstraints = " + layerFeatureConstraints + "\n" );
    187            ret += ( "styles = " + styles + "\n" );
    188
    189            return ret;
    190        }
    191
    192    }