Revision 44203

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/feature/Feature.java
35 35
import org.gvsig.tools.dynobject.DynObject;
36 36
import org.gvsig.tools.evaluator.Evaluator;
37 37
import org.gvsig.tools.evaluator.EvaluatorData;
38
import org.gvsig.tools.util.GetItemByKey;
38 39

  
39 40

  
40 41
/**
......
71 72
 * </p>
72 73
 *
73 74
 */
74
public interface Feature {
75
public interface Feature extends GetItemByKey<String, Object>{
75 76

  
76 77
	/**
77 78
	 * Returns a unique identifier for this Feature in the associated store.
......
133 134
	 * @return
134 135
	 * 		value of the specified attribute
135 136
	 */
137
        @Override
136 138
	public Object   get(String name);
137 139

  
138 140
	/**
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/DefaultFeatureProvider.java
83 83
    @Override
84 84
    public void set(int i, Object value) {
85 85
        FeatureAttributeDescriptor attribute = featureType.getAttributeDescriptor(i);
86
        if (this.isReadOnly(i)) {
87
            return;
88
        }
86
//        if (this.isReadOnly(i)) {
87
//            return;
88
//        }
89 89
        if (featureType.getDefaultGeometryAttributeIndex() == i) {
90 90
            if (value instanceof Geometry) {
91 91
                defaultGeometry = (Geometry) value;
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/feature/impl/DefaultFeature.java
234 234
            FeatureAttributeDescriptor attribute = (FeatureAttributeDescriptor) iterator
235 235
            .next();
236 236
            if (attribute.isAutomatic() || attribute.isReadOnly()
237
                    || attribute.getEvaluator() != null) {
237
                    || attribute.isComputed() ) {
238 238
                continue;
239 239
            }
240 240
            if (attribute.getDefaultValue() == null && !attribute.allowNull()) {
......
518 518
    private Object get(FeatureAttributeDescriptor featureAttributeDescriptor, Object value){
519 519
        FeatureAttributeEmulator emulator = featureAttributeDescriptor.getFeatureAttributeEmulator();
520 520
        if( emulator != null ) {
521
            value = emulator.get(this);
521
            int index = featureAttributeDescriptor.getIndex();
522
            value = this.data.get(index);
523
            if( value==null ) {
524
                value = emulator.get(this);
525
                this.data.set(index,value);
526
            }
522 527
        } else {
523 528
            FeatureAttributeGetter getter = featureAttributeDescriptor.getFeatureAttributeGetter();
524 529
            if( getter != null ) {
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
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());
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/symboltables/ListOfFeaturesWrapper.java
1
package org.gvsig.app.project.symboltables;
2

  
3
import java.util.Iterator;
4
import java.util.List;
5
import java.util.NoSuchElementException;
6
import org.gvsig.expressionevaluator.Expression;
7
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
8
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager;
9
import org.gvsig.expressionevaluator.MutableSymbolTable;
10
import org.gvsig.expressionevaluator.SymbolTable;
11
import org.gvsig.fmap.dal.DALLocator;
12
import org.gvsig.fmap.dal.DataManager;
13
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable;
14
import org.gvsig.fmap.dal.feature.Feature;
15
import org.gvsig.tools.util.UnmodifiableBasicList;
16
import org.gvsig.tools.util.UnmodifiableBasicListToListAdapter;
17

  
18
/**
19
 *
20
 * @author jjdelcerro
21
 */
22
public class ListOfFeaturesWrapper implements UnmodifiableBasicList<Object> {
23

  
24
    private final List<Feature> features;
25
    private final FeatureSymbolTable featureSymbolTable;
26
    private final MutableSymbolTable symbolTable;
27
    private final Expression expression;
28
    
29
    public ListOfFeaturesWrapper(
30
            List<Feature> features, 
31
            SymbolTable symbolTable, 
32
            String expression
33
        ) {
34
        DataManager dataManager = DALLocator.getDataManager();
35
        ExpressionEvaluatorManager expManager = ExpressionEvaluatorLocator.getManager();
36
        
37
        this.features = features;
38
        this.featureSymbolTable = dataManager.createFeatureSymbolTable();
39
        this.symbolTable = this.featureSymbolTable.createParent();
40
        this.symbolTable.addSymbolTable(symbolTable);
41

  
42
        this.expression = expManager.createExpression();
43
        this.expression.setPhrase(expression);
44
    }
45

  
46
    private Object getValue(Feature feature) {
47
        this.featureSymbolTable.setFeature(feature);
48
        Object value = this.expression.execute(this.symbolTable);
49
        return value;
50
    }
51
    
52
    @Override
53
    public boolean isEmpty() {
54
        return this.features.isEmpty();
55
    }
56

  
57
    @Override
58
    public List<Object> toList() {
59
        List<Object> x = new UnmodifiableBasicListToListAdapter<>(this);
60
        return x;
61
    }
62

  
63
    @Override
64
    public Object get(int position) {
65
        return this.getValue(this.features.get(position));
66
    }
67

  
68
    @Override
69
    public int size() {
70
        return this.features.size();
71
    }
72

  
73
    @Override
74
    public Iterator<Object> iterator() {
75
        return new Itr();
76
    }
77
    
78
    private class Itr implements Iterator<Object> {
79
        int cursor;       // index of next element to return
80

  
81
        Itr() {}
82

  
83
        @Override
84
        public boolean hasNext() {
85
            return cursor != size();
86
        }
87

  
88
        @Override
89
        public Object next() {
90
            int i = cursor;
91
            if (i >= size())
92
                throw new NoSuchElementException();
93
            cursor = i + 1;
94
            return get(i);
95
        }
96

  
97
        @Override
98
        public void remove() {
99
            throw new UnsupportedOperationException("Not supported yet."); 
100
        }
101
    }
102
}
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/programming/GetitemFunction.java
9 9
import org.gvsig.expressionevaluator.spi.AbstractFunction;
10 10
import org.gvsig.tools.util.GetItem;
11 11
import org.gvsig.tools.util.GetItem64;
12
import org.gvsig.tools.util.GetItemByKey;
12 13

  
13 14
public class GetitemFunction extends AbstractFunction {
14 15

  
......
70 71
            long index = getLong(args,1);
71 72
            value = l.get64(index);
72 73
            
74
        } else if( obj instanceof GetItemByKey ) {
75
            GetItemByKey l = (GetItemByKey)obj;
76
            Object key = getObject(args,1);
77
            value = l.get(key);
78
            
73 79
        } else {
74 80
            throw new ExpressionRuntimeException("The "+NAME+" function require a String, List or Map and a received a '"+obj.getClass().getSimpleName()+"'.");
75 81
        }

Also available in: Unified diff