A user defined Element needs to comply with the Java Bean Standard.
Following is a code sample for SimpleElement:
public class SimpleElement {
private String fieldA;
private String fieldB;
private String fieldC;
public String getFieldA() {
return fieldA;
}
public void setFieldA(String fieldA) {
this.fieldA = fieldA;
}
public String getFieldB() {
return fieldB;
}
public void setFieldB(String fieldB) {
this.fieldB = fieldB;
}
public String getFieldC() {
return fieldC;
}
public void setFieldC(String fieldC) {
this.fieldC = fieldC;
}
}
In elements.xml, you can define it as follows:
<elements.xml>
<myPackage.SimpleElement id="aSimpleElement" fieldA="valueA" fieldB="valueB"
fieldC="valueC" />
</elements.xml>
You can create the instance of SimpleElement
using the following statement:
public static void main(String[] args) throws Exception {
ElementFactory factory = new BasicElementFactory("jar:///elements.xml");
SimpleElement simpleElement = (SimpleElement)
factory.getElement("aSimpleElement");
System.out.println("fieldA: " + simpleElement.getFieldA());
System.out.println("fieldB: " + simpleElement.getFieldB());
System.out.println("fieldC: " + simpleElement.getFieldC());
}
If you run this main method, you can get the following
output:
fieldA: valueA
fieldB: valueB
fieldC: valueC