Revision 44376 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

View differences:

DefaultFeatureSymbolTable.java
3 3
import java.util.Arrays;
4 4
import java.util.List;
5 5
import org.apache.commons.lang3.Range;
6
import org.apache.commons.lang3.StringUtils;
6 7
import org.gvsig.expressionevaluator.ExpressionBuilder;
7 8
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
8 9
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager;
......
24 25
import org.gvsig.fmap.dal.feature.FeatureStore;
25 26
import org.gvsig.fmap.dal.feature.FeatureType;
26 27
import org.gvsig.fmap.dal.feature.ForeingKey;
27
import static org.gvsig.fmap.dal.impl.expressionevaluator.DALSymbolTable.FUNCTION_FEATURES;
28 28
import org.gvsig.fmap.dal.impl.expressionevaluator.DALSymbolTable.FeaturesFunction;
29
import org.gvsig.tools.dynobject.DynObjectAdapter;
30
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
29 31
import org.gvsig.tools.script.Script;
30 32
import org.gvsig.tools.util.UnmodifiableBasicList;
31 33
import org.gvsig.tools.util.UnmodifiableBasicListAdapter;
......
37 39
    @SuppressWarnings("UseSpecificCatch")
38 40
public class DefaultFeatureSymbolTable extends AbstractSymbolTable implements FeatureSymbolTable {
39 41

  
42
//    public static final String FUNCTION_FEATURES = "FEATURES";
43
//
44
//    public class FeaturesFunction extends AbstractFunction {
45
//
46
//        public FeaturesFunction() {
47
//            super(
48
//                    "Data access",
49
//                    FUNCTION_FEATURES,
50
//                    Range.between(1, 3),
51
//                    "Return a list of the features selecteds with filter in the store.",
52
//                    FUNCTION_FEATURES + "({{store_name}}, filter, order)",
53
//                    new String[]{
54
//                        "store - data store name to be used",
55
//                        "where - Optional. String value with a filter expression",
56
//                        "order - Optional. String value with the order. must be a string with the names of separate fields with commas"
57
//                    },
58
//                    "LIST"
59
//            );
60
//        }
61
//
62
//        @Override
63
//        public Object call(Interpreter interpreter, Object[] args) throws Exception {
64
//            String storeName = getStr(args, 0);
65
//            String where = null;
66
//            String order = null;
67
//            switch (args.length) {
68
//                case 2:
69
//                    where = getStr(args, 1);
70
//                    break;
71
//                case 3:
72
//                    where = getStr(args, 1);
73
//                    order = getStr(args, 2);
74
//                    break;
75
//            }
76
//            try {
77
//                DataStore store = getStore(storeName);
78
//                if (store == null || !(store instanceof FeatureStore)) {
79
//                    throw new ExpressionRuntimeException("Cant locate the store '" + storeName + "' in function '" + FUNCTION_FEATURES + "'.");
80
//                }
81
//                if (!(store instanceof FeatureStore)) {
82
//                    throw new ExpressionRuntimeException("The store'" + storeName + "' is not valid for function '" + FUNCTION_FEATURES + "', a FeatureStore is required.");
83
//                }
84
//                FeatureStore featureStore = (FeatureStore) store;
85
//                List<Feature> features;
86
//                if (where == null && order == null) {
87
//                    features = featureStore.getFeatures();
88
//                } else {
89
//                    FeatureQuery query = featureStore.createFeatureQuery();
90
//                    if (where != null) {
91
//                        query.addFilter(where);
92
//                    }
93
//                    if (order != null) {
94
//                        query.getOrder().add(order);
95
//                    }
96
//                    query.retrievesAllAttributes();
97
//                    features = featureStore.getFeatures(query);
98
//                }
99
//                return features;
100
//            } catch (ExpressionRuntimeException ex) {
101
//                throw ex;
102
//            } catch (Exception ex) {
103
//                throw new ExpressionRuntimeException("Problems calling '" + FUNCTION_FEATURES + "' function", ex);
104
//            }
105
//        }
106
//
107
//        protected DataStore getStore(String storeName) {
108
//            DataStore store = feature.getStore();
109
////            DataManager dataManager = DALLocator.getDataManager();
110
////            DataStore store = dataManager.getStoresRepository().getStore(storeName);
111
//            return store;
112
//        }
113
//    }
114

  
40 115
    public class ForeingValueFunction extends AbstractFunction {
41 116

  
42 117
        public ForeingValueFunction() {
......
66 141
                fieldNames = (UnmodifiableBasicList<String>) fields_o;
67 142
            } else {
68 143
                throw new ExpressionRuntimeException(
69
                    "Problems calling '" + FUNCTION_FEATURES + 
144
                    "Problems calling '" + FUNCTION_FOREING_VALUE + 
70 145
                    "' function, type of parameter '"+fields_o.getClass().getSimpleName()+
71 146
                    "' not supported, use string or list.");
72 147
            }
148
            
73 149
            Feature currentFeature = feature;
74 150
            try {
75 151
                String fieldName;
76 152
                Object value;
153
                
154
                value = feature.getExtraValue(StringUtils.join(fieldNames, "."));
155
                if( value != null ) {
156
                    return value;
157
                }
77 158
                for (int i = 0; i < fieldNames.size()-1; i++) {
78 159
                    fieldName = fieldNames.get(i);
79 160
                    value = currentFeature.get(fieldName);
......
93 174
            } catch (ExpressionRuntimeException ex) {
94 175
                throw ex;
95 176
            } catch (Exception ex) {
96
                throw new ExpressionRuntimeException("Problems calling '" + FUNCTION_FEATURES + "' function", ex);
177
                throw new ExpressionRuntimeException("Problems calling '" + FUNCTION_FOREING_VALUE + "' function", ex);
97 178
            }
98 179
        }
99 180
        
......
111 192
            DataStore store = null;
112 193
            if (feature != null) {
113 194
                store = feature.getStore();
114
                store = store.getChildren().get(storeName);
195
                store = store.getStoresRepository().getStore(storeName);
115 196
            }
116 197
            if (store == null) {
117 198
                StoresRepository repository = dataManager.getStoresRepository();
......
199 280

  
200 281
    private Feature feature;
201 282
    private FeatureType type;
283
    private String storeName;
202 284

  
203 285
    @SuppressWarnings("OverridableMethodCallInConstructor")
204 286
    public DefaultFeatureSymbolTable() {
205 287
        super(DataManager.DAL_SYMBOL_TABLE_FEATURE);
206 288

  
289

  
290
//        this.addFunction(new FeaturesFunction());
207 291
        this.addFunction(new FeatureFunction());
208 292
        this.addFunction(new FeatureStoreFunction());
209 293
        this.addFunction(new IsSelectedFunction());
......
243 327
        if (feature == null) {
244 328
            return null;
245 329
        }
330
        if( StringUtils.equalsIgnoreCase(name, this.storeName) ) {
331
            return new DynObjectAdapter() {
332
                @Override
333
                public Object getDynValue(String string) throws DynFieldNotFoundException {
334
                    return feature.get(string);
335
                }
336
            };
337
        }
246 338
        return this.feature.get(name);
247 339
    }
248 340

  
......
264 356
    @Override
265 357
    public void setFeature(Feature feature) {
266 358
        this.feature = feature;
267
        this.type = feature.getType();
359
        if( this.type == null ) {
360
            this.type = feature.getType();
361
            FeatureStore store = feature.getStore();
362
            if( store!=null ) {
363
                this.storeName = store.getName();
364
            }
365
        }
268 366
    }
269 367

  
270 368
    @Override

Also available in: Unified diff