Ant Task To Generate Convertor Class
To help alleviate the amount of boiler plate code that you may need to write, XML Factory also includes an ant task to generate convertor classes from your Java beans.
To help alleviate the amount of boiler plate code that you may need to write, XML Factory also includes an ant task to generate convertor classes from your Java beans.
Below is a sample Ant build file that utilizes the XmlConvertorTask to create a convertor for my TestObject bean.
A task needs to be defined for the XmlConvertorTask class, using the taskdef Ant tag. On line 1, I named my task xmlConvertor and made sure the classpath points to the appropriate directory, i.e. where the XMLFactory jar is located.
A type needs to be defined for the XmlClass class, using the typedef Ant tag. Again, make sure you have an appropriate classpath and if you are running ant from an IDE like Eclipse you will need to specify the jar on the Ant task launcher classpath.
Lastly, I'll add an Ant target that calls the xmlConvertor task, passing in the output directory.
Nested inside the xmlConvertor task is an xmlClass tag that specifies the class to generate a convertor for (xmlClass), the name of the resultant convertor class (convertorName) and the root xml tag name to be used (rootTagName). Keep in mind that multiple xmlClass tags can be supplied.
Here is my input class, TestObject.
Here is the result convertor, MyTestObjectConvertor. The resultant class is implement as an enum to implement singleton behavior. If this is not the desired output, it can then be tweaked to include/exclude fields or change tag names.