svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / impl / expressionevaluator / DefaultFeatureSymbolTable.java @ 44205
History | View | Annotate | Download (5.54 KB)
1 | 43983 | jjdelcerro | package org.gvsig.fmap.dal.impl.expressionevaluator; |
---|---|---|---|
2 | |||
3 | import org.apache.commons.lang3.Range; |
||
4 | import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
||
5 | import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
||
6 | import org.gvsig.expressionevaluator.Interpreter; |
||
7 | 44100 | jjdelcerro | import org.gvsig.expressionevaluator.MutableSymbolTable; |
8 | 43983 | jjdelcerro | import org.gvsig.expressionevaluator.spi.AbstractFunction; |
9 | import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
||
10 | 43987 | jjdelcerro | import org.gvsig.fmap.dal.DataManager; |
11 | 43983 | jjdelcerro | import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
12 | import org.gvsig.fmap.dal.feature.Feature; |
||
13 | 44205 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
14 | 43983 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureSelection; |
15 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
16 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
17 | 43984 | jjdelcerro | import org.gvsig.tools.script.Script; |
18 | import org.gvsig.tools.util.UnmodifiableBasicList; |
||
19 | 43983 | jjdelcerro | |
20 | /**
|
||
21 | *
|
||
22 | * @author jjdelcerro
|
||
23 | */
|
||
24 | public class DefaultFeatureSymbolTable extends AbstractSymbolTable implements FeatureSymbolTable { |
||
25 | |||
26 | private class FeatureFunction extends AbstractFunction { |
||
27 | |||
28 | public FeatureFunction() {
|
||
29 | super(
|
||
30 | "Data access",
|
||
31 | "feature",
|
||
32 | Range.is(0),
|
||
33 | "Access to the current feature object when used in a filter.\n"
|
||
34 | + "Return null if used outer a filter.",
|
||
35 | "feature()",
|
||
36 | null,
|
||
37 | "Feature"
|
||
38 | ); |
||
39 | } |
||
40 | |||
41 | @Override
|
||
42 | public Object call(Interpreter interpreter, Object[] args) throws Exception { |
||
43 | return feature;
|
||
44 | } |
||
45 | |||
46 | } |
||
47 | |||
48 | public class FeatureStoreFunction extends AbstractFunction { |
||
49 | |||
50 | public FeatureStoreFunction() {
|
||
51 | super(
|
||
52 | "Data access",
|
||
53 | "store",
|
||
54 | Range.is(0),
|
||
55 | "Access to the current store object when used in a filter.\n"
|
||
56 | + "Return null if used outer a filter.",
|
||
57 | "store()",
|
||
58 | null,
|
||
59 | "FeatureStore"
|
||
60 | ); |
||
61 | } |
||
62 | |||
63 | @Override
|
||
64 | public Object call(Interpreter interpreter, Object[] args) throws Exception { |
||
65 | 43987 | jjdelcerro | if( feature==null ) { |
66 | return null; |
||
67 | } |
||
68 | 43983 | jjdelcerro | return feature.getStore();
|
69 | } |
||
70 | |||
71 | } |
||
72 | |||
73 | public class IsSelectedFunction extends AbstractFunction { |
||
74 | |||
75 | public IsSelectedFunction() {
|
||
76 | super(
|
||
77 | "Data access",
|
||
78 | "isSelected",
|
||
79 | Range.is(0),
|
||
80 | "Return if the current feature is selected in the store when used in a filter.\n"
|
||
81 | + "Return false if used outer a filter.",
|
||
82 | "isSelected()",
|
||
83 | null,
|
||
84 | "Boolean"
|
||
85 | ); |
||
86 | } |
||
87 | |||
88 | @Override
|
||
89 | public Object call(Interpreter interpreter, Object[] args) throws Exception { |
||
90 | 43987 | jjdelcerro | if( feature==null ) { |
91 | return false; |
||
92 | } |
||
93 | 43983 | jjdelcerro | FeatureStore store = feature.getStore(); |
94 | FeatureSelection selection = store.getFeatureSelection(); |
||
95 | return selection.isSelected(feature);
|
||
96 | } |
||
97 | |||
98 | } |
||
99 | |||
100 | private Feature feature;
|
||
101 | private FeatureType type;
|
||
102 | |||
103 | 43987 | jjdelcerro | @SuppressWarnings("OverridableMethodCallInConstructor") |
104 | 43983 | jjdelcerro | public DefaultFeatureSymbolTable() {
|
105 | 43987 | jjdelcerro | super(DataManager.FEATURE_SYMBOL_TABLE);
|
106 | 43983 | jjdelcerro | |
107 | this.addFunction(new FeatureFunction()); |
||
108 | this.addFunction(new FeatureStoreFunction()); |
||
109 | this.addFunction(new IsSelectedFunction()); |
||
110 | } |
||
111 | |||
112 | 43984 | jjdelcerro | @SuppressWarnings("OverridableMethodCallInConstructor") |
113 | public DefaultFeatureSymbolTable(Script userScript, UnmodifiableBasicList<Script> scripts) {
|
||
114 | this();
|
||
115 | if (userScript != null) { |
||
116 | this.getScripts().add(userScript);
|
||
117 | } |
||
118 | if (scripts != null && !scripts.isEmpty()) { |
||
119 | for (Script script : scripts) {
|
||
120 | this.getScripts().add(script);
|
||
121 | } |
||
122 | } |
||
123 | } |
||
124 | |||
125 | 43983 | jjdelcerro | @Override
|
126 | public FeatureSymbolTable clone() throws CloneNotSupportedException { |
||
127 | DefaultFeatureSymbolTable other = (DefaultFeatureSymbolTable) super.clone();
|
||
128 | return other;
|
||
129 | } |
||
130 | |||
131 | @Override
|
||
132 | public boolean exists(String name) { |
||
133 | 43987 | jjdelcerro | if (type!=null && type.get(name) != null) { |
134 | 43983 | jjdelcerro | return true; |
135 | } |
||
136 | return false; |
||
137 | } |
||
138 | |||
139 | @Override
|
||
140 | public Object value(String name) { |
||
141 | 43987 | jjdelcerro | if( feature==null ) { |
142 | return null; |
||
143 | } |
||
144 | 43983 | jjdelcerro | return this.feature.get(name); |
145 | } |
||
146 | |||
147 | @Override
|
||
148 | 44205 | jjdelcerro | public boolean isSQLCompatible(String name) { |
149 | if( this.type == null ) { |
||
150 | return super.isSQLCompatible(name); |
||
151 | } |
||
152 | FeatureAttributeDescriptor attrdesc = this.type.getAttributeDescriptor(name);
|
||
153 | if( attrdesc == null ) { |
||
154 | return true; |
||
155 | } |
||
156 | if( attrdesc.isComputed() ) {
|
||
157 | return false; |
||
158 | } |
||
159 | return true; |
||
160 | } |
||
161 | |||
162 | @Override
|
||
163 | 43983 | jjdelcerro | public void setFeature(Feature feature) { |
164 | this.feature = feature;
|
||
165 | this.type = feature.getType();
|
||
166 | } |
||
167 | |||
168 | 44100 | jjdelcerro | @Override
|
169 | public MutableSymbolTable createParent() {
|
||
170 | ExpressionEvaluatorManager expManager = ExpressionEvaluatorLocator.getManager(); |
||
171 | |||
172 | MutableSymbolTable symbolTable = expManager.createSymbolTable(); |
||
173 | symbolTable.addSymbolTable(this);
|
||
174 | return symbolTable;
|
||
175 | } |
||
176 | |||
177 | |||
178 | 43983 | jjdelcerro | public static void selfRegister() { |
179 | ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
||
180 | 44128 | jjdelcerro | manager.registerSymbolTable(new DefaultfeatureSymbolTableFactory());
|
181 | 43983 | jjdelcerro | } |
182 | } |