/* * GeoTools - The Open Source Java GIS Toolkit * http://geotools.org * * (C) 2002-2010, Open Source Geospatial Foundation (OSGeo) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ package org.geotools.se.v1_1.bindings; import java.util.List; import org.geotools.se.v1_1.SE; import org.geotools.styling.ColorMap; import org.geotools.styling.ColorMapEntry; import org.geotools.styling.StyleFactory; import org.geotools.xml.*; import org.opengis.filter.FilterFactory; import org.opengis.filter.expression.Expression; import javax.xml.namespace.QName; /** * Binding object for the element http://www.opengis.net/se:Categorize. * * <p> * * <pre> * <code> * <xsd:element name="Categorize" substitutionGroup="se:Function" type="se:CategorizeType"> * <xsd:annotation> * <xsd:documentation> * The transformation of continuous values to distinct values. * </xsd:documentation> * </xsd:annotation> * </xsd:element> * * </code> * </pre> * * <pre> * <code> * <xsd:complexType name="CategorizeType"> * <xsd:complexContent> * <xsd:extension base="se:FunctionType"> * <xsd:sequence> * <xsd:element ref="se:LookupValue"/> * <xsd:element ref="se:Value"/> * <xsd:sequence maxOccurs="unbounded" minOccurs="0"> * <xsd:element ref="se:Threshold"/> * <xsd:element ref="se:Value"/> * </xsd:sequence> * </xsd:sequence> * <xsd:attribute name="threshholdsBelongTo" * type="se:ThreshholdsBelongToType" use="optional"/> * </xsd:extension> * </xsd:complexContent> * </xsd:complexType> * * </code> * </pre> * * </p> * * @generated * * @source $URL: http://svn.osgeo.org/geotools/trunk/modules/extension/xsd/xsd-sld/src/main/java/org/geotools/se/v1_1/bindings/CategorizeBinding.java $ */ public class CategorizeBinding extends AbstractComplexBinding { StyleFactory styleFactory; FilterFactory filterFactory; public CategorizeBinding(StyleFactory styleFactory, FilterFactory filterFactory) { this.styleFactory = styleFactory; this.filterFactory = filterFactory; } /** * @generated */ public QName getTarget() { return SE.Categorize; } /** * <!-- begin-user-doc --> <!-- end-user-doc --> * * @generated modifiable */ public Class getType() { return ColorMap.class; } /** * <!-- begin-user-doc --> <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { ColorMap map = styleFactory.createColorMap(); List<Node> children = node.getChildren(); int i = 0; while(!"Value".equals(children.get(i).getComponent().getName())) i++; ColorMapEntry entry = styleFactory.createColorMapEntry(); entry.setColor((Expression)children.get(i++).getValue()); map.addColorMapEntry(entry); while(i < children.size()) { entry = styleFactory.createColorMapEntry(); entry.setQuantity((Expression)children.get(i).getValue()); if (i+1 >= children.size()) { throw new IllegalArgumentException("Incorrectly specified color map Threshold/Value pair"); } entry.setColor((Expression)children.get(i+1).getValue()); map.addColorMapEntry(entry); i+=2; } return map; } }