@title("Smart Data Binding in UTGB")
= Smart Data Binding in UTGB
UTGB has an support to map data from !XML/JSON/Relational data format to Java class objects, and vice verca. This conversion is automatically done once you write appropriate Java class definitions.
== An Quick Example
Supporse you have the following XML data (saved as "gene.xml"), which describes a gene object:
gene1
chr1
1000
4000
In order to parse this XML data, you have to write a corresponding Java class definition as follows:
class Gene
{
int id;
String name;
String chr;
int start;
int end;
// public default constructor
public Gene() {}
// setter definitions
public void setId(int id) { this.id = id; }
public void setName(String name) { this.name = name; }
public void setChr(String chr) { this.chr = chr; }
public void setStart(int start) { this.start = start; }
public void setEnd(int end) { this.end = end; }
// getter definitions
public int getId() { return id; }
public Stirng getName() { return name; }
public String getChr() { return chr; }
public int getStart() { return start; }
public int getEnd() { return end; }
}
To create an instance of the Gene object from the XML file ("gene.xml"), you have to use BeanUtil.createBeanFromXML(target class, input reader) mehtod:
BufferedReader xmlReader = new BufferedReader(new FileReader("gene.xml"));
Gene gene = BeanUtil.createBeanFromXML(Gene.class, xmlReader);
// gene.getId() == 1
// gene.getName() == "gene1"
// gene.getChr() == "chr1"
// gene.getStart() == 1000
// gene.getEnd() == 4000
UTGB automatically converts string data appeared in the XML file into appropriate data type (integer, String, etc. ) by seeing setter methods in the class definition.