Revision 44203 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/symboltables/ProjectSymbolTable.java

View differences:

ProjectSymbolTable.java
4 4
import java.io.FileInputStream;
5 5
import java.util.HashMap;
6 6
import java.util.Iterator;
7
import java.util.List;
7 8
import java.util.Map;
8 9
import java.util.Properties;
9 10
import org.apache.commons.io.IOUtils;
......
41 42
import org.gvsig.temporarystorage.TemporaryStorageGroup;
42 43
import org.gvsig.temporarystorage.TemporaryStorageLocator;
43 44
import org.gvsig.temporarystorage.TemporaryStorageManager;
45
import org.gvsig.tools.util.UnmodifiableBasicList;
44 46

  
45 47
/**
46 48
 *
......
54 56
    public static final String STORE_NAME = "STORE";
55 57
    public static final String FETCH_FIRST_NAME = "FETCH_FIRST";
56 58
    public static final String FETCH_FIRST_SELECTED_NAME = "FETCH_FIRST_SELECTED";
59
    public static final String FETCH_NAME = "FETCH";
57 60
        
58 61
    static final String NAME = "Project";
59 62
    
......
200 203
        
201 204
    }
202 205
    
206
    private class FetchFunction extends AbstractFunction {
207

  
208
        public FetchFunction() {
209
            super(
210
                    "Project",
211
                    FETCH_NAME,
212
                    Range.between(2, 4),
213
                    "Access to the features of a table and retuen a list with the values.",
214
                    FETCH_NAME+"({{value}}, store, where, order)",
215
                    new String[]{
216
                        "value - value to retrieve from the store, usually an expression in the columns of this are involved.",
217
                        "store - data store from which values will be collected",
218
                        "where - Optional. String value with a filter expression",
219
                        "order - Optional. String value with the order. must be a string with the names of separate fields with commas"
220
                    },
221
                    "Object"
222
            );
223
        }
224

  
225
        @Override
226
        public Object call(Interpreter interpreter, Object[] args) throws Exception {
227
            Object value;
228
            String where = null;
229
            String order = null;
230
            String expression_s = getStr(args, 0);
231
            FeatureStore store = (FeatureStore) getObject(args, 1);
232
            switch (args.length) {
233
                case 3:
234
                    where = getStr(args, 2);
235
                    break;
236
                case 4:
237
                    where = getStr(args, 2);
238
                    order = getStr(args, 3);
239
                    break;
240
            }
241
            try {
242
                List<Feature> features;
243
                if (where == null && order == null) {
244
                    features = store.getFeatures();
245
                } else {
246
                    FeatureQuery query = store.createFeatureQuery();
247
                    if (where != null) {
248
                        query.addFilter(where);
249
                    }
250
                    if (order != null) {
251
                        query.getOrder().add(order);
252
                    }
253
                    query.retrievesAllAttributes();
254
                    features = store.getFeatures(query);
255
                }
256
                UnmodifiableBasicList<Object> list = new ListOfFeaturesWrapper(
257
                        features,
258
                        interpreter.getSymbolTable(), 
259
                        expression_s
260
                );
261
                return list;
262
            } catch (Exception ex) {
263
                throw new ExpressionRuntimeException("Problems calling '"+FETCH_NAME+"' function", ex);
264
            }
265
        }
266
    }
267

  
203 268
    private class FetchFirstFunction extends AbstractFunction {
204 269

  
205 270
        public FetchFirstFunction() {
......
537 602
        super(NAME);
538 603
        this.addFunction(new CurrentProjectFunction());
539 604
        this.addFunction(new StoreFunction());
605
        this.addFunction(new FetchFunction());
540 606
        this.addFunction(new FetchFirstFunction());
541 607
        this.addFunction(new FetchFirstSelectedFunction());
542 608
        this.addFunction(new ViewFunction());

Also available in: Unified diff