svn-gvsig-desktop / branches / v10 / extensions / extExpressionField / src / com / iver / cit / gvsig / project / documents / table / operators / FieldCopy.java @ 11524
History | View | Annotate | Download (2.13 KB)
1 |
package com.iver.cit.gvsig.project.documents.table.operators; |
---|---|
2 |
|
3 |
import java.util.Date; |
4 |
|
5 |
import org.apache.bsf.BSFException; |
6 |
import org.apache.bsf.BSFManager; |
7 |
|
8 |
|
9 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
10 |
import com.hardcode.gdbms.engine.values.BooleanValue; |
11 |
import com.hardcode.gdbms.engine.values.DateValue; |
12 |
import com.hardcode.gdbms.engine.values.NumericValue; |
13 |
import com.hardcode.gdbms.engine.values.Value; |
14 |
import com.iver.cit.gvsig.ExpresionFieldExtension; |
15 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
16 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
17 |
import com.iver.cit.gvsig.project.documents.table.AbstractOperator; |
18 |
import com.iver.cit.gvsig.project.documents.table.Index; |
19 |
/**
|
20 |
* @author Vicente Caballero Navarro
|
21 |
*/
|
22 |
public class FieldCopy extends AbstractOperator{ |
23 |
private FieldDescription fd;
|
24 |
public FieldCopy() {
|
25 |
} |
26 |
public void setFieldDescription(FieldDescription fd) { |
27 |
this.fd=fd;
|
28 |
} |
29 |
public String addText(String s) { |
30 |
return s.concat(toString());
|
31 |
} |
32 |
|
33 |
public void eval(BSFManager interpreter) throws BSFException { |
34 |
interpreter.declareBean(fd.getFieldAlias(),this,FieldCopy.class);
|
35 |
interpreter.eval(ExpresionFieldExtension.JYTHON,null,-1,-1,"java.lang.Object "+ fd.getFieldAlias()+ "(){return "+fd.getFieldAlias()+".getValue(indexRow,sds);};"); |
36 |
} |
37 |
public Object getValue(Index indexRow,SelectableDataSource sds) { |
38 |
try {
|
39 |
int index=sds.getFieldIndexByName(fd.getFieldName());
|
40 |
Value value=sds.getFieldValue(indexRow.get(),index); |
41 |
if (value instanceof NumericValue) { |
42 |
double dv=((NumericValue)value).doubleValue();
|
43 |
return new Double(dv); |
44 |
}else if (value instanceof DateValue) { |
45 |
Date date=((DateValue)value).getValue();
|
46 |
return date;
|
47 |
}else if (value instanceof BooleanValue){ |
48 |
boolean b=((BooleanValue)value).getValue();
|
49 |
return new Boolean(b); |
50 |
}else {
|
51 |
return value.toString();
|
52 |
} |
53 |
} catch (DriverException e) {
|
54 |
throw new RuntimeException(e.getMessage()); |
55 |
} |
56 |
} |
57 |
public String toString() { |
58 |
return "["+fd.getFieldAlias()+"]"; |
59 |
} |
60 |
public boolean isEnable() { |
61 |
return true; |
62 |
} |
63 |
public String getDescription() { |
64 |
// TODO Auto-generated method stub
|
65 |
return null; |
66 |
} |
67 |
} |