001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.sld.bindings;
017:
018: import org.picocontainer.MutablePicoContainer;
019: import org.w3c.dom.Document;
020: import org.w3c.dom.Element;
021: import java.util.ArrayList;
022: import java.util.Iterator;
023: import javax.xml.namespace.QName;
024: import org.geotools.filter.Expression;
025: import org.geotools.filter.FilterFactory;
026: import org.geotools.filter.IllegalFilterException;
027: import org.geotools.xml.*;
028:
029: /**
030: * Binding object for the type http://www.opengis.net/sld:ParameterValueType.
031: *
032: * <p>
033: * <pre>
034: * <code>
035: * <xsd:complexType name="ParameterValueType" mixed="true">
036: * <xsd:annotation>
037: * <xsd:documentation> The "ParameterValueType"
038: * uses WFS-Filter expressions to give values for SLD
039: * graphic parameters. A "mixed" element-content
040: * model is used with textual substitution for values. </xsd:documentation>
041: * </xsd:annotation>
042: * <xsd:sequence minOccurs="0" maxOccurs="unbounded">
043: * <xsd:element ref="ogc:expression"/>
044: * </xsd:sequence>
045: * </xsd:complexType>
046: *
047: * </code>
048: * </pre>
049: * </p>
050: *
051: * @generated
052: */
053: public class SLDParameterValueTypeBinding extends
054: AbstractComplexBinding {
055: FilterFactory filterFactory;
056:
057: public SLDParameterValueTypeBinding(FilterFactory filterFactory) {
058: this .filterFactory = filterFactory;
059: }
060:
061: /**
062: * @generated
063: */
064: public QName getTarget() {
065: return SLD.PARAMETERVALUETYPE;
066: }
067:
068: /**
069: * <!-- begin-user-doc -->
070: * <!-- end-user-doc -->
071: *
072: * @generated modifiable
073: */
074: public int getExecutionMode() {
075: return OVERRIDE;
076: }
077:
078: /**
079: * <!-- begin-user-doc -->
080: * <!-- end-user-doc -->
081: *
082: * @generated modifiable
083: */
084: public Class getType() {
085: return Expression.class;
086: }
087:
088: /**
089: * <!-- begin-user-doc -->
090: * <!-- end-user-doc -->
091: *
092: * @generated modifiable
093: */
094: public void initialize(ElementInstance instance, Node node,
095: MutablePicoContainer context) {
096: }
097:
098: /**
099: * <!-- begin-user-doc -->
100: * Even though the spec allows an instance of ParamterValueType to have
101: * multiple expressions as children, it is more often that there is only
102: * one. Therefore this binding returns the first expression it finds or
103: * null. If a subtype needs multiple expressions they should ovveride.
104: * <!-- end-user-doc -->
105: *
106: * @generated modifiable
107: */
108: public Object parse(ElementInstance instance, Node node,
109: Object value) throws Exception {
110: //first look for an expresion in the child text
111: String text = instance.getText();
112:
113: if ((text != null) && !"".equals(text)) {
114: return filterFactory.createLiteralExpression(text);
115: }
116:
117: for (Iterator itr = node.getChildren().iterator(); itr
118: .hasNext();) {
119: Node child = (Node) itr.next();
120:
121: if (child.getValue() instanceof Expression) {
122: return child.getValue();
123: }
124: }
125:
126: return null;
127: }
128: }
|