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 / expressionevaluator / impl / DefaultFeatureRuleExpression.java @ 44871
History | View | Annotate | Download (2.99 KB)
1 | 44871 | jjdelcerro | package org.gvsig.expressionevaluator.impl; |
---|---|---|---|
2 | |||
3 | import org.gvsig.expressionevaluator.Expression; |
||
4 | import org.gvsig.expressionevaluator.impl.symboltable.FeatureSymbolTableImpl; |
||
5 | import org.gvsig.fmap.dal.exception.DataException; |
||
6 | import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
||
7 | import org.gvsig.fmap.dal.feature.AbstractFeatureRule; |
||
8 | import org.gvsig.fmap.dal.feature.Feature; |
||
9 | import org.gvsig.fmap.dal.feature.FeatureRuleExpression; |
||
10 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
11 | import org.gvsig.fmap.dal.feature.exception.ValidateFeaturesException; |
||
12 | import org.gvsig.tools.dataTypes.DataTypeUtils; |
||
13 | import org.gvsig.tools.persistence.PersistentState; |
||
14 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
15 | |||
16 | /**
|
||
17 | *
|
||
18 | * @author gvSIG team
|
||
19 | */
|
||
20 | public class DefaultFeatureRuleExpression |
||
21 | extends AbstractFeatureRule
|
||
22 | implements FeatureRuleExpression
|
||
23 | { |
||
24 | |||
25 | private Expression expression; |
||
26 | private FeatureSymbolTable symbolTable;
|
||
27 | |||
28 | public DefaultFeatureRuleExpression(String name, String description, boolean checkAtUpdate, |
||
29 | boolean checkAtFinishEdition, Expression expression) { |
||
30 | super(name, description, checkAtUpdate, checkAtFinishEdition);
|
||
31 | this.expression = expression;
|
||
32 | this.symbolTable = new FeatureSymbolTableImpl(); |
||
33 | } |
||
34 | |||
35 | @Override
|
||
36 | public void validate(Feature feature, FeatureStore featureStore) throws DataException { |
||
37 | this.symbolTable.setFeature(feature);
|
||
38 | Object value = this.expression.execute(symbolTable); |
||
39 | boolean ok = false; |
||
40 | if( value!=null ) { |
||
41 | if( value instanceof Boolean ) { |
||
42 | ok = (Boolean)value;
|
||
43 | } else {
|
||
44 | ok = DataTypeUtils.toBoolean(value, false);
|
||
45 | } |
||
46 | } |
||
47 | if( ok ) {
|
||
48 | return;
|
||
49 | } |
||
50 | throw new ValidateFeaturesException(null, featureStore.getName()); |
||
51 | } |
||
52 | |||
53 | public static void selfRegister() { |
||
54 | |||
55 | } |
||
56 | |||
57 | @Override
|
||
58 | public void loadFromState(PersistentState state) throws PersistenceException { |
||
59 | this.name = state.getString("name"); |
||
60 | this.description = state.getString("description"); |
||
61 | this.checkAtFinishEdition = state.getBoolean("checkAtFinishEdition"); |
||
62 | this.checkAtUpdate = state.getBoolean("checkAtUpdate"); |
||
63 | this.expression = (Expression) state.get("expression"); |
||
64 | this.symbolTable = new FeatureSymbolTableImpl(); |
||
65 | } |
||
66 | |||
67 | @Override
|
||
68 | public void saveToState(PersistentState state) throws PersistenceException { |
||
69 | state.set("name", this.name); |
||
70 | state.set("description", this.description); |
||
71 | state.set("checkAtFinishEdition", this.checkAtFinishEdition); |
||
72 | state.set("checkAtUpdate", this.checkAtUpdate); |
||
73 | state.set("expression", this.expression); |
||
74 | } |
||
75 | |||
76 | @Override
|
||
77 | public void setCheckAtUpdate(boolean checkAtUpdate) { |
||
78 | this.checkAtUpdate = checkAtUpdate;
|
||
79 | } |
||
80 | |||
81 | @Override
|
||
82 | public void setCheckAtFinishEditing(boolean checkAtFinishEditing) { |
||
83 | this.checkAtFinishEdition = checkAtFinishEditing;
|
||
84 | } |
||
85 | |||
86 | @Override
|
||
87 | public Expression getExpression() { |
||
88 | return this.expression; |
||
89 | } |
||
90 | |||
91 | @Override
|
||
92 | public void setExpression(Expression expression) { |
||
93 | this.expression = expression;
|
||
94 | } |
||
95 | |||
96 | } |