svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / project / documents / table / operators / Field.java @ 10254
History | View | Annotate | Download (2.06 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 |
import bsh.EvalError; |
9 |
|
10 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
11 |
import com.hardcode.gdbms.engine.values.BooleanValue; |
12 |
import com.hardcode.gdbms.engine.values.DateValue; |
13 |
import com.hardcode.gdbms.engine.values.NumericValue; |
14 |
import com.hardcode.gdbms.engine.values.Value; |
15 |
import com.iver.cit.gvsig.ExpresionFieldExtension; |
16 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
17 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
18 |
import com.iver.cit.gvsig.project.documents.table.AbstractOperator; |
19 |
import com.iver.cit.gvsig.project.documents.table.Index; |
20 |
/**
|
21 |
* @author Vicente Caballero Navarro
|
22 |
*/
|
23 |
public class Field extends AbstractOperator{ |
24 |
private FieldDescription fd;
|
25 |
public Field() { |
26 |
} |
27 |
public void setFieldDescription(FieldDescription fd) { |
28 |
this.fd=fd;
|
29 |
} |
30 |
public String addText(String s) { |
31 |
return s.concat(toString()+"()"); |
32 |
} |
33 |
|
34 |
public void eval(BSFManager interpreter) throws BSFException { |
35 |
interpreter.declareBean(fd.getFieldAlias(),this,Field.class); |
36 |
interpreter.eval(ExpresionFieldExtension.BEANSHELL,null,-1,-1,"java.lang.Object "+ fd.getFieldAlias()+ "(){return "+fd.getFieldAlias()+".getValue(indexRow,sds);};"); |
37 |
} |
38 |
public Object getValue(Index indexRow,SelectableDataSource sds) { |
39 |
try {
|
40 |
int index=sds.getFieldIndexByName(fd.getFieldName());
|
41 |
Value value=sds.getFieldValue(indexRow.get(),index); |
42 |
if (value instanceof NumericValue) { |
43 |
double dv=((NumericValue)value).doubleValue();
|
44 |
return new Double(dv); |
45 |
}else if (value instanceof DateValue) { |
46 |
Date date=((DateValue)value).getValue();
|
47 |
return date;
|
48 |
}else if (value instanceof BooleanValue){ |
49 |
boolean b=((BooleanValue)value).getValue();
|
50 |
return new Boolean(b); |
51 |
}else {
|
52 |
return value.toString();
|
53 |
} |
54 |
} catch (DriverException e) {
|
55 |
new EvalError(e.getMessage(),null,null); |
56 |
} |
57 |
return null; |
58 |
} |
59 |
public String toString() { |
60 |
return fd.getFieldAlias();
|
61 |
} |
62 |
public boolean isEnable() { |
63 |
return true; |
64 |
} |
65 |
} |