001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/graphics/sld/FeatureTypeConstraint.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 by:
006: EXSE, Department of Geography, University of Bonn
007: http://www.giub.uni-bonn.de/deegree/
008: lat/lon GmbH
009: http://www.lat-lon.de
010:
011: This library is free software; you can redistribute it and/or
012: modify it under the terms of the GNU Lesser General Public
013: License as published by the Free Software Foundation; either
014: version 2.1 of the License, or (at your option) any later version.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: Contact:
026:
027: Andreas Poth
028: lat/lon GmbH
029: Aennchenstr. 19
030: 53115 Bonn
031: Germany
032: E-Mail: poth@lat-lon.de
033:
034: Prof. Dr. Klaus Greve
035: Department of Geography
036: University of Bonn
037: Meckenheimer Allee 166
038: 53115 Bonn
039: Germany
040: E-Mail: greve@giub.uni-bonn.de
041:
042:
043: ---------------------------------------------------------------------------*/
044: package org.deegree.graphics.sld;
045:
046: import java.util.ArrayList;
047: import java.util.List;
048:
049: import org.deegree.datatypes.QualifiedName;
050: import org.deegree.framework.xml.Marshallable;
051: import org.deegree.model.filterencoding.Filter;
052:
053: /**
054: * A FeatureTypeConstraint element is used to identify a feature type by well-known name, using the
055: * FeatureTypeName element.
056: *
057: * @author <a href="mailto:k.lupp@web.de">Katharina Lupp </a>
058: * @version $Revision: 9340 $ $Date: 2007-12-27 04:32:12 -0800 (Thu, 27 Dec 2007) $
059: */
060:
061: public class FeatureTypeConstraint implements Marshallable {
062:
063: private List<Extent> extents = null;
064:
065: private Filter filter = null;
066:
067: private QualifiedName featureTypeName = null;
068:
069: /**
070: * constructor initializing the class with the <FeatureTypeConstraint>
071: */
072: public FeatureTypeConstraint(QualifiedName featureTypeName,
073: Filter filter, Extent[] extents) {
074: if (extents != null) {
075: this .extents = new ArrayList<Extent>(extents.length);
076: setExtents(extents);
077: }
078: setFeatureTypeName(featureTypeName);
079: setFilter(filter);
080:
081: }
082:
083: /**
084: * returns the name of the feature type
085: *
086: * @return the name of the feature type
087: */
088: public QualifiedName getFeatureTypeName() {
089: return featureTypeName;
090: }
091:
092: /**
093: * sets the name of the feature type
094: *
095: * @param featureTypeName
096: * the name of the feature type
097: */
098: public void setFeatureTypeName(QualifiedName featureTypeName) {
099: this .featureTypeName = featureTypeName;
100: }
101:
102: /**
103: * returns a feature-filter as defined in WFS specifications.
104: *
105: * @return the filter of the FeatureTypeConstraints
106: */
107: public Filter getFilter() {
108: return filter;
109: }
110:
111: /**
112: * sets a feature-filter as defined in WFS specifications.
113: *
114: * @param filter
115: * the filter of the FeatureTypeConstraints
116: */
117: public void setFilter(Filter filter) {
118: this .filter = filter;
119: }
120:
121: /**
122: * returns the extent for filtering the feature type
123: *
124: * @return the extent for filtering the feature type
125: */
126: public Extent[] getExtents() {
127: if (this .extents != null) {
128: return extents.toArray(new Extent[extents.size()]);
129: }
130: return new Extent[0];
131: }
132:
133: /**
134: * sets the extent for filtering the feature type
135: *
136: * @param extents
137: * extents for filtering the feature type
138: */
139: public void setExtents(Extent[] extents) {
140: if (this .extents != null) {
141: this .extents.clear();
142: }
143:
144: if (extents != null) {
145: for (int i = 0; i < extents.length; i++) {
146: addExtent(extents[i]);
147: }
148: }
149: }
150:
151: /**
152: * Adds an Extent to the Extent-List of a FeatureTypeConstraint
153: *
154: * @param extent
155: * an extent to add
156: */
157: public void addExtent(Extent extent) {
158: if (this .extents != null) {
159: extents = new ArrayList<Extent>();
160: }
161: extents.add(extent);
162: }
163:
164: /**
165: * Removes an Extent from the Extent-List of a FeatureTypeConstraint
166: *
167: * @param extent
168: * an extent to remove
169: */
170: public void removeExtent(Extent extent) {
171: extents.remove(extents.indexOf(extent));
172: }
173:
174: /**
175: * @return the FeatureTypeConstraint as String
176: */
177: public String toString() {
178: String ret = getClass().getName() + "\n";
179: ret = "featureTypeName = " + featureTypeName + "\n";
180: ret += ("filter = " + filter + "\n");
181: ret += ("extents = " + extents + "\n");
182:
183: return ret;
184: }
185:
186: /**
187: * exports the content of the FeatureTypeConstraint as XML formated String
188: *
189: * @return xml representation of the FeatureTypeConstraint
190: */
191: public String exportAsXML() {
192:
193: StringBuffer sb = new StringBuffer(1000);
194: sb.append("<FeatureTypeConstraint>");
195: if (featureTypeName.getNamespace() == null) {
196: sb.append("<FeatureTypeName>");
197: sb.append(featureTypeName.getLocalName());
198: } else {
199: sb.append("<FeatureTypeName xmlns:").append(
200: featureTypeName.getPrefix());
201: sb.append("='").append(
202: featureTypeName.getNamespace().toASCIIString())
203: .append("'>");
204: sb.append(featureTypeName.getPrefixedName());
205: }
206: sb.append("</FeatureTypeName>");
207: if (filter != null) {
208: sb.append(filter.toXML());
209: }
210: if (extents != null) {
211: for (int i = 0; i < extents.size(); i++) {
212: sb
213: .append(((Marshallable) extents.get(i))
214: .exportAsXML());
215: }
216: }
217: sb.append("</FeatureTypeConstraint>");
218:
219: return sb.toString();
220: }
221:
222: }
|