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.geotools.styling.ChannelSelection;
023: import org.geotools.styling.SelectedChannelType;
024: import org.geotools.styling.StyleFactory;
025: import org.geotools.xml.*;
026:
027: /**
028: * Binding object for the element http://www.opengis.net/sld:ChannelSelection.
029: *
030: * <p>
031: *
032: * <pre>
033: * <code>
034: * <xsd:element name="ChannelSelection">
035: * <xsd:annotation>
036: * <xsd:documentation> "ChannelSelection"
037: * specifies the false-color channel selection for a
038: * multi-spectral raster source. </xsd:documentation>
039: * </xsd:annotation>
040: * <xsd:complexType>
041: * <xsd:choice>
042: * <xsd:sequence>
043: * <xsd:element ref="sld:RedChannel"/>
044: * <xsd:element ref="sld:GreenChannel"/>
045: * <xsd:element ref="sld:BlueChannel"/>
046: * </xsd:sequence>
047: * <xsd:element ref="sld:GrayChannel"/>
048: * </xsd:choice>
049: * </xsd:complexType>
050: * </xsd:element>
051: *
052: *
053: * </code>
054: * </pre>
055: *
056: * </p>
057: *
058: * @generated
059: */
060: public class SLDChannelSelectionBinding extends AbstractComplexBinding {
061: StyleFactory styleFactory;
062:
063: public SLDChannelSelectionBinding(StyleFactory styleFactory) {
064: this .styleFactory = styleFactory;
065: }
066:
067: /**
068: * @generated
069: */
070: public QName getTarget() {
071: return SLD.CHANNELSELECTION;
072: }
073:
074: /**
075: * <!-- begin-user-doc --> <!-- end-user-doc -->
076: *
077: * @generated modifiable
078: */
079: public int getExecutionMode() {
080: return AFTER;
081: }
082:
083: /**
084: * <!-- begin-user-doc --> <!-- end-user-doc -->
085: *
086: * @generated modifiable
087: */
088: public Class getType() {
089: return ChannelSelection.class;
090: }
091:
092: /**
093: * <!-- begin-user-doc --> <!-- 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 --> <!-- end-user-doc -->
103: *
104: * @generated modifiable
105: */
106: public Object parse(ElementInstance instance, Node node,
107: Object value) throws Exception {
108: if ((node.getChild("RedChannel") == null)
109: || (node.getChild("BlueChannel") == null)
110: || (node.getChild("GreenChannel") == null)
111: || (node.getChild("GrayChannel") == null)) {
112: String msg = "All of Red,Blue,Green,Gray must be specified";
113: throw new RuntimeException(msg);
114: }
115:
116: SelectedChannelType[] rgb = new SelectedChannelType[] {
117: (SelectedChannelType) node.getChildValue("RedChannel"),
118: (SelectedChannelType) node
119: .getChildValue("GreenChannel"),
120: (SelectedChannelType) node.getChildValue("BlueChannel") };
121: SelectedChannelType gray = (SelectedChannelType) node
122: .getChildValue("GrayChannel");
123:
124: ChannelSelection cs = styleFactory.createChannelSelection(null);
125: cs.setGrayChannel(gray);
126: cs.setRGBChannels(rgb);
127:
128: return cs;
129: }
130: }
|