root / branches / Mobile_Compatible_Hito_1 / libFMap_data / src / org / gvsig / data / vectorial / filter / ExpressionAbstract.java @ 21563
History | View | Annotate | Download (2.9 KB)
1 |
/*
|
---|---|
2 |
* GeoTools - OpenSource mapping toolkit
|
3 |
* http://geotools.org
|
4 |
* (C) 2006, GeoTools Project Managment Committee (PMC)
|
5 |
*
|
6 |
* This library is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU Lesser General Public
|
8 |
* License as published by the Free Software Foundation;
|
9 |
* version 2.1 of the License.
|
10 |
*
|
11 |
* This library is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
* Lesser General Public License for more details.
|
15 |
*/
|
16 |
package org.gvsig.data.vectorial.filter; |
17 |
|
18 |
import org.gvsig.data.vectorial.Feature; |
19 |
import org.opengis.filter.expression.Expression; |
20 |
import org.opengis.filter.expression.ExpressionVisitor; |
21 |
|
22 |
//
|
23 |
/**
|
24 |
* Abstract superclass of these Expression implementations.
|
25 |
* <p>
|
26 |
* Contains additional support for "Expression chaining". This allows
|
27 |
* Expressions to be constructed as a chain of Java commands similar to the use
|
28 |
* of the java collections api.
|
29 |
* </p>
|
30 |
* <p>
|
31 |
* Note: Expression chaining is a simple developer convience, it has no effect
|
32 |
* on the data model exposed by the GeoAPI interfaces.
|
33 |
* </p>
|
34 |
* <p>
|
35 |
* Idea: We may also be able to teach this implementation to make use of
|
36 |
* JXPath to extract "attribute values" from Java Beans, DOM, JDOM in addition
|
37 |
* to the geotools & geoapi FeatureType models. It is a cunning plan - any
|
38 |
* implementation will make use of this abstract base class.
|
39 |
* </p>
|
40 |
*
|
41 |
* @author Jody Garnett
|
42 |
* @author jcarrasco
|
43 |
*
|
44 |
*/
|
45 |
public abstract class ExpressionAbstract implements Expression, ExpressionType { |
46 |
|
47 |
/** Defines the type of this expression. */
|
48 |
protected short expressionType; |
49 |
|
50 |
/** Subclass should overide, default implementation returns null */
|
51 |
public Object evaluate(Object object) { |
52 |
return null; |
53 |
} |
54 |
|
55 |
/**
|
56 |
* Default implementation delegates handling of context
|
57 |
* conversion to Value utility class.
|
58 |
* <p>
|
59 |
* Subclasses are expected to make use of the Value utility class
|
60 |
* (as the easiest way to provide value morphing in confirmance with
|
61 |
* the Filter specification).
|
62 |
*
|
63 |
*/
|
64 |
public abstract Object evaluate(Object object, Class context); |
65 |
|
66 |
/** Subclass should override, default implementation just returns extraData */
|
67 |
public Object accept(ExpressionVisitor visitor, Object extraData) { |
68 |
return extraData;
|
69 |
} |
70 |
|
71 |
/**
|
72 |
* Helper method for subclasses to reduce null checks
|
73 |
* @param expression
|
74 |
* @param feature
|
75 |
* @return value or null
|
76 |
*/
|
77 |
protected Object eval( Expression expression, Feature feature ){ |
78 |
if( expression == null || feature == null ) return null; |
79 |
return expression.evaluate( feature );
|
80 |
} |
81 |
|
82 |
public short getType() { |
83 |
return expressionType;
|
84 |
} |
85 |
} |