Revision 47597 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultFeatureRuleExpression.java
DefaultFeatureRuleExpression.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator.impl; |
2 | 2 |
|
3 | 3 |
import javax.json.JsonObject; |
4 |
import org.gvsig.expressionevaluator.Code; |
|
4 | 5 |
import org.gvsig.expressionevaluator.Expression; |
6 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
7 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
5 | 8 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
6 |
import org.gvsig.expressionevaluator.SymbolTable; |
|
9 |
import org.gvsig.expressionevaluator.Interpreter; |
|
10 |
import org.gvsig.expressionevaluator.Optimizer; |
|
7 | 11 |
import org.gvsig.expressionevaluator.impl.symboltable.FeatureSymbolTableImpl; |
8 | 12 |
import org.gvsig.fmap.dal.exception.DataException; |
9 | 13 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
... | ... | |
33 | 37 |
|
34 | 38 |
private Expression expression; |
35 | 39 |
private FeatureSymbolTable featureSymbolTable; |
36 |
private SymbolTable symbolTable; |
|
40 |
private Interpreter interpreter; |
|
41 |
private ExpressionEvaluatorManager manager; |
|
37 | 42 |
|
38 | 43 |
public DefaultFeatureRuleExpression() { |
39 | 44 |
super(null, null, false, false); |
... | ... | |
43 | 48 |
boolean checkAtFinishEdition, Expression expression) { |
44 | 49 |
super(name, description, checkAtUpdate, checkAtFinishEdition); |
45 | 50 |
this.expression = expression; |
46 |
this.featureSymbolTable = new FeatureSymbolTableImpl(); |
|
47 |
this.symbolTable = this.featureSymbolTable.createParent(); |
|
48 | 51 |
} |
49 | 52 |
|
50 | 53 |
@Override |
... | ... | |
59 | 62 |
|
60 | 63 |
@Override |
61 | 64 |
public void validate(EditableFeature feature, FeatureStore featureStore) throws DataException { |
62 |
this.featureSymbolTable.setFeature(feature); |
|
63 |
Object value = this.expression.execute(this.symbolTable); |
|
65 |
Object value = this.execute(feature); |
|
64 | 66 |
boolean ok = false; |
65 | 67 |
if (value != null) { |
66 | 68 |
if (value instanceof Boolean) { |
... | ... | |
75 | 77 |
throw new ValidateFeaturesException(featureStore.getName(), null); |
76 | 78 |
} |
77 | 79 |
|
80 |
public Object execute(EditableFeature feature) { |
|
81 |
if (this.interpreter == null) { |
|
82 |
this.manager = ExpressionEvaluatorLocator.getExpressionEvaluatorManager(); |
|
83 |
this.interpreter = this.manager.createInterpreter(); |
|
84 |
this.featureSymbolTable = new FeatureSymbolTableImpl(); |
|
85 |
this.featureSymbolTable.addSymbolTable(this.manager.createSymbolTable()); |
|
86 |
this.interpreter.setSymbolTable(this.featureSymbolTable); |
|
87 |
Optimizer optimizer = new DefaultOptimizer(this.manager, featureSymbolTable); |
|
88 |
Code code = optimizer.optimize(this.expression.getCode()); |
|
89 |
this.interpreter.link(code); |
|
90 |
} |
|
91 |
this.featureSymbolTable.setFeature(feature); |
|
92 |
Code code_exp = this.expression.getCode(); |
|
93 |
if( this.manager.hasHostExpressions(code_exp) ) { |
|
94 |
code_exp = this.manager.resolveHostExpressions(code_exp, interpreter); |
|
95 |
} |
|
96 |
Object x = this.interpreter.run(code_exp); |
|
97 |
return x; |
|
98 |
} |
|
99 |
|
|
100 |
|
|
78 | 101 |
public static void selfRegister() { |
79 | 102 |
Json.registerSerializer(FeatureRuleExpression.class); |
80 | 103 |
registerPersistenceDefinition(); |
... | ... | |
114 | 137 |
this.checkwhen.setBits(CHECK_WHEN_INSERT_OR_UPDATE_FEATURE); |
115 | 138 |
} |
116 | 139 |
this.expression = (Expression) state.get("expression"); |
117 |
this.featureSymbolTable = new FeatureSymbolTableImpl(); |
|
118 |
this.symbolTable = this.featureSymbolTable.createParent(); |
|
119 | 140 |
} |
120 | 141 |
|
121 | 142 |
@Override |
... | ... | |
187 | 208 |
this.checkwhen.setBits(CHECK_WHEN_INSERT_OR_UPDATE_FEATURE); |
188 | 209 |
} |
189 | 210 |
this.expression = ExpressionUtils.createExpression(json.getString("expression", null)); |
190 |
this.featureSymbolTable = new FeatureSymbolTableImpl(); |
|
191 |
this.symbolTable = this.featureSymbolTable.createParent(); |
|
192 | 211 |
} |
193 | 212 |
|
194 | 213 |
@Override |
Also available in: Unified diff