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.NamedLayer;
024: import org.geotools.styling.StyleFactory;
025: import org.geotools.styling.StyledLayer;
026: import org.geotools.styling.StyledLayerDescriptor;
027: import org.geotools.styling.UserLayer;
028: import org.geotools.xml.*;
029:
030: /**
031: * Binding object for the element http://www.opengis.net/sld:StyledLayerDescriptor.
032: *
033: * <p>
034: * <pre>
035: * <code>
036: * <xsd:element name="StyledLayerDescriptor">
037: * <xsd:annotation>
038: * <xsd:documentation> A StyledLayerDescriptor is a
039: * sequence of styled layers, represented at the first
040: * level by NamedLayer and UserLayer elements. </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:choice minOccurs="0" maxOccurs="unbounded">
048: * <xsd:element ref="sld:NamedLayer"/>
049: * <xsd:element ref="sld:UserLayer"/>
050: * </xsd:choice>
051: * </xsd:sequence>
052: * <xsd:attribute name="version" type="xsd:string" use="required" fixed="1.0.0"/>
053: * </xsd:complexType>
054: * </xsd:element>
055: *
056: * </code>
057: * </pre>
058: * </p>
059: *
060: * @generated
061: */
062: public class SLDStyledLayerDescriptorBinding extends
063: AbstractComplexBinding {
064: StyleFactory styleFactory;
065:
066: public SLDStyledLayerDescriptorBinding(StyleFactory styleFactory) {
067: this .styleFactory = styleFactory;
068: }
069:
070: /**
071: * @generated
072: */
073: public QName getTarget() {
074: return SLD.STYLEDLAYERDESCRIPTOR;
075: }
076:
077: /**
078: * <!-- begin-user-doc -->
079: * <!-- end-user-doc -->
080: *
081: * @generated modifiable
082: */
083: public int getExecutionMode() {
084: return AFTER;
085: }
086:
087: /**
088: * <!-- begin-user-doc -->
089: * <!-- end-user-doc -->
090: *
091: * @generated modifiable
092: */
093: public Class getType() {
094: return StyledLayerDescriptor.class;
095: }
096:
097: /**
098: * <!-- begin-user-doc -->
099: * <!-- end-user-doc -->
100: *
101: * @generated modifiable
102: */
103: public void initialize(ElementInstance instance, Node node,
104: MutablePicoContainer context) {
105: }
106:
107: /**
108: * <!-- begin-user-doc -->
109: * <!-- end-user-doc -->
110: *
111: * @generated modifiable
112: */
113: public Object parse(ElementInstance instance, Node node,
114: Object value) throws Exception {
115: StyledLayerDescriptor sld = styleFactory
116: .createStyledLayerDescriptor();
117:
118: //<xsd:element ref="sld:Name" minOccurs="0"/>
119: if (node.hasChild("Name")) {
120: sld.setName((String) node.getChildValue("Name"));
121: }
122:
123: //<xsd:element ref="sld:Title" minOccurs="0"/>
124: if (node.hasChild("Title")) {
125: sld.setTitle((String) node.getChildValue("Title"));
126: }
127:
128: //<xsd:element ref="sld:Abstract" minOccurs="0"/>
129: if (node.hasChild("Abstract")) {
130: sld.setAbstract((String) node.getChildValue("Abstract"));
131: }
132:
133: //<xsd:choice minOccurs="0" maxOccurs="unbounded">
134: // <xsd:element ref="sld:NamedLayer"/>
135: // <xsd:element ref="sld:UserLayer"/>
136: //</xsd:choice>
137: StyledLayer[] layers = null;
138:
139: if (node.hasChild(NamedLayer.class)) {
140: List namedLayers = node.getChildValues(NamedLayer.class);
141: layers = (StyledLayer[]) namedLayers
142: .toArray(new StyledLayer[namedLayers.size()]);
143: } else if (node.hasChild(UserLayer.class)) {
144: List userLayers = node.getChildValues(UserLayer.class);
145: layers = (StyledLayer[]) userLayers
146: .toArray(new StyledLayer[userLayers.size()]);
147: }
148:
149: sld.setStyledLayers(layers);
150:
151: //<xsd:attribute name="version" type="xsd:string" use="required" fixed="1.0.0"/>
152: //TODO: no version?
153: return sld;
154: }
155: }
|