/*
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
* (C) 2002-2008, 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.sld.bindings;
import java.util.Iterator;
import javax.xml.namespace.QName;
import org.geotools.filter.Filters;
import org.geotools.sld.CssParameter;
import org.geotools.styling.Graphic;
import org.geotools.styling.Stroke;
import org.geotools.styling.StyleFactory;
import org.geotools.xml.AbstractComplexBinding;
import org.geotools.xml.ElementInstance;
import org.geotools.xml.Node;
import org.opengis.filter.expression.Expression;
import org.picocontainer.MutablePicoContainer;
/**
* Binding object for the element http://www.opengis.net/sld:Stroke.
*
* <p>
* <pre>
* <code>
* <xsd:element name="Stroke">
* <xsd:annotation>
* <xsd:documentation> A "Stroke" specifies the
* appearance of a linear geometry. It is defined in
* parallel with SVG strokes. The following CssParameters
* may be used: "stroke" (color),
* "stroke-opacity", "stroke-width",
* "stroke-linejoin", "stroke-linecap",
* "stroke-dasharray", and
* "stroke-dashoffset". </xsd:documentation>
* </xsd:annotation>
* <xsd:complexType>
* <xsd:sequence>
* <xsd:choice minOccurs="0">
* <xsd:element ref="sld:GraphicFill"/>
* <xsd:element ref="sld:GraphicStroke"/>
* </xsd:choice>
* <xsd:element ref="sld:CssParameter" minOccurs="0" maxOccurs="unbounded"/>
* </xsd:sequence>
* </xsd:complexType>
* </xsd:element>
*
* </code>
* </pre>
* </p>
*
* @generated
*
* @source $URL$
*/
public class SLDStrokeBinding extends AbstractComplexBinding {
StyleFactory styleFactory;
public SLDStrokeBinding(StyleFactory styleFactory) {
this.styleFactory = styleFactory;
}
/**
* @generated
*/
public QName getTarget() {
return SLD.STROKE;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated modifiable
*/
public int getExecutionMode() {
return AFTER;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated modifiable
*/
public Class getType() {
return Stroke.class;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated modifiable
*/
public void initialize(ElementInstance instance, Node node, MutablePicoContainer context) {
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated modifiable
*/
public Object parse(ElementInstance instance, Node node, Object value)
throws Exception {
//The following CssParameters may be used:
//"stroke" (color),
//"stroke-opacity"
//"stroke-width",
//"stroke-linejoin"
//"stroke-linecap",
//"stroke-dasharray",
//"stroke-dashoffset".
Expression color = null;
//The following CssParameters may be used:
//"stroke" (color),
//"stroke-opacity"
//"stroke-width",
//"stroke-linejoin"
//"stroke-linecap",
//"stroke-dasharray",
//"stroke-dashoffset".
Expression opacity = null;
//The following CssParameters may be used:
//"stroke" (color),
//"stroke-opacity"
//"stroke-width",
//"stroke-linejoin"
//"stroke-linecap",
//"stroke-dasharray",
//"stroke-dashoffset".
Expression width = null;
//The following CssParameters may be used:
//"stroke" (color),
//"stroke-opacity"
//"stroke-width",
//"stroke-linejoin"
//"stroke-linecap",
//"stroke-dasharray",
//"stroke-dashoffset".
Expression lineJoin = null;
Expression lineCap = null;
Expression dashArray = null;
Expression dashOffset = null;
for (Iterator i = node.getChildValues(CssParameter.class).iterator(); i.hasNext();) {
CssParameter css = (CssParameter) i.next();
if (css.getExpressions().isEmpty()) {
continue;
}
if ("stroke".equals(css.getName())) {
color = (Expression) css.getExpressions().get(0);
} else if ("stroke-opacity".equals(css.getName())) {
opacity = (Expression) css.getExpressions().get(0);
} else if ("stroke-width".equals(css.getName())) {
width = (Expression) css.getExpressions().get(0);
} else if ("stroke-linejoin".equals(css.getName())) {
lineJoin = (Expression) css.getExpressions().get(0);
} else if ("stroke-linecap".equals(css.getName())) {
lineCap = (Expression) css.getExpressions().get(0);
} else if ("stroke-dasharray".equals(css.getName())) {
dashArray = (Expression) css.getExpressions().get(0);
} else if ("stroke-dashoffset".equals(css.getName())) {
dashOffset = (Expression) css.getExpressions().get(0);
}
}
float[] dash = null;
if (dashArray != null) {
String[] string = Filters.asString(dashArray).split(" +");
dash = new float[string.length];
for (int i = 0; i < string.length; i++) {
dash[i] = Float.parseFloat(string[i]);
}
}
//<xsd:choice minOccurs="0">
// <xsd:element ref="sld:GraphicFill"/>
// <xsd:element ref="sld:GraphicStroke"/>
//</xsd:choice>
Graphic graphicFill = (Graphic) node.getChildValue("GraphicFill");
Graphic graphicStroke = (Graphic) node.getChildValue("GraphicStroke");
return styleFactory.createStroke(color, width, opacity, lineJoin, lineCap, dash,
dashOffset, graphicFill, graphicStroke);
}
}