/*
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
* (C) 2002-2010, Open Source Geospatial Foundation (OSGeo)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
package org.geotools.se.v1_1.bindings;
import org.geotools.se.v1_1.SE;
import org.geotools.xml.*;
import org.opengis.filter.FilterFactory;
import org.opengis.filter.expression.Expression;
import org.opengis.filter.expression.Function;
import javax.xml.namespace.QName;
/**
* Binding object for the element http://www.opengis.net/se:Substring.
*
* <p>
*
* <pre>
* <code>
* <xsd:element name="Substring" substitutionGroup="se:Function" type="se:SubstringType">
* <xsd:annotation>
* <xsd:documentation>
* Returns substrings.
* </xsd:documentation>
* </xsd:annotation>
* </xsd:element>
*
* </code>
* </pre>
*
* <pre>
* <code>
* <xsd:complexType name="SubstringType">
* <xsd:complexContent>
* <xsd:extension base="se:FunctionType">
* <xsd:sequence>
* <xsd:element ref="se:StringValue"/>
* <xsd:element minOccurs="0" ref="se:Position"/>
* <xsd:element minOccurs="0" ref="se:Length"/>
* </xsd:sequence>
* </xsd:extension>
* </xsd:complexContent>
* </xsd:complexType>
*
* </code>
* </pre>
*
* </p>
*
* @generated
*
* @source $URL: http://svn.osgeo.org/geotools/branches/2.7.x/build/maven/javadoc/../../../modules/extension/xsd/xsd-sld/src/main/java/org/geotools/se/v1_1/bindings/SubstringBinding.java $
*/
public class SubstringBinding extends AbstractComplexBinding {
FilterFactory filterFactory;
public SubstringBinding(FilterFactory filterFactory) {
this.filterFactory = filterFactory;
}
/**
* @generated
*/
public QName getTarget() {
return SE.Substring;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated modifiable
*/
public Class getType() {
return Expression.class;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated modifiable
*/
public Object parse(ElementInstance instance, Node node, Object value) throws Exception {
//<xsd:element ref="se:StringValue"/>
Expression string = (Expression) node.getChildValue("StringValue");
//<xsd:element minOccurs="0" ref="se:Position"/>
Expression position = (Expression) node.getChildValue("Position");
//function is one based
position = filterFactory.subtract(position, filterFactory.literal(1));
//<xsd:element minOccurs="0" ref="se:Length"/>
Expression length = (Expression) node.getChildValue("Length");
//our strSubstring function works with begin,end rather than begin,length
Expression end = filterFactory.add(position, length);
return filterFactory.function("strSubstring", string, position, end);
}
}