001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/portal/context/SLD.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.portal.context;
037    
038    import java.net.URL;
039    
040    import org.deegree.graphics.sld.FeatureTypeStyle;
041    import org.deegree.graphics.sld.StyledLayerDescriptor;
042    
043    /**
044     * This class encapsulates the descriptions of a SLD element as defined by the OGC Web Map Context specification.
045     * <p>
046     * The &lt;SLD&gt; element must contain required &lt;Name&gt; and optional &lt;Title&gt; elements which identify the
047     * particular element of a Styled Layer Descriptor to be used for this style. The &lt;SLD&gt; element must then contain
048     * one of three alternative sources of description of a layer style:
049     * </p>
050     * <p>
051     * 1. an &lt;OnlineResource&gt; element describing a link to the specified SLD document.<p/> &lt;OnlineResource
052     * xmlns:xlink="http://www.w3.org/TR/xlink" xlink:type="simple"
053     * xlink:href=�http://example.org/this/is/an/example/link/to/the/sld"&gt;
054     * </p>
055     * <p>
056     * This reference may be to a separately referenced SLD document or to an inline &lt;StyledLayerDescriptor&gt; in the
057     * same context document (which may define the styles for multiple layers within the Web Map Context)
058     * </p>
059     * <p>
060     * 2. &lt;StyledLayerDescriptor&gt; element containing inline the namedStyle or userStyle named in the enclosing
061     * &lt;Style&gt; element
062     * </p>
063     * <p>
064     * 3. &lt;FeatureTypeStyle&gt; element containing inline the specific feature styling instructions for the enclosing
065     * &lt;Style&gt; element
066     *
067     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
068     * @version $Revision: 18195 $
069     */
070    public class SLD {
071        private FeatureTypeStyle featureTypeStyle = null;
072    
073        private String name = null;
074    
075        private String title = null;
076    
077        private StyledLayerDescriptor styledLayerDescriptor = null;
078    
079        private URL onlineResource = null;
080    
081        /**
082         * Creates a new SLD object.
083         *
084         * @param name
085         *            name of the SLD
086         * @param title
087         *            title of the SLD
088         */
089        private SLD( String name, String title ) {
090            setName( name );
091            setTitle( title );
092        }
093    
094        /**
095         * Creates a new SLD object.
096         *
097         * @param name
098         *            name of the SLD
099         * @param title
100         *            title of the SLD
101         * @param styledLayerDescriptor
102         *            complete StyledLayerDescriptor
103         *
104         * @throws ContextException
105         */
106        public SLD( String name, String title, StyledLayerDescriptor styledLayerDescriptor ) throws ContextException {
107            this( name, title );
108            setStyledLayerDescriptor( styledLayerDescriptor );
109        }
110    
111        /**
112         * Creates a new SLD object.
113         *
114         * @param name
115         *            name of the SLD
116         * @param title
117         *            title of the SLD
118         * @param onlineResource
119         *            online resource where to access the StyledLayerDescriptor
120         *
121         * @throws ContextException
122         */
123        public SLD( String name, String title, URL onlineResource ) throws ContextException {
124            this( name, title );
125            setOnlineResource( onlineResource );
126        }
127    
128        /**
129         * Creates a new SLD object.
130         *
131         * @param name
132         *            name of the SLD
133         * @param title
134         *            title of the SLD
135         * @param featureTypeStyle
136         *            one concrete FeatureTypeStyle as part of a StyledLayerDescriptor
137         *
138         * @throws ContextException
139         */
140        public SLD( String name, String title, FeatureTypeStyle featureTypeStyle ) throws ContextException {
141            this( name, title );
142            setFeatureTypeStyle( featureTypeStyle );
143        }
144    
145        /**
146         * name of the SLD
147         *
148         * @return name of the SLD
149         */
150        public String getName() {
151            return name;
152        }
153    
154        /**
155         * title of the SLD
156         *
157         * @return title of the SLD
158         */
159        public String getTitle() {
160            return title;
161        }
162    
163        /**
164         * describing a link to the specified SLD document.
165         *
166         * @return a link to the specified SLD document.
167         */
168        public URL getOnlineResource() {
169            return onlineResource;
170        }
171    
172        /**
173         * containing inline the specific feature styling instructions for the enclosing <code>&lt;Style&gt;</code>
174         * element
175         *
176         * @return the enclosing <code>&lt;Style&gt;</code> element
177         */
178        public FeatureTypeStyle getFeatureTypeStyle() {
179            return featureTypeStyle;
180        }
181    
182        /**
183         * inline the namedStyle or userStyle named in the enclosing &lt;Style&gt; element
184         *
185         * @return the namedStyle or userStyle
186         */
187        public StyledLayerDescriptor getStyledLayerDescriptor() {
188            return styledLayerDescriptor;
189        }
190    
191        /**
192         * see also org.deegree.clients.context.SLD#getName()
193         *
194         * @param name
195         */
196        public void setName( String name ) {
197            this.name = name;
198        }
199    
200        /**
201         * see also org.deegree.clients.context.Server#getTitle()
202         *
203         * @param title
204         */
205        public void setTitle( String title ) {
206            this.title = title;
207        }
208    
209        /**
210         * see also org.deegree.clients.context.Server#getOnlineResource()
211         *
212         * @param onlineResource
213         *
214         * @throws ContextException
215         */
216        public void setOnlineResource( URL onlineResource )
217                                throws ContextException {
218            if ( onlineResource == null ) {
219                throw new ContextException( "onlineResource isn't allowed to be null" );
220            }
221    
222            this.onlineResource = onlineResource;
223        }
224    
225        /**
226         * see also org.deegree.clients.context.SLD#getFeatureTypeStyle()
227         *
228         * @param featureTypeStyle
229         *
230         * @throws ContextException
231         */
232        public void setFeatureTypeStyle( FeatureTypeStyle featureTypeStyle )
233                                throws ContextException {
234            if ( featureTypeStyle == null ) {
235                throw new ContextException( "featureTypeStyle isn't allowed to be null" );
236            }
237    
238            this.featureTypeStyle = featureTypeStyle;
239        }
240    
241        /**
242         * see also org.deegree.clients.context.SLD#getStyledLayerDescriptor()
243         *
244         * @param styledLayerDescriptor
245         *
246         * @throws ContextException
247         */
248        public void setStyledLayerDescriptor( StyledLayerDescriptor styledLayerDescriptor )
249                                throws ContextException {
250            if ( styledLayerDescriptor == null ) {
251                throw new ContextException( "onlineResource isn't allowed to be null" );
252            }
253    
254            this.styledLayerDescriptor = styledLayerDescriptor;
255        }
256    
257    }