Revision 19405 trunk/libraries/libDataSourceBaseDrivers/src/org/gvsig/data/datastores/vectorial/driver/dbf/DBFFeatureCollection.java
DBFFeatureCollection.java | ||
---|---|---|
8 | 8 |
import org.gvsig.data.ComplexObservable; |
9 | 9 |
import org.gvsig.data.IObservable; |
10 | 10 |
import org.gvsig.data.vectorial.IFeature; |
11 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
|
12 | 11 |
import org.gvsig.data.vectorial.IFeatureCollection; |
13 | 12 |
import org.gvsig.data.vectorial.IFeatureID; |
14 | 13 |
import org.gvsig.data.vectorial.IFeatureType; |
15 | 14 |
import org.gvsig.data.vectorial.expansionadapter.FeatureManager; |
16 |
import org.nfunk.jep.JEP; |
|
17 |
import org.nfunk.jep.Node; |
|
15 |
import org.gvsig.data.vectorial.filter.FeatureFilterParser; |
|
18 | 16 |
|
19 | 17 |
public class DBFFeatureCollection implements IFeatureCollection { |
20 | 18 |
protected ComplexObservable observable = new ComplexObservable(); |
... | ... | |
23 | 21 |
protected String filter; |
24 | 22 |
protected String order; |
25 | 23 |
protected DBFDriver driver; |
26 |
private JEP parser = null;
|
|
24 |
private FeatureFilterParser parser = null;
|
|
27 | 25 |
protected FeatureManager featureManager; |
28 | 26 |
protected long driverFeatureCount=0; |
29 | 27 |
protected boolean modified=false; |
... | ... | |
39 | 37 |
this.order=order; |
40 | 38 |
} |
41 | 39 |
protected void parseExpression(String filter){ |
42 |
parser = new JEP(); |
|
43 |
parser.setAllowUndeclared(true); |
|
44 |
parser.addStandardFunctions(); |
|
45 |
// parser.parseExpression(filter); |
|
40 |
parser = new FeatureFilterParser(filter,this.featureType); |
|
46 | 41 |
} |
47 |
protected void setVarValue (String varName, Object value){ |
|
48 |
parser.addVariable(varName, value); |
|
49 |
} |
|
42 |
|
|
50 | 43 |
protected boolean evaluate(IFeature feature) throws Exception{ |
51 |
if (filter==null) |
|
44 |
if (filter==null){
|
|
52 | 45 |
return true; |
53 |
|
|
54 |
for (int i=0;i<featureType.size();i++){ |
|
55 |
IFeatureAttributeDescriptor fad=(IFeatureAttributeDescriptor)featureType.get(i); |
|
56 |
setVarValue(fad.getName(),feature.get(i)); |
|
57 | 46 |
} |
58 |
|
|
59 |
Node function = parser.parse(filter); |
|
60 |
Object output = parser.evaluate(function); |
|
61 |
if (output instanceof Double){ |
|
62 |
return (((Double)output).doubleValue()!=0.0); |
|
63 |
} |
|
64 |
|
|
65 |
return(parser.getValue()!=0.0); |
|
47 |
return parser.match(feature); |
|
66 | 48 |
} |
49 |
|
|
67 | 50 |
public int size() { |
68 | 51 |
if (filter==null){ |
69 | 52 |
return (int)(driverFeatureCount+featureManager.getNum()); |
Also available in: Unified diff