Appendix B. Quick Source Files

This appendix contains the source files for classes into which the XML documents will be unmarshalled. The examples in Chapter 9 use these classes. Each demonstrates that in addition to data accessor and mutator methods, Quick is capable of converting XML into Java classes that have business methods. All of these classes are also available online at http://www.newInstance.com.

Example B-1 is the top of the object tree and represents a purchase order. This can, in turn, store several different orders and also has a business method on it (getTotalPrice()).

Example B-1. The PurchaseOrder class

package javajaxb.po;
  
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
  
public class PurchaseOrder {
  
    /** The list of <code>{@link Order}</code> objects */
    protected List orderList;
  
    public PurchaseOrder(  ) {
        this(new LinkedList(  ));
    }
    
    public PurchaseOrder(List orderList) {
        if (orderList != null) {
            this.orderList = orderList;
        } else {
            this.orderList = new LinkedList(  );
        }
    }
  
    public List getOrderList(  ) {
        return orderList;
    }
  
    public void setOrderList(List orderList) {
        this.orderList = orderList;
    }
  
    public void addOrder(Order order) {
        orderList.add(order);
    }
  
    public float getTotalPrice(  ) {
        if (orderList == null) {
            return 0;
        }
        
        float totalPrice = 0;
        for (Iterator i = orderList.iterator(); i.hasNext(  ); ) {
            Order order = (Order)i.next(  );
            totalPrice += order.getStock().getQuantity() * order.getPurchasePrice(  );
        }
        return totalPrice;
    }
}

Example ...

Get Java & XML Data Binding now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.