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 javax.xml.namespace.QName;
023: import org.geotools.styling.LayerFeatureConstraints;
024: import org.geotools.styling.NamedLayer;
025: import org.geotools.styling.Style;
026: import org.geotools.styling.StyleFactory;
027: import org.geotools.xml.*;
028:
029: /**
030: * Binding object for the element http://www.opengis.net/sld:NamedLayer.
031: *
032: * <p>
033: * <pre>
034: * <code>
035: * <xsd:element name="NamedLayer">
036: * <xsd:annotation>
037: * <xsd:documentation> A NamedLayer is a layer of data that
038: * has a name advertised by a WMS. </xsd:documentation>
039: * </xsd:annotation>
040: * <xsd:complexType>
041: * <xsd:sequence>
042: * <xsd:element ref="sld:Name"/>
043: * <xsd:element ref="sld:LayerFeatureConstraints" minOccurs="0"/>
044: * <xsd:choice minOccurs="0" maxOccurs="unbounded">
045: * <xsd:element ref="sld:NamedStyle"/>
046: * <xsd:element ref="sld:UserStyle"/>
047: * </xsd:choice>
048: * </xsd:sequence>
049: * </xsd:complexType>
050: * </xsd:element>
051: *
052: * </code>
053: * </pre>
054: * </p>
055: *
056: * @generated
057: */
058: public class SLDNamedLayerBinding extends AbstractComplexBinding {
059: StyleFactory styleFactory;
060:
061: public SLDNamedLayerBinding(StyleFactory styleFactory) {
062: this .styleFactory = styleFactory;
063: }
064:
065: /**
066: * @generated
067: */
068: public QName getTarget() {
069: return SLD.NAMEDLAYER;
070: }
071:
072: /**
073: * <!-- begin-user-doc -->
074: * <!-- end-user-doc -->
075: *
076: * @generated modifiable
077: */
078: public int getExecutionMode() {
079: return AFTER;
080: }
081:
082: /**
083: * <!-- begin-user-doc -->
084: * <!-- end-user-doc -->
085: *
086: * @generated modifiable
087: */
088: public Class getType() {
089: return NamedLayer.class;
090: }
091:
092: /**
093: * <!-- begin-user-doc -->
094: * <!-- end-user-doc -->
095: *
096: * @generated modifiable
097: */
098: public void initialize(ElementInstance instance, Node node,
099: MutablePicoContainer context) {
100: }
101:
102: /**
103: * <!-- begin-user-doc -->
104: * <!-- end-user-doc -->
105: *
106: * @generated modifiable
107: */
108: public Object parse(ElementInstance instance, Node node,
109: Object value) throws Exception {
110: NamedLayer namedLayer = styleFactory.createNamedLayer();
111:
112: //<xsd:element ref="sld:Name"/>
113: namedLayer.setName((String) node.getChildValue("Name"));
114:
115: //<xsd:element ref="sld:LayerFeatureConstraints" minOccurs="0"/>
116: if (node.hasChild("LayerFeatureConstraints")) {
117: LayerFeatureConstraints constraints = (LayerFeatureConstraints) node
118: .getChildValue("LayerFeatureConstraints");
119: namedLayer.setLayerFeatureConstraints(constraints
120: .getFeatureTypeConstraints());
121: }
122:
123: //<xsd:choice minOccurs="0" maxOccurs="unbounded">
124: // <xsd:element ref="sld:NamedStyle"/>
125: // <xsd:element ref="sld:UserStyle"/>
126: //</xsd:choice>
127: for (Iterator itr = node.getChildValues(Style.class).iterator(); itr
128: .hasNext();) {
129: namedLayer.addStyle((Style) itr.next());
130: }
131:
132: return namedLayer;
133: }
134: }
|