|
Download Sources | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | |||||||||
@Retention(value=RUNTIME)
@Target(value={TYPE,METHOD})
public @interface FlexNode
Used to define property's node name in the generated XML.
If the declared name begins with @, the property will be an attribute. Otherwise it will be an element. Note that Entity classes, Array, Collection and Map cannot be used as attribute.
This annotation can be used on the class or on the getter method. If the annotation is not present, then the name of the class or the property will be used as the name of the node. It means that each properties will be a nested element by default.
Exemple :
public class Person {
private int _id;
private String _name;
private Person[] _contacts;
private List<Person> _otherContacts;
@FlexNode("@id")
public int getId() {
return _id;
}
public void setId(int id) {
_id = id;
}
@FlexNode("@name")
public String getName() {
return _name;
}
public void setName(String name) {
_name = name;
}
public Person[] getContacts(){
return _contacts;
}
public void setContacts(Person[] contacts){
_contacts = contacts;
}
@FlexNode("others-contacts")
@FlexList(Person.class)
public List<Person> getOtherContacts(){
return _otherContacts;
}
public void setOtherContacts(List<Person> contacts){
_otherContacts = contacts;
}
}
After running the generator, you can now use the PersonBuilder class.
static int ids = 1;
static Person getPerson(String name, Person[] contacts){
Person p = new Person();
p.setId(ids++);
p.setName(name);
p.setContacts(contacts);
return p;
}
public static void main(String[] args) {
// construct "Bob" and his friends
Person bob = getPerson("Bob", new Person[]{
getPerson("Bill", null),
getPerson("Tedd", null),
getPerson("Joey", null)
});
bob.setOtherContacts(Arrays.asList(new Person[]{
getPerson("Serge", new Person[]{
getPerson("Sergine", null)
}),
getPerson("Alain", null),
getPerson("Paul", null)
}));
// generate a dom4j element from "Bob" instance
Element bobElement = PersonBuilder.getElement(bob);
// output the XML to the console
new XMLWriter(System.out).write(bobElement);
}
Generated XML :
<Person id="4" name="Bob">
<contacts>
<Person id="1" name="Bill"/>
<Person id="2" name="Tedd"/>
<Person id="3" name="Joey"/>
</contacts>
<others-contacts>
<Person id="6" name="Serge">
<contacts>
<Person id="5" name="Sergine"/>
</contacts>
</Person>
<Person id="7" name="Alain"/>
<Person id="8" name="Paul"/>
</others-contacts>
</Person>
| Required Element Summary | |
|---|---|
java.lang.String |
value
If the value begins with @, then the property will be an attribute. |
| Element Detail |
|---|
public abstract java.lang.String value
If the value begins with @, then the property will be an attribute. Otherwise it will be an element. Note that Entity classes, Array, Collection and Map cannot be used as attribute.
|
FlexGenerator | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | |||||||||