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.filter;
017:
018: import org.geotools.feature.Feature;
019: import org.opengis.filter.FilterVisitor;
020: import org.opengis.filter.PropertyIsNull;
021:
022: /**
023: * Defines a null filter, which checks to see if an attribute is null.
024: *
025: * @author Rob Hranac, Vision for New York
026: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/filter/NullFilterImpl.java $
027: * @version $Id: NullFilterImpl.java 24253 2007-02-07 13:19:42Z groldan $
028: */
029: public class NullFilterImpl extends AbstractFilterImpl implements
030: NullFilter {
031: /** The null check value, which must be an attribute expression. */
032: private org.opengis.filter.expression.Expression nullCheck = null;
033:
034: /**
035: * Constructor which sets the type as null check.
036: */
037: protected NullFilterImpl() {
038: super (FilterFactoryFinder.createFilterFactory());
039: filterType = NULL;
040: }
041:
042: /**
043: * Determines whether or not a given feature is 'inside' this filter.
044: *
045: * @param nullCheck The attribute expression to null check.
046: *
047: * @throws IllegalFilterException If attempting to add a non-attribute
048: * expression.
049: *
050: * @task REVISIT: change arg to AttributeExpression?
051: * @task REVISIT: change name to setNullCheckValue.
052: *
053: * @deprecated use {@link PropertyIsNull#setExpression(Expression)}
054: */
055: public final void nullCheckValue(Expression nullCheck)
056: throws IllegalFilterException {
057: setExpression(nullCheck);
058: }
059:
060: /**
061: * Returns the expression being checked for null.
062: *
063: * @return the Expression to null check.
064: *
065: * @deprecated use {@link #getExpression()}.
066: */
067: public final Expression getNullCheckValue() {
068: return (Expression) getExpression();
069: }
070:
071: /**
072: * Returns the expression which represents the null check.
073: */
074: public org.opengis.filter.expression.Expression getExpression() {
075: return nullCheck;
076: }
077:
078: /**
079: * Sets the expression which represents the null check.
080: */
081: public void setExpression(
082: org.opengis.filter.expression.Expression nullCheck) {
083: if (nullCheck instanceof AttributeExpression) {
084: this .nullCheck = nullCheck;
085: } else {
086: throw new IllegalFilterException(
087: "Attempted to add non-attribute expression to a null filter.");
088: }
089: }
090:
091: /**
092: * Determines whether or not a given feature is 'inside' this filter.
093: *
094: * @param feature Specified feature to examine.
095: *
096: * @return Flag confirming whether or not this feature is inside the
097: * filter.
098: */
099: public boolean evaluate(Object feature) {
100: if (nullCheck == null) {
101: return false;
102: } else {
103: return (nullCheck.evaluate(feature) == null);
104: }
105: }
106:
107: /**
108: * Returns a string representation of this filter.
109: *
110: * @return String representation of the null filter.
111: */
112: public String toString() {
113: return "[ " + nullCheck.toString() + " is null ]";
114: }
115:
116: /**
117: * Compares this filter to the specified object. Returns true if the
118: * passed in object is the same as this filter. Checks to make sure the
119: * filter types, and the NullCheckValue are the same.
120: *
121: * @param obj - the object to compare this LikeFilter against.
122: *
123: * @return true if specified object is equal to this filter; false
124: * otherwise.
125: */
126: public boolean equals(Object obj) {
127: if (obj != null && obj.getClass() == this .getClass()) {
128: NullFilterImpl nullFilter = (NullFilterImpl) obj;
129:
130: return ((nullFilter.getFilterType() == this .filterType) && nullFilter
131: .getNullCheckValue().equals(this .nullCheck));
132: } else {
133: return false;
134: }
135: }
136:
137: /**
138: * Override of hashCode method.
139: *
140: * @return a hash code value for this geometry filter.
141: */
142: public int hashCode() {
143: int result = 17;
144: result = (37 * result)
145: + ((nullCheck == null) ? 0 : nullCheck.hashCode());
146:
147: return result;
148: }
149:
150: /**
151: * Used by FilterVisitors to perform some action on this filter instance.
152: * Typicaly used by Filter decoders, but may also be used by any thing
153: * which needs infomration from filter structure. Implementations should
154: * always call: visitor.visit(this); It is importatant that this is not
155: * left to a parent class unless the parents API is identical.
156: *
157: * @param visitor The visitor which requires access to this filter, the
158: * method must call visitor.visit(this);
159: */
160: public Object accept(FilterVisitor visitor, Object extraData) {
161: return visitor.visit(this, extraData);
162: }
163: }
|