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.styling.FeatureTypeStyle;
024: import org.geotools.styling.Style;
025: import org.geotools.styling.StyleFactory;
026: import org.geotools.xml.*;
027:
028: /**
029: * Binding object for the element http://www.opengis.net/sld:UserStyle.
030: *
031: * <p>
032: * <pre>
033: * <code>
034: * <xsd:element name="UserStyle">
035: * <xsd:annotation>
036: * <xsd:documentation> A UserStyle allows user-defined
037: * styling and is semantically equivalent to a WMS
038: * named style. </xsd:documentation>
039: * </xsd:annotation>
040: * <xsd:complexType>
041: * <xsd:sequence>
042: * <xsd:element ref="sld:Name" minOccurs="0"/>
043: * <xsd:element ref="sld:Title" minOccurs="0"/>
044: * <xsd:element ref="sld:Abstract" minOccurs="0"/>
045: * <xsd:element ref="sld:IsDefault" minOccurs="0"/>
046: * <xsd:element ref="sld:FeatureTypeStyle" maxOccurs="unbounded"/>
047: * </xsd:sequence>
048: * </xsd:complexType>
049: * </xsd:element>
050: *
051: * </code>
052: * </pre>
053: * </p>
054: *
055: * @generated
056: */
057: public class SLDUserStyleBinding extends AbstractComplexBinding {
058: StyleFactory styleFactory;
059:
060: public SLDUserStyleBinding(StyleFactory styleFactory) {
061: this .styleFactory = styleFactory;
062: }
063:
064: /**
065: * @generated
066: */
067: public QName getTarget() {
068: return SLD.USERSTYLE;
069: }
070:
071: /**
072: * <!-- begin-user-doc -->
073: * <!-- end-user-doc -->
074: *
075: * @generated modifiable
076: */
077: public int getExecutionMode() {
078: return AFTER;
079: }
080:
081: /**
082: * <!-- begin-user-doc -->
083: * <!-- end-user-doc -->
084: *
085: * @generated modifiable
086: */
087: public Class getType() {
088: return Style.class;
089: }
090:
091: /**
092: * <!-- begin-user-doc -->
093: * <!-- end-user-doc -->
094: *
095: * @generated modifiable
096: */
097: public void initialize(ElementInstance instance, Node node,
098: MutablePicoContainer context) {
099: }
100:
101: /**
102: * <!-- begin-user-doc -->
103: * <!-- end-user-doc -->
104: *
105: * @generated modifiable
106: */
107: public Object parse(ElementInstance instance, Node node,
108: Object value) throws Exception {
109: Style style = styleFactory.createStyle();
110:
111: //<xsd:element ref="sld:Name" minOccurs="0"/>
112: if (node.hasChild("Name")) {
113: style.setName((String) node.getChildValue("Name"));
114: }
115:
116: //<xsd:element ref="sld:Title" minOccurs="0"/>
117: if (node.hasChild("Title")) {
118: style.setTitle((String) node.getChildValue("Title"));
119: }
120:
121: //<xsd:element ref="sld:Abstract" minOccurs="0"/>
122: if (node.hasChild("Abstract")) {
123: style.setAbstract((String) node.getChildValue("Abstract"));
124: }
125:
126: //<xsd:element ref="sld:IsDefault" minOccurs="0"/>
127: if (node.hasChild("IsDefault")) {
128: style
129: .setDefault(((Boolean) node
130: .getChildValue("IsDefault")).booleanValue());
131: }
132:
133: //<xsd:element ref="sld:FeatureTypeStyle" maxOccurs="unbounded"/>
134: List fts = node.getChildValues("FeatureTypeStyle");
135: style.setFeatureTypeStyles((FeatureTypeStyle[]) fts
136: .toArray(new FeatureTypeStyle[fts.size()]));
137:
138: return style;
139: }
140: }
|