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.filter.Expression;
023: import org.geotools.filter.FilterFactory;
024: import org.geotools.styling.ColorMapEntry;
025: import org.geotools.styling.StyleFactory;
026: import org.geotools.xml.*;
027:
028: /**
029: * Binding object for the element http://www.opengis.net/sld:ColorMapEntry.
030: *
031: * <p>
032: * <pre>
033: * <code>
034: * <xsd:element name="ColorMapEntry">
035: * <xsd:complexType>
036: * <xsd:attribute name="color" type="xsd:string" use="required"/>
037: * <xsd:attribute name="opacity" type="xsd:double"/>
038: * <xsd:attribute name="quantity" type="xsd:double"/>
039: * <xsd:attribute name="label" type="xsd:string"/>
040: * </xsd:complexType>
041: * </xsd:element>
042: *
043: * </code>
044: * </pre>
045: * </p>
046: *
047: * @generated
048: */
049: public class SLDColorMapEntryBinding extends AbstractComplexBinding {
050: StyleFactory styleFactory;
051: FilterFactory filterFactory;
052:
053: public SLDColorMapEntryBinding(StyleFactory styleFactory,
054: FilterFactory filterFactory) {
055: this .styleFactory = styleFactory;
056: this .filterFactory = filterFactory;
057: }
058:
059: /**
060: * @generated
061: */
062: public QName getTarget() {
063: return SLD.COLORMAPENTRY;
064: }
065:
066: /**
067: * <!-- begin-user-doc -->
068: * <!-- end-user-doc -->
069: *
070: * @generated modifiable
071: */
072: public int getExecutionMode() {
073: return AFTER;
074: }
075:
076: /**
077: * <!-- begin-user-doc -->
078: * <!-- end-user-doc -->
079: *
080: * @generated modifiable
081: */
082: public Class getType() {
083: return ColorMapEntry.class;
084: }
085:
086: /**
087: * <!-- begin-user-doc -->
088: * <!-- end-user-doc -->
089: *
090: * @generated modifiable
091: */
092: public void initialize(ElementInstance instance, Node node,
093: MutablePicoContainer context) {
094: }
095:
096: /**
097: * <!-- begin-user-doc -->
098: * <!-- end-user-doc -->
099: *
100: * @generated modifiable
101: */
102: public Object parse(ElementInstance instance, Node node,
103: Object value) throws Exception {
104: ColorMapEntry entry = styleFactory.createColorMapEntry();
105:
106: Expression color = filterFactory
107: .createLiteralExpression((String) node
108: .getAttributeValue("color"));
109: entry.setColor(color);
110:
111: if (node.getAttributeValue("opacity") != null) {
112: Double opacity = (Double) node.getAttributeValue("opacity");
113: entry.setOpacity(filterFactory
114: .createLiteralExpression(opacity.doubleValue()));
115: }
116:
117: if (node.getAttributeValue("quantity") != null) {
118: Double quantity = (Double) node
119: .getAttributeValue("quantity");
120: entry.setQuantity(filterFactory
121: .createLiteralExpression(quantity.doubleValue()));
122: }
123:
124: if (node.getAttributeValue("label") != null) {
125: String label = (String) node.getAttributeValue("label");
126: entry.setLabel(label);
127: }
128:
129: return entry;
130: }
131: }
|