001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/graphics/sld/ParameterValueType.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: 53177 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.io.Serializable;
047: import java.util.ArrayList;
048:
049: import org.deegree.framework.xml.Marshallable;
050: import org.deegree.model.feature.Feature;
051: import org.deegree.model.filterencoding.Expression;
052: import org.deegree.model.filterencoding.FilterEvaluationException;
053:
054: /**
055: *
056: *
057: *
058: * @version $Revision: 9340 $
059: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
060: * @author last edited by: $Author: apoth $
061: *
062: * @version $Revision: 9340 $
063: */
064: public class ParameterValueType implements Serializable, Marshallable {
065:
066: private static final long serialVersionUID = -2232181501775429152L;
067:
068: private ArrayList<Object> components = new ArrayList<Object>();
069:
070: /**
071: * Constructs a new <tt>ParameterValueType</tt>.
072: * <p>
073: *
074: * @param components
075: * <tt>String</tt>s/<tt>Expression</tt> s that make up the contents of the
076: * <tt>ParameterValueType</tt>
077: */
078: public ParameterValueType(Object[] components) {
079: setComponents(components);
080: }
081:
082: /**
083: * Returns the contents (mix of <tt>String</tt>/<tt>Expression</tt> -objects) of this
084: * <tt>ParameterValueType</tt>.
085: * <p>
086: *
087: * @return mix of <tt>String</tt>/<tt>Expression</tt> -objects
088: *
089: */
090: public Object[] getComponents() {
091: return components.toArray(new Object[components.size()]);
092: }
093:
094: /**
095: * Sets the contents (mix of <tt>String</tt>/<tt>Expression</tt> -objects) of this
096: * <tt>ParameterValueType</tt>.
097: * <p>
098: *
099: * @param components
100: * mix of <tt>String</tt> and <tt>Expression</tt> -objects
101: */
102: public void setComponents(Object[] components) {
103: this .components.clear();
104:
105: if (components != null) {
106: this .components.ensureCapacity(components.length);
107: for (int i = 0; i < components.length; i++) {
108: this .components.add(components[i]);
109: }
110: }
111: }
112:
113: /**
114: * Concatenates a component (a<tt>String</tt> or an <tt>Expression</tt> -object) to this
115: * <tt>ParameterValueType</tt>.
116: * <p>
117: *
118: * @param component
119: * either a <tt>String</tt> or an <tt>Expression</tt> -object
120: */
121: public void addComponent(Object component) {
122: components.add(component);
123: }
124:
125: /**
126: * Removes a component (a<tt>String</tt> or an <tt>Expression</tt> -object) from this
127: * <tt>ParameterValueType</tt>.
128: * <p>
129: *
130: * @param component
131: * either a <tt>String</tt> or an <tt>Expression</tt> -object
132: */
133: public void removeComponent(Object component) {
134: components.remove(components.indexOf(component));
135: }
136:
137: /**
138: * Returns the actual <tt>String</tt> value of this object. Expressions are evaluated
139: * according to the given <tt>Feature</tt> -instance.
140: * <p>
141: *
142: * @param feature
143: * used for the evaluation of the underlying 'wfs:Expression'-elements
144: * @return the (evaluated) String value
145: * @throws FilterEvaluationException
146: * if the evaluation fails
147: */
148: public String evaluate(Feature feature)
149: throws FilterEvaluationException {
150: StringBuffer sb = new StringBuffer();
151:
152: for (int i = 0; i < components.size(); i++) {
153: Object component = components.get(i);
154: if (component instanceof Expression) {
155: sb.append(((Expression) component).evaluate(feature));
156: } else if (component != null && component instanceof String) {
157: sb.append(((String) component).trim());
158: } else {
159: sb.append(component);
160: }
161: }
162:
163: return sb.toString();
164: }
165:
166: /**
167: * Exports the content of the ParameterValueType as an XML formatted String.
168: *
169: * @return xml representation of the ParameterValueType
170: */
171: public String exportAsXML() {
172:
173: StringBuffer sb = new StringBuffer();
174: for (int i = 0; i < components.size(); i++) {
175: Object component = components.get(i);
176: if (component instanceof Expression) {
177: sb.append(((Expression) component).toXML());
178: } else if (component != null && component instanceof String) {
179: sb.append(((String) component).trim());
180: } else {
181: sb.append(component);
182: }
183: }
184: return sb.toString();
185: }
186:
187: @Override
188: public String toString() {
189: return exportAsXML();
190: }
191:
192: }
|