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 @ 43983
History | View | Annotate | Download (4.21 KB)
1 |
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.Function; |
7 |
import org.gvsig.expressionevaluator.Interpreter; |
8 |
import org.gvsig.expressionevaluator.SymbolTable; |
9 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
10 |
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
11 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
12 |
import org.gvsig.fmap.dal.feature.Feature; |
13 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
14 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
15 |
import org.gvsig.fmap.dal.feature.FeatureType; |
16 |
|
17 |
/**
|
18 |
*
|
19 |
* @author jjdelcerro
|
20 |
*/
|
21 |
public class DefaultFeatureSymbolTable extends AbstractSymbolTable implements FeatureSymbolTable { |
22 |
|
23 |
private class FeatureFunction extends AbstractFunction { |
24 |
|
25 |
public FeatureFunction() {
|
26 |
super(
|
27 |
"Data access",
|
28 |
"feature",
|
29 |
Range.is(0),
|
30 |
"Access to the current feature object when used in a filter.\n"
|
31 |
+ "Return null if used outer a filter.",
|
32 |
"feature()",
|
33 |
null,
|
34 |
"Feature"
|
35 |
); |
36 |
} |
37 |
|
38 |
@Override
|
39 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
40 |
return feature;
|
41 |
} |
42 |
|
43 |
} |
44 |
|
45 |
public class FeatureStoreFunction extends AbstractFunction { |
46 |
|
47 |
public FeatureStoreFunction() {
|
48 |
super(
|
49 |
"Data access",
|
50 |
"store",
|
51 |
Range.is(0),
|
52 |
"Access to the current store object when used in a filter.\n"
|
53 |
+ "Return null if used outer a filter.",
|
54 |
"store()",
|
55 |
null,
|
56 |
"FeatureStore"
|
57 |
); |
58 |
} |
59 |
|
60 |
@Override
|
61 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
62 |
return feature.getStore();
|
63 |
} |
64 |
|
65 |
} |
66 |
|
67 |
public class IsSelectedFunction extends AbstractFunction { |
68 |
|
69 |
public IsSelectedFunction() {
|
70 |
super(
|
71 |
"Data access",
|
72 |
"isSelected",
|
73 |
Range.is(0),
|
74 |
"Return if the current feature is selected in the store when used in a filter.\n"
|
75 |
+ "Return false if used outer a filter.",
|
76 |
"isSelected()",
|
77 |
null,
|
78 |
"Boolean"
|
79 |
); |
80 |
} |
81 |
|
82 |
@Override
|
83 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
84 |
FeatureStore store = feature.getStore(); |
85 |
FeatureSelection selection = store.getFeatureSelection(); |
86 |
return selection.isSelected(feature);
|
87 |
} |
88 |
|
89 |
} |
90 |
|
91 |
private Feature feature;
|
92 |
private FeatureType type;
|
93 |
|
94 |
public DefaultFeatureSymbolTable() {
|
95 |
super("DAL.FeatureSymbolTable"); |
96 |
|
97 |
this.addFunction(new FeatureFunction()); |
98 |
this.addFunction(new FeatureStoreFunction()); |
99 |
this.addFunction(new IsSelectedFunction()); |
100 |
} |
101 |
|
102 |
public final void addFunction(Function function) { |
103 |
if (function == null) { |
104 |
throw new IllegalArgumentException("function can't be null"); |
105 |
} |
106 |
this.getFunctions().put(function.name().toUpperCase(), function);
|
107 |
} |
108 |
|
109 |
@Override
|
110 |
public FeatureSymbolTable clone() throws CloneNotSupportedException { |
111 |
DefaultFeatureSymbolTable other = (DefaultFeatureSymbolTable) super.clone();
|
112 |
return other;
|
113 |
} |
114 |
|
115 |
@Override
|
116 |
public boolean exists(String name) { |
117 |
if (type.get(name) != null) { |
118 |
return true; |
119 |
} |
120 |
return false; |
121 |
} |
122 |
|
123 |
@Override
|
124 |
public Object value(String name) { |
125 |
return this.feature.get(name); |
126 |
} |
127 |
|
128 |
@Override
|
129 |
public void setFeature(Feature feature) { |
130 |
this.feature = feature;
|
131 |
this.type = feature.getType();
|
132 |
} |
133 |
|
134 |
public static void selfRegister() { |
135 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
136 |
manager.registerSymbolTable(new DefaultFeatureSymbolTable());
|
137 |
} |
138 |
} |