Statistics
| Revision:

root / trunk / libraries / libDataSource / src / org / gvsig / data / vectorial / filter / FeatureFilterParser.java @ 19456

History | View | Annotate | Download (1.58 KB)

1
package org.gvsig.data.vectorial.filter;
2

    
3
import java.util.Map.Entry;
4

    
5
import org.gvsig.data.exception.ParseException;
6
import org.gvsig.data.exception.ReadException;
7
import org.gvsig.data.vectorial.IFeature;
8
import org.gvsig.data.vectorial.IFeatureType;
9
import org.medfoster.sqljep.BaseJEP;
10

    
11

    
12
public class FeatureFilterParser extends BaseJEP {
13
        private IFeatureType featureType;
14
        private IFeature feature;
15
        private boolean parsed = false;
16
        private String expresion;
17

    
18
        public FeatureFilterParser(String expression,IFeatureType featureType) {
19
                super(expression);
20
                this.expresion=expression;
21
                this.featureType = featureType;
22
        }
23

    
24
        public int findColumn(String fieldName) {
25
                return featureType.indexOf(fieldName);
26
        }
27

    
28
        public Comparable getColumnObject(int fieldPos){
29
                return (Comparable)this.feature.get(fieldPos);
30
        }
31

    
32
        public Entry getVariable(String arg0){
33
                return new FeatureEntry(arg0);
34
        }
35

    
36

    
37
        public boolean match(IFeature feature) throws ReadException{
38
                try{
39
                        this.feature = feature;
40
                        if (!parsed){
41
                                this.parseExpression();
42
                                parsed=true;
43
                        }
44
                        Comparable value = super.getValue();
45
                        return value.compareTo(Boolean.TRUE) == 0;
46
                } catch (org.medfoster.sqljep.ParseException e) {
47
                        throw new ParseException("FeatureFilterParser",this.expresion,e);
48
                }
49
        }
50

    
51
        private class FeatureEntry implements Entry{
52
                private String key;
53

    
54
                public FeatureEntry(String key){
55
                        this.key = key;
56
                }
57

    
58
                public Object getKey() {
59
                        return this.key;
60
                }
61

    
62
                public Object getValue() {
63
                        Object value =feature.get(this.key);
64
                        return value;
65
                }
66

    
67
                public Object setValue(Object arg0) {
68
                        return null;
69
                }
70

    
71
        }
72

    
73
}