Example codeHere's a set of classes to be used as an example for the binding generation
tool, all from the public class Customer { private Name name; private Address address; private Order[] orders; } public class Name { private String firstName; private String lastName; } public class Address { private String street; private String city; private String state; private Integer zip; } import java.math.BigDecimal; import java.sql.Date; public class Order { private Date date; private BigDecimal amount; } Running the binding generatorI'll assume that the above set of classes have been compiled into the current directory, and that the jibx-genbinding.jar has been copied into the lib directory of the JiBX installation located at /home/dennis/jibx. Then to generate a default binding for these classes I just need to run the following: java -jar /home/dennis/jibx/lib/jibx-genbinding.jar example.Customer example.Order Note that you don't need to specify every class to be included in the binding
definition, only those classes which should be bound using <mapping>
elements. In this case the Here's the generated binding: <?xml version="1.0" encoding="UTF-8"?> <binding value-style="attribute"> <mapping class="example.Customer" name="customer"> <structure field="name" usage="optional" name="name"> <value style="element" name="first-name" field="firstName" usage="optional"/> <value style="element" name="last-name" field="lastName" usage="optional"/> </structure> <structure field="address" usage="optional" name="address"> <value style="element" name="street" field="street" usage="optional"/> <value style="element" name="city" field="city" usage="optional"/> <value style="element" name="state" field="state" usage="optional"/> <value name="zip" field="zip" usage="optional"/> </structure> <collection field="orders" usage="optional"/> </mapping> <mapping class="example.Order" name="order"> <value name="date" field="date" usage="optional"/> <value name="amount" field="amount" usage="optional"/> </mapping> </binding> Binding generation problemsProblems and potential problems in the binding generation are reported in the
console output from the binding generator tool. For example, suppose the array
of import java.util.ArrayList; public class Customer { private Name name; private Address address; private ArrayList orders; } Then running the binding generation tool gives a warning message: Warning: field orders requires mapped implementation of item classes Similar warning or error messages may result from other types of situations which cannot be handled by the binding generator. The command line options supported by the binding generator can be used to handle many of these situations by supplying additional instructions to the binding generator. |