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.Iterator;
022: import java.util.List;
023: import javax.xml.namespace.QName;
024: import org.geotools.filter.Expression;
025: import org.geotools.sld.CssParameter;
026: import org.geotools.styling.Fill;
027: import org.geotools.styling.Graphic;
028: import org.geotools.styling.StyleFactory;
029: import org.geotools.xml.AbstractComplexBinding;
030: import org.geotools.xml.ElementInstance;
031: import org.geotools.xml.Node;
032:
033: /**
034: * Binding object for the element http://www.opengis.net/sld:Fill.
035: *
036: * <p>
037: * <pre>
038: * <code>
039: * <xsd:element name="Fill">
040: * <xsd:annotation>
041: * <xsd:documentation> A "Fill" specifies the
042: * pattern for filling an area geometry. The allowed
043: * CssParameters are: "fill" (color) and
044: * "fill-opacity". </xsd:documentation>
045: * </xsd:annotation>
046: * <xsd:complexType>
047: * <xsd:sequence>
048: * <xsd:element ref="sld:GraphicFill" minOccurs="0"/>
049: * <xsd:element ref="sld:CssParameter" minOccurs="0" maxOccurs="unbounded"/>
050: * </xsd:sequence>
051: * </xsd:complexType>
052: * </xsd:element>
053: *
054: * </code>
055: * </pre>
056: * </p>
057: *
058: * @generated
059: */
060: public class SLDFillBinding extends AbstractComplexBinding {
061: StyleFactory styleFactory;
062:
063: public SLDFillBinding(StyleFactory styleFactory) {
064: this .styleFactory = styleFactory;
065: }
066:
067: /**
068: * @generated
069: */
070: public QName getTarget() {
071: return SLD.FILL;
072: }
073:
074: /**
075: * <!-- begin-user-doc -->
076: * <!-- end-user-doc -->
077: *
078: * @generated modifiable
079: */
080: public int getExecutionMode() {
081: return AFTER;
082: }
083:
084: /**
085: * <!-- begin-user-doc -->
086: * <!-- end-user-doc -->
087: *
088: * @generated modifiable
089: */
090: public Class getType() {
091: return Fill.class;
092: }
093:
094: /**
095: * <!-- begin-user-doc -->
096: * <!-- end-user-doc -->
097: *
098: * @generated modifiable
099: */
100: public void initialize(ElementInstance instance, Node node,
101: MutablePicoContainer context) {
102: }
103:
104: /**
105: * <!-- begin-user-doc -->
106: * <!-- end-user-doc -->
107: *
108: * @generated modifiable
109: */
110: public Object parse(ElementInstance instance, Node node,
111: Object value) throws Exception {
112: Expression color = null;
113: Expression opacity = null;
114: Graphic graphicFill = null;
115:
116: graphicFill = (Graphic) node.getChildValue("GraphicFill");
117:
118: //"fill" (color)
119: //"fill-opacity"
120: List params = node.getChildValues("CssParameter");
121:
122: for (Iterator itr = params.iterator(); itr.hasNext();) {
123: CssParameter param = (CssParameter) itr.next();
124:
125: if ("fill".equals(param.getName())) {
126: color = (Expression) param.getExpressions().get(0);
127: }
128:
129: if ("fill-opacity".equals(param.getName())) {
130: opacity = (Expression) param.getExpressions().get(0);
131: }
132: }
133:
134: Fill fill = styleFactory.createFill(color);
135:
136: if (opacity != null) {
137: fill.setOpacity(opacity);
138: }
139:
140: return fill;
141: }
142: }
|