public static void main(String[] args) {
try {
System.out.println("Unmarshalling Invoice");
MyInvoice invoice = null;
invoice = MyInvoice.unmarshal(new FileReader("invoice1.xml"));
System.out.println();
System.out.println("unmarshalled...performing tests...");
System.out.println();
// -- Display unmarshalled address to the screen
System.out.println("Invoice");
System.out.println("-------");
System.out.println();
System.out.println("Ship To:");
ShipTo shipTo = invoice.getShipTo();
System.out.println(" " + shipTo.getCustomer().getName());
AddressElement address = shipTo.getCustomer().getAddressElement();
System.out.println(" " + address.getStreet1());
String street2 = address.getSecondStreet();
if (street2 != null) {
System.out.println(" " + street2);
}
System.out.print(" " + address.getCity());
System.out.print(", " + address.getState());
System.out.println(" " + address.getZipCode());
System.out.println(" " + shipTo.getCustomer().getPhone());
System.out.println();
System.out.println("Item:");
Item[] item = invoice.getItem();
for (int i = 0; i < item.length; i++) {
String result = item[i].getInStock() ? "yes" : "no";
System.out.println(" In Stock: " + result);
System.out.println(" Category:" + item[i].getCategory());
System.out.println(" ID:" + item[i].getId());
System.out.println(" Quantity:" + item[i].getQuantity());
System.out.println(" Price:" + item[i].getSpecialPrice());
}
System.out.println();
System.out.println("Shipping Method:");
ShippingMethod method = invoice.getShippingMethod();
System.out.print(" " + method.getCarrier());
System.out.println(" " + method.getOption());
System.out.print(" Estimated Time: ");
Duration duration = method.getEstimatedDelivery();
int years = duration.getYear();
int months = duration.getMonth();
int days = duration.getDay();
int hours = duration.getHour();
boolean printComma = false;
if (years > 0) {
System.out.print(years + " year(s)");
printComma = true;
}
if (months > 0) {
if (printComma) {
System.out.print(", ");
}
System.out.print(months + " month(s)");
printComma = true;
}
if (days > 0) {
if (printComma) {
System.out.print(", ");
}
System.out.print(days + " day(s)");
printComma = true;
}
if (hours > 0) {
if (printComma) {
System.out.print(", ");
}
System.out.print(hours + " hour(s)");
}
System.out.println();
System.out.println();
System.out.println("Shipping Date:");
ShippingDate date = invoice.getShippingDate();
Date day = date.getDate();
Time time = date.getTime();
System.out.println(" Date :" + day.toString());
System.out.println(" Time :" + time.toString());
System.out.println();
System.out.println("----End of Invoice----");
invoice.marshal(new FileWriter("invoice2.xml"));
} catch (Exception e) {
e.printStackTrace();
}