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.List;
022: import javax.xml.namespace.QName;
023: import org.geotools.filter.Filter;
024: import org.geotools.styling.Graphic;
025: import org.geotools.styling.Rule;
026: import org.geotools.styling.StyleFactory;
027: import org.geotools.styling.Symbolizer;
028: import org.geotools.xml.*;
029:
030: /**
031: * Binding object for the element http://www.opengis.net/sld:Rule.
032: *
033: * <p>
034: * <pre>
035: * <code>
036: * <xsd:element name="Rule">
037: * <xsd:annotation>
038: * <xsd:documentation> A Rule is used to attach
039: * property/scale conditions to and group the
040: * individual symbolizers used for rendering. </xsd:documentation>
041: * </xsd:annotation>
042: * <xsd:complexType>
043: * <xsd:sequence>
044: * <xsd:element ref="sld:Name" minOccurs="0"/>
045: * <xsd:element ref="sld:Title" minOccurs="0"/>
046: * <xsd:element ref="sld:Abstract" minOccurs="0"/>
047: * <xsd:element ref="sld:LegendGraphic" minOccurs="0"/>
048: * <xsd:choice minOccurs="0">
049: * <xsd:element ref="ogc:Filter"/>
050: * <xsd:element ref="sld:ElseFilter"/>
051: * </xsd:choice>
052: * <xsd:element ref="sld:MinScaleDenominator" minOccurs="0"/>
053: * <xsd:element ref="sld:MaxScaleDenominator" minOccurs="0"/>
054: * <xsd:element ref="sld:Symbolizer" maxOccurs="unbounded"/>
055: * </xsd:sequence>
056: * </xsd:complexType>
057: * </xsd:element>
058: *
059: * </code>
060: * </pre>
061: * </p>
062: *
063: * @generated
064: */
065: public class SLDRuleBinding extends AbstractComplexBinding {
066: StyleFactory styleFactory;
067:
068: public SLDRuleBinding(StyleFactory styleFactory) {
069: this .styleFactory = styleFactory;
070: }
071:
072: /**
073: * @generated
074: */
075: public QName getTarget() {
076: return SLD.RULE;
077: }
078:
079: /**
080: * <!-- begin-user-doc -->
081: * <!-- end-user-doc -->
082: *
083: * @generated modifiable
084: */
085: public int getExecutionMode() {
086: return AFTER;
087: }
088:
089: /**
090: * <!-- begin-user-doc -->
091: * <!-- end-user-doc -->
092: *
093: * @generated modifiable
094: */
095: public Class getType() {
096: return Rule.class;
097: }
098:
099: /**
100: * <!-- begin-user-doc -->
101: * <!-- end-user-doc -->
102: *
103: * @generated modifiable
104: */
105: public void initialize(ElementInstance instance, Node node,
106: MutablePicoContainer context) {
107: }
108:
109: /**
110: * <!-- begin-user-doc -->
111: * <!-- end-user-doc -->
112: *
113: * @generated modifiable
114: */
115: public Object parse(ElementInstance instance, Node node,
116: Object value) throws Exception {
117: Rule rule = styleFactory.createRule();
118:
119: //<xsd:element ref="sld:Name" minOccurs="0"/>
120: if (node.hasChild("Name")) {
121: rule.setName((String) node.getChildValue("Name"));
122: }
123:
124: //<xsd:element ref="sld:Title" minOccurs="0"/>
125: if (node.hasChild("Title")) {
126: rule.setTitle((String) node.getChildValue("Title"));
127: }
128:
129: //<xsd:element ref="sld:Abstract" minOccurs="0"/>
130: if (node.hasChild("Abstract")) {
131: rule.setAbstract((String) node.getChildValue("Abstract"));
132: }
133:
134: //<xsd:element ref="sld:LegendGraphic" minOccurs="0"/>
135: if (node.hasChild("LegendGraphic")) {
136: rule.setLegendGraphic(new Graphic[] { (Graphic) node
137: .getChildValue("LegendGraphic") });
138: }
139:
140: //<xsd:choice minOccurs="0">
141: // <xsd:element ref="ogc:Filter"/>
142: // <xsd:element ref="sld:ElseFilter"/>
143: //</xsd:choice>
144: if (node.hasChild(Filter.class)) {
145: rule.setFilter((Filter) node.getChildValue(Filter.class));
146: } else if (node.hasChild("ElseFilter")) {
147: rule.setIsElseFilter(true);
148: }
149:
150: //<xsd:element ref="sld:MinScaleDenominator" minOccurs="0"/>
151: if (node.hasChild("MinScaleDenominator")) {
152: rule.setMinScaleDenominator(((Double) node
153: .getChildValue("MinScaleDenominator"))
154: .doubleValue());
155: }
156:
157: //<xsd:element ref="sld:MaxScaleDenominator" minOccurs="0"/>
158: if (node.hasChild("MaxScaleDenominator")) {
159: rule.setMaxScaleDenominator(((Double) node
160: .getChildValue("MaxScaleDenominator"))
161: .doubleValue());
162: }
163:
164: //<xsd:element ref="sld:Symbolizer" maxOccurs="unbounded"/>
165: List syms = node.getChildValues(Symbolizer.class);
166: rule.setSymbolizers((Symbolizer[]) syms
167: .toArray(new Symbolizer[syms.size()]));
168:
169: return rule;
170: }
171: }
|