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