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 @ 43987
History | View | Annotate | Download (4.77 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.spi.AbstractFunction; |
9 |
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
10 |
import org.gvsig.fmap.dal.DataManager; |
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 |
import org.gvsig.tools.script.Script; |
17 |
import org.gvsig.tools.util.UnmodifiableBasicList; |
18 |
|
19 |
/**
|
20 |
*
|
21 |
* @author jjdelcerro
|
22 |
*/
|
23 |
public class DefaultFeatureSymbolTable extends AbstractSymbolTable implements FeatureSymbolTable { |
24 |
|
25 |
private class FeatureFunction extends AbstractFunction { |
26 |
|
27 |
public FeatureFunction() {
|
28 |
super(
|
29 |
"Data access",
|
30 |
"feature",
|
31 |
Range.is(0),
|
32 |
"Access to the current feature object when used in a filter.\n"
|
33 |
+ "Return null if used outer a filter.",
|
34 |
"feature()",
|
35 |
null,
|
36 |
"Feature"
|
37 |
); |
38 |
} |
39 |
|
40 |
@Override
|
41 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
42 |
return feature;
|
43 |
} |
44 |
|
45 |
} |
46 |
|
47 |
public class FeatureStoreFunction extends AbstractFunction { |
48 |
|
49 |
public FeatureStoreFunction() {
|
50 |
super(
|
51 |
"Data access",
|
52 |
"store",
|
53 |
Range.is(0),
|
54 |
"Access to the current store object when used in a filter.\n"
|
55 |
+ "Return null if used outer a filter.",
|
56 |
"store()",
|
57 |
null,
|
58 |
"FeatureStore"
|
59 |
); |
60 |
} |
61 |
|
62 |
@Override
|
63 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
64 |
if( feature==null ) { |
65 |
return null; |
66 |
} |
67 |
return feature.getStore();
|
68 |
} |
69 |
|
70 |
} |
71 |
|
72 |
public class IsSelectedFunction extends AbstractFunction { |
73 |
|
74 |
public IsSelectedFunction() {
|
75 |
super(
|
76 |
"Data access",
|
77 |
"isSelected",
|
78 |
Range.is(0),
|
79 |
"Return if the current feature is selected in the store when used in a filter.\n"
|
80 |
+ "Return false if used outer a filter.",
|
81 |
"isSelected()",
|
82 |
null,
|
83 |
"Boolean"
|
84 |
); |
85 |
} |
86 |
|
87 |
@Override
|
88 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
89 |
if( feature==null ) { |
90 |
return false; |
91 |
} |
92 |
FeatureStore store = feature.getStore(); |
93 |
FeatureSelection selection = store.getFeatureSelection(); |
94 |
return selection.isSelected(feature);
|
95 |
} |
96 |
|
97 |
} |
98 |
|
99 |
private Feature feature;
|
100 |
private FeatureType type;
|
101 |
|
102 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
103 |
public DefaultFeatureSymbolTable() {
|
104 |
super(DataManager.FEATURE_SYMBOL_TABLE);
|
105 |
|
106 |
this.addFunction(new FeatureFunction()); |
107 |
this.addFunction(new FeatureStoreFunction()); |
108 |
this.addFunction(new IsSelectedFunction()); |
109 |
} |
110 |
|
111 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
112 |
public DefaultFeatureSymbolTable(Script userScript, UnmodifiableBasicList<Script> scripts) {
|
113 |
this();
|
114 |
if (userScript != null) { |
115 |
this.getScripts().add(userScript);
|
116 |
} |
117 |
if (scripts != null && !scripts.isEmpty()) { |
118 |
for (Script script : scripts) {
|
119 |
this.getScripts().add(script);
|
120 |
} |
121 |
} |
122 |
} |
123 |
|
124 |
@Override
|
125 |
public FeatureSymbolTable clone() throws CloneNotSupportedException { |
126 |
DefaultFeatureSymbolTable other = (DefaultFeatureSymbolTable) super.clone();
|
127 |
return other;
|
128 |
} |
129 |
|
130 |
@Override
|
131 |
public boolean exists(String name) { |
132 |
if (type!=null && type.get(name) != null) { |
133 |
return true; |
134 |
} |
135 |
return false; |
136 |
} |
137 |
|
138 |
@Override
|
139 |
public Object value(String name) { |
140 |
if( feature==null ) { |
141 |
return null; |
142 |
} |
143 |
return this.feature.get(name); |
144 |
} |
145 |
|
146 |
@Override
|
147 |
public void setFeature(Feature feature) { |
148 |
this.feature = feature;
|
149 |
this.type = feature.getType();
|
150 |
} |
151 |
|
152 |
public static void selfRegister() { |
153 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
154 |
manager.registerSymbolTable(new DefaultFeatureSymbolTable(), false); |
155 |
} |
156 |
} |