BindGen example code

The /examples/bindgen directory of the JiBX distribution contains some samples for demonstrating the use of BindGen. The samples use two versions of the same code, the first (in the package org.jibx.starter1) using Java 5 typed collections and an enum type, and the second (in the package org.jibx.starter2) using untyped collections and a custom type-safe enumeration type.

Both versions of the code model the data which would be used for order processing by an online store. Here's a sample from the Java 5 version, with only a few of the classes shown and most of the get/set access methods left out:

/**
 * Order information.
 */
public class Order
{
    private long orderNumber;
    
    private Customer customer;
    
    /** Billing address information. */
    private Address billTo;
    
    private Shipping shipping;
    
    /** Shipping address information. If missing, the billing address is also used as the
     shipping address. */
    private Address shipTo;
    
    private List items;
    
    /** Date order was placed with server. */
    private Date orderDate;
    
    /** Date order was shipped. This will be <code>null</code> if the order has not
     yet shipped. */
    private Date shipDate;

    public long getOrderNumber() {
        return orderNumber;
    }

    public void setOrderNumber(long orderId) {
        this.orderNumber = orderId;
    }
    ...
}

/**
 * Address information.
 */
public class Address
{
    /** First line of street information (required). */
    private String street1;
    
    /** Second line of street information (optional). */
    private String street2;
    
    private String city;
    
    /** State abbreviation (required for the U.S. and Canada, optional otherwise). */
    private String state;
    
    /** Postal code (required for the U.S. and Canada, optional otherwise). */
    private String postCode;
    
    /** Country name (optional, U.S. assumed if not supplied). */
    private String country;

    public String getStreet1() {
        return street1;
    }

    public void setStreet1(String street1) {
        this.street1 = street1;
    }
    ...
}

/**
 * Supported shipment methods. The "INTERNATIONAL" shipment methods can only be used for
 * orders with shipping addresses outside the U.S., and one of these methods is required
 * in this case.
 */
public enum Shipping
{
    STANDARD_MAIL, PRIORITY_MAIL, INTERNATIONAL_MAIL, DOMESTIC_EXPRESS, INTERNATIONAL_EXPRESS
}

Generation examples

The Ant build.xml file in the /examples/bindgen defines build targets for four different ways of generating a binding and schema from the example code. These are discussed in more detail in the other pages of this section: