001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-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; either
009: * version 2.1 of the License, or (at your option) any later version.
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: * Created on Jan 24, 2004
017: */
018: package org.geotools.validation.attributes;
019:
020: import org.geotools.feature.Feature;
021: import org.geotools.feature.FeatureType;
022: import org.geotools.validation.DefaultFeatureValidation;
023: import org.geotools.validation.ValidationResults;
024:
025: /**
026: * PointCoveredByLineValidation purpose.
027: *
028: * <p>
029: * Completes the specified attribute comparison.
030: * </p>
031: *
032: * @author dzwiers, Refractions Research, Inc.
033: * @author $Author: dmzwiers $ (last modification)
034: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/validation/src/main/java/org/geotools/validation/attributes/AttributeValidation.java $
035: * @version $Id: AttributeValidation.java 22266 2006-10-19 11:30:55Z acuster $
036: */
037: public class AttributeValidation extends DefaultFeatureValidation {
038: public static final int LESS_THAN = -1;
039: public static final int EQUALITY = 0;
040: public static final int GREATER_THAN = 1;
041: private String attributeComparisonValue;
042: private String attributeName;
043: private int attributeComparisonType;
044:
045: /**
046: * PointCoveredByLineValidation constructor.
047: *
048: * <p>
049: * Super
050: * </p>
051: */
052: public AttributeValidation() {
053: super ();
054: }
055:
056: /**
057: * Completes the specified comparison.
058: *
059: * @param feature Feature to be Validated
060: * @param type FeatureTypeInfo schema of feature
061: * @param results coallate results information
062: *
063: *
064: * @see org.geotools.validation.FeatureValidation#validate(org.geotools.feature.Feature,
065: * org.geotools.feature.FeatureType,
066: * org.geotools.validation.ValidationResults)
067: */
068: public boolean validate(Feature feature, FeatureType type,
069: ValidationResults results) {
070: int surface = ((Integer) feature.getAttribute("surface"))
071: .intValue();
072: int speed = ((Integer) feature.getAttribute("speed"))
073: .intValue();
074: if (surface == 1 && speed > 110) {
075: results.error(feature, "speed over 110");
076: return false;
077: }
078: if (surface == 2 && speed > 110) {
079: results.error(feature, "speed over 70");
080: return false;
081: }
082: return true;
083: }
084:
085: /**
086: * Access attributeComparisonType property.
087: *
088: * @return Returns the attributeComparisonType.
089: */
090: public int getAttributeComparisonType() {
091: return attributeComparisonType;
092: }
093:
094: /**
095: * Set attributeComparisonType to attributeComparisonType.
096: *
097: * @param attributeComparisonType The attributeComparisonType to set.
098: */
099: public void setAttributeComparisonType(int attributeComparisonType) {
100: this .attributeComparisonType = attributeComparisonType;
101: }
102:
103: /**
104: * Access attributeComparisonValue property.
105: *
106: * @return Returns the attributeComparisonValue.
107: */
108: public String getAttributeComparisonValue() {
109: return attributeComparisonValue;
110: }
111:
112: /**
113: * Set attributeComparisonValue to attributeComparisonValue.
114: *
115: * @param attributeComparisonValue The attributeComparisonValue to set.
116: */
117: public void setAttributeComparisonValue(
118: String attributeComparisonValue) {
119: this .attributeComparisonValue = attributeComparisonValue;
120: }
121:
122: /**
123: * Access attributeName property.
124: *
125: * @return Returns the attributeName.
126: */
127: public String getAttributeName() {
128: return attributeName;
129: }
130:
131: /**
132: * Set attributeName to attributeName.
133: *
134: * @param attributeName The attributeName to set.
135: */
136: public void setAttributeName(String attributeName) {
137: this.attributeName = attributeName;
138: }
139: }
|