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 javax.xml.namespace.QName;
022: import org.opengis.filter.expression.PropertyName;
023: import org.geotools.filter.Expression;
024: import org.geotools.styling.Fill;
025: import org.geotools.styling.Font;
026: import org.geotools.styling.Halo;
027: import org.geotools.styling.LabelPlacement;
028: import org.geotools.styling.StyleFactory;
029: import org.geotools.styling.TextSymbolizer;
030: import org.geotools.xml.*;
031:
032: /**
033: * Binding object for the element http://www.opengis.net/sld:TextSymbolizer.
034: *
035: * <p>
036: * <pre>
037: * <code>
038: * <xsd:element name="TextSymbolizer" substitutionGroup="sld:Symbolizer">
039: * <xsd:annotation>
040: * <xsd:documentation> A "TextSymbolizer" is used
041: * to render text labels according to various graphical
042: * parameters. </xsd:documentation>
043: * </xsd:annotation>
044: * <xsd:complexType>
045: * <xsd:complexContent>
046: * <xsd:extension base="sld:SymbolizerType">
047: * <xsd:sequence>
048: * <xsd:element ref="sld:Geometry" minOccurs="0"/>
049: * <xsd:element ref="sld:Label" minOccurs="0"/>
050: * <xsd:element ref="sld:Font" minOccurs="0"/>
051: * <xsd:element ref="sld:LabelPlacement" minOccurs="0"/>
052: * <xsd:element ref="sld:Halo" minOccurs="0"/>
053: * <xsd:element ref="sld:Fill" minOccurs="0"/>
054: * </xsd:sequence>
055: * </xsd:extension>
056: * </xsd:complexContent>
057: * </xsd:complexType>
058: * </xsd:element>
059: *
060: * </code>
061: * </pre>
062: * </p>
063: *
064: * @generated
065: */
066: public class SLDTextSymbolizerBinding extends AbstractComplexBinding {
067: StyleFactory styleFactory;
068:
069: public SLDTextSymbolizerBinding(StyleFactory styleFactory) {
070: this .styleFactory = styleFactory;
071: }
072:
073: /**
074: * @generated
075: */
076: public QName getTarget() {
077: return SLD.TEXTSYMBOLIZER;
078: }
079:
080: /**
081: * <!-- begin-user-doc -->
082: * <!-- end-user-doc -->
083: *
084: * @generated modifiable
085: */
086: public int getExecutionMode() {
087: return AFTER;
088: }
089:
090: /**
091: * <!-- begin-user-doc -->
092: * <!-- end-user-doc -->
093: *
094: * @generated modifiable
095: */
096: public Class getType() {
097: return TextSymbolizer.class;
098: }
099:
100: /**
101: * <!-- begin-user-doc -->
102: * <!-- end-user-doc -->
103: *
104: * @generated modifiable
105: */
106: public void initialize(ElementInstance instance, Node node,
107: MutablePicoContainer context) {
108: }
109:
110: /**
111: * <!-- begin-user-doc -->
112: * <!-- end-user-doc -->
113: *
114: * @generated modifiable
115: */
116: public Object parse(ElementInstance instance, Node node,
117: Object value) throws Exception {
118: TextSymbolizer ts = styleFactory.createTextSymbolizer();
119:
120: //<xsd:element ref="sld:Geometry" minOccurs="0"/>
121: if (node.hasChild("Geometry")) {
122: PropertyName propertyName = (PropertyName) node
123: .getChildValue("Geometry");
124: ts.setGeometryPropertyName(propertyName.getPropertyName());
125: }
126:
127: //<xsd:element ref="sld:Label" minOccurs="0"/>
128: if (node.hasChild("Label")) {
129: ts.setLabel((Expression) node.getChildValue("Label"));
130: }
131:
132: //<xsd:element ref="sld:Font" minOccurs="0"/>
133: if (node.hasChild("Font")) {
134: ts
135: .setFonts(new Font[] { (Font) node
136: .getChildValue("Font") });
137: }
138:
139: //<xsd:element ref="sld:LabelPlacement" minOccurs="0"/>
140: if (node.hasChild("LabelPlacement")) {
141: ts.setPlacement((LabelPlacement) node
142: .getChildValue("LabelPlacement"));
143: }
144:
145: //<xsd:element ref="sld:Halo" minOccurs="0"/>
146: if (node.hasChild("Halo")) {
147: ts.setHalo((Halo) node.getChildValue("Halo"));
148: }
149:
150: //<xsd:element ref="sld:Fill" minOccurs="0"/>
151: if (node.hasChild("Fill")) {
152: ts.setFill((Fill) node.getChildValue("Fill"));
153: }
154:
155: return ts;
156: }
157: }
|