Statistics
| Revision:

root / org.gvsig.expressionfield / trunk / org.gvsig.expressionfield / src / main / java / org / gvsig / expressionfield / project / documents / table / operators / AbstractField.java @ 24

History | View | Annotate | Download (2.75 KB)

1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
26
package org.gvsig.expressionfield.project.documents.table.operators;
27

    
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.expressionfield.ExpressionFieldExtension;
31
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
32
import org.gvsig.fmap.dal.feature.Feature;
33

    
34

    
35
public abstract class AbstractField extends AbstractOperator{
36
        private boolean isEval=false;
37
        public Object getValue(Feature feature, String nameField){
38
                if (feature != null)
39
                        return feature.get(nameField);
40
                return null;
41
        }
42
//        public Object getValue(String nameField,Index indexRow,SelectableDataSource sds) {
43
//                try {
44
//                        int index=sds.getFieldIndexByName(nameField);
45
//                        Value value=sds.getFieldValue(indexRow.get(),index);
46
//                        if (value instanceof NumericValue) {
47
//                                double dv=((NumericValue)value).doubleValue();
48
//                                return new Double(dv);
49
//                        }else if (value instanceof DateValue) {
50
//                                Date date=((DateValue)value).getValue();
51
//                                return date;
52
//                        }else if (value instanceof BooleanValue){
53
//                                boolean b=((BooleanValue)value).getValue();
54
//                                return new Boolean(b);
55
//                        }else {
56
//                                return value.toString();
57
//                        }
58
//                } catch (ReadDriverException e) {
59
//                        throw new RuntimeException(e.getMessage());
60
//                }
61
//        }
62
        public void eval(BSFManager interpreter) throws BSFException {
63
                if (!isEval){
64
                interpreter.declareBean("jfield",this,Field.class);
65
                interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def field(nameField):\n" +
66
                                "  return jfield.getValue(featureContainer.getFeature(), nameField)");
67
                isEval=true;
68
                }
69
        }
70
}