Revision 46086 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/DefaultFeatureExpressionEvaluator.java

View differences:

DefaultFeatureExpressionEvaluator.java
35 35
import org.slf4j.LoggerFactory;
36 36

  
37 37
@SuppressWarnings("UseSpecificCatch")
38
public class DefaultFeatureExpressionEvaluator 
39
        extends AbstractEvaluator 
40
        implements ExpressionEvaluator, Cloneable 
41
    {
38
public class DefaultFeatureExpressionEvaluator
39
        extends AbstractEvaluator
40
        implements ExpressionEvaluator, Cloneable {
42 41

  
43 42
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultFeatureExpressionEvaluator.class);
44
	private String storeName;
43
    private String storeName;
45 44

  
46 45
    private static class DescriptionAdapter implements Description {
47 46

  
......
91 90
    private Expression expression;
92 91
    private Description[] availableOperators;
93 92
    private Description[] availableFunctions;
94
    
93

  
95 94
    public DefaultFeatureExpressionEvaluator() {
96 95
        ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
97 96
        this.symbolTable = manager.createSymbolTable();
......
102 101
    }
103 102

  
104 103
    public DefaultFeatureExpressionEvaluator(String source) {
105
		this(null, source);
106
	}
107
	
104
        this(null, source);
105
    }
106

  
108 107
    public DefaultFeatureExpressionEvaluator(String storeName, String source) {
109 108
        this();
110 109
        ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
111 110
        this.expression = manager.createExpression();
112 111
        this.expression.setPhrase(source);
113
		this.storeName = storeName;
112
        this.storeName = storeName;
114 113
    }
115 114

  
116 115
    public DefaultFeatureExpressionEvaluator(Expression expression) {
117
		this(null, expression);
116
        this(null, expression);
118 117
    }
119
	
118

  
120 119
    public DefaultFeatureExpressionEvaluator(String storeName, Expression expression) {
121 120
        this();
122 121
        this.expression = expression;
123
		this.storeName = storeName;
124
		
125
	}
122
        this.storeName = storeName;
126 123

  
124
    }
125

  
127 126
    @Override
128 127
    public String getName() {
129 128
        return "Genereric expression";
......
148 147
    public SymbolTable toSymbolTable() {
149 148
        return this.symbolTable;
150 149
    }
151
    
150

  
152 151
    @Override
153 152
    public Object evaluate(EvaluatorData data) throws EvaluatorException {
154 153
        this.featureSymbolTable.setFeature((Feature) data);
......
161 160
        final Set<String> names = new HashSet<>();
162 161
        try {
163 162
            this.expression.getCode().accept((Object code) -> {
164
              if (code instanceof Code.Identifier) {
165
                Code.Identifier identifier = (Code.Identifier) code;
166
				if(!StringUtils.equalsIgnoreCase(storeName, identifier.name())) {
167
					names.add(identifier.name());
168
				}
169
              } else if (code instanceof Code.Callable) {
170
				  Callable callable = (Callable) code;
171
				  if (callable.name().equals(ExpressionBuilder.FUNCTION_GETATTR)) {
172
					  Code p0 = callable.parameters().get(0);
173
					  if (!(p0 instanceof Code.Identifier)) {
174
						  return;
175
					  }
176
					  if (!StringUtils.equalsIgnoreCase(storeName, ((Code.Identifier) p0).name())) {
177
						  return;
178
					  }
179
					  Code p1 = callable.parameters().get(1);
180
					  if (!(p1 instanceof Code.Constant)) {
181
						  return;
182
					  }
183
					  String s = Objects.toString(((Code.Constant)p1).value(), null);
184
					  if (s != null) {
185
						  names.add(s);
186
					  }
187
				  }
188
			  } 
163
                if (code instanceof Code.Identifier) {
164
                    Code.Identifier identifier = (Code.Identifier) code;
165
                    if (!StringUtils.equalsIgnoreCase(storeName, identifier.name())) {
166
                        names.add(identifier.name());
167
                    }
168
                } else if (code instanceof Code.Callable) {
169
                    Callable callable = (Callable) code;
170
                    if (callable.name().equals(ExpressionBuilder.FUNCTION_GETATTR)) {
171
                        Code p0 = callable.parameters().get(0);
172
                        if (!(p0 instanceof Code.Identifier)) {
173
                            return;
174
                        }
175
                        if (!StringUtils.equalsIgnoreCase(storeName, ((Code.Identifier) p0).name())) {
176
                            return;
177
                        }
178
                        Code p1 = callable.parameters().get(1);
179
                        if (!(p1 instanceof Code.Constant)) {
180
                            return;
181
                        }
182
                        String s = Objects.toString(((Code.Constant) p1).value(), null);
183
                        if (s != null) {
184
                            names.add(s);
185
                        }
186
                    }
187
                }
189 188
            });
190 189
            EvaluatorFieldsInfo info = new EvaluatorFieldsInfo();
191 190
            for (String name : names) {
......
240 239
        }
241 240
        return other;
242 241
    }
243
    
242

  
244 243
    @Override
245 244
    public void saveToState(PersistentState ps) throws PersistenceException {
246 245
        ps.set("expression", expression);
......
250 249
    public void loadFromState(PersistentState state) throws PersistenceException {
251 250
        this.expression = (Expression) state.get("expression");
252 251
    }
253
    
252

  
254 253
    public static void registerPersistence() {
255 254
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
256 255
        if (manager.getDefinition("DefaultFeatureExpressionEvaluator") == null) {
......
262 261

  
263 262
    @Override
264 263
    public void addSymbolTable(SymbolTable symbolTable) {
265
        if( symbolTable!=null ) {
264
        if (symbolTable != null) {
266 265
            this.symbolTable.addSymbolTable(symbolTable);
267 266
        }
268 267
    }

Also available in: Unified diff