package com.foo ;
import java.util.Iterator ;
import java.util.List ;
import java.util.ArrayList ;

public class Order {
	private Customer instanceCustomer ;
	public Customer getInstanceCustomer() {
		return this.instanceCustomer ;
	}
	public void setInstanceCustomer(Customer customer) {
		this.instanceCustomer = customer ;
	}
	private List instanceItems ;
	public List getInstanceItems() {
		return this.instanceItems ;
	}
	public void setInstanceItems(List items) {
		this.instanceItems = items ;
	}
	public void addInstanceItem(Item item) {
		this.instanceItems.add(item) ;
	}

	// Castor seems to need a getter that:
	// 1) uses the exact class name of the List elements 
	// 2) and returns the exact class ArrayList

	public ArrayList getItem() {
		return (ArrayList)this.instanceItems ;
	}
	public void setItem(ArrayList items) {
		this.instanceItems = items ;
	}

	public String toString() {
		StringBuffer buf = new StringBuffer() ;
		buf.append("" + getInstanceCustomer()) ;
		if (null == getInstanceItems()) {
			buf.append("Items list is null.") ;
			return buf.toString() ;
		}
		if (getInstanceItems().isEmpty()) {
			buf.append("Items list is empty.") ;
			return buf.toString() ;
		}
		Iterator it = getInstanceItems().iterator() ;
		while (it.hasNext()) {
			buf.append("----\n") ; 
			buf.append("" + (Item)it.next()) ;
		}
		return buf.toString() ;
	}
}

