Revision 27739 trunk/extensions/extExpressionField/src/com/iver/cit/gvsig/project/documents/table/operators/FieldCopy.java
FieldCopy.java | ||
---|---|---|
1 | 1 |
package com.iver.cit.gvsig.project.documents.table.operators; |
2 | 2 |
|
3 |
import java.util.Date; |
|
4 |
|
|
5 | 3 |
import org.apache.bsf.BSFException; |
6 | 4 |
import org.apache.bsf.BSFManager; |
5 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
7 | 6 |
|
8 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
9 |
import com.hardcode.gdbms.engine.values.BooleanValue; |
|
10 |
import com.hardcode.gdbms.engine.values.DateValue; |
|
11 |
import com.hardcode.gdbms.engine.values.NumericValue; |
|
12 |
import com.hardcode.gdbms.engine.values.Value; |
|
13 | 7 |
import com.iver.cit.gvsig.ExpressionFieldExtension; |
14 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
|
15 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
|
16 | 8 |
import com.iver.cit.gvsig.project.documents.table.AbstractOperator; |
17 |
import com.iver.cit.gvsig.project.documents.table.Index;
|
|
9 |
import com.iver.cit.gvsig.project.documents.table.gui.FeatureContainer;
|
|
18 | 10 |
/** |
19 | 11 |
* @author Vicente Caballero Navarro |
20 | 12 |
*/ |
21 | 13 |
public class FieldCopy extends AbstractOperator{ |
22 |
private FieldDescription fd;
|
|
14 |
private FeatureAttributeDescriptor fd;
|
|
23 | 15 |
public FieldCopy() { |
24 | 16 |
} |
25 |
public void setFieldDescription(FieldDescription fd) {
|
|
17 |
public void setFieldDescription(FeatureAttributeDescriptor fd) {
|
|
26 | 18 |
this.fd=fd; |
27 | 19 |
} |
28 | 20 |
public String addText(String s) { |
... | ... | |
30 | 22 |
} |
31 | 23 |
|
32 | 24 |
public void eval(BSFManager interpreter) throws BSFException { |
33 |
interpreter.declareBean(fd.getFieldAlias(),this,FieldCopy.class);
|
|
34 |
interpreter.eval(ExpressionFieldExtension.JYTHON,null,-1,-1,"java.lang.Object "+ fd.getFieldAlias()+ "(){return "+fd.getFieldAlias()+".getValue(indexRow,sds);};");
|
|
25 |
interpreter.declareBean(fd.getName(),this,FieldCopy.class);
|
|
26 |
interpreter.eval(ExpressionFieldExtension.JYTHON,null,-1,-1,"java.lang.Object "+ fd.getName()+ "(){return "+fd.getName()+".getValue(featureContainer);};");
|
|
35 | 27 |
} |
36 |
public Object getValue(Index indexRow,SelectableDataSource sds) { |
|
37 |
try { |
|
38 |
int index=sds.getFieldIndexByName(fd.getFieldName()); |
|
39 |
Value value=sds.getFieldValue(indexRow.get(),index); |
|
40 |
if (value instanceof NumericValue) { |
|
41 |
double dv=((NumericValue)value).doubleValue(); |
|
42 |
return new Double(dv); |
|
43 |
}else if (value instanceof DateValue) { |
|
44 |
Date date=((DateValue)value).getValue(); |
|
45 |
return date; |
|
46 |
}else if (value instanceof BooleanValue){ |
|
47 |
boolean b=((BooleanValue)value).getValue(); |
|
48 |
return new Boolean(b); |
|
49 |
}else { |
|
50 |
return value.toString(); |
|
51 |
} |
|
52 |
} catch (ReadDriverException e) { |
|
53 |
throw new RuntimeException(e.getMessage()); |
|
54 |
} |
|
28 |
public Object getValue(FeatureContainer featureContainer){ |
|
29 |
return featureContainer.getFeature().get(fd.getName()); |
|
55 | 30 |
} |
31 |
// public Object getValue(Index indexRow,FeatureStore sds) { |
|
32 |
// try { |
|
33 |
// int index=sds.getFieldIndexByName(fd.getName()); |
|
34 |
// Value value=sds.getFieldValue(indexRow.get(),index); |
|
35 |
// if (value instanceof NumericValue) { |
|
36 |
// double dv=((NumericValue)value).doubleValue(); |
|
37 |
// return new Double(dv); |
|
38 |
// }else if (value instanceof DateValue) { |
|
39 |
// Date date=((DateValue)value).getValue(); |
|
40 |
// return date; |
|
41 |
// }else if (value instanceof BooleanValue){ |
|
42 |
// boolean b=((BooleanValue)value).getValue(); |
|
43 |
// return new Boolean(b); |
|
44 |
// }else { |
|
45 |
// return value.toString(); |
|
46 |
// } |
|
47 |
// } catch (ReadDriverException e) { |
|
48 |
// throw new RuntimeException(e.getMessage()); |
|
49 |
// } |
|
50 |
// } |
|
56 | 51 |
public String toString() { |
57 |
return "["+fd.getFieldAlias()+"]";
|
|
52 |
return "["+fd.getName()+"]";
|
|
58 | 53 |
} |
59 | 54 |
public boolean isEnable() { |
60 | 55 |
return true; |
Also available in: Unified diff