Revision 47597

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/expressionevaluator/FeatureSymbolTable.java
8 8
 *
9 9
 * @author jjdelcerro
10 10
 */
11
public interface FeatureSymbolTable extends SymbolTable {
11
public interface FeatureSymbolTable extends MutableSymbolTable {
12 12
    public static final String SYMBOL_CURRENT_TABLE = "$TABLE";
13 13
    public static final String SYMBOL_CURRENT_ROW = "$ROW";
14 14
  
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
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
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/symboltable/FeatureSymbolTableImpl.java
36 36
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable;
37 37
import static org.gvsig.fmap.dal.DataManager.FUNCTION_CURRENT_ROW;
38 38
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable;
39
import org.gvsig.fmap.dal.feature.EditableFeature;
39 40
import org.gvsig.fmap.dal.feature.Feature;
40 41
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
41 42
import org.gvsig.fmap.dal.feature.FeatureStore;
......
147 148
      return null;
148 149
  }
149 150

  
151
  public void setVar(String name, Object value) {
152
      if (feature instanceof EditableFeature ) {
153
          if( this.feature.hasValue(name) ) {
154
              ((EditableFeature)this.feature).set(name, value);
155
              return;
156
          }
157
      }
158
      super.setVar(name, value);
159
  }
160
  
150 161
  @Override
151 162
  public boolean isSQLCompatible(String name) {
152 163
    if (this.type == null) {

Also available in: Unified diff