001: /**
002: * Redistribution and use of this software and associated documentation
003: * ("Software"), with or without modification, are permitted provided
004: * that the following conditions are met:
005: *
006: * 1. Redistributions of source code must retain copyright
007: * statements and notices. Redistributions must also contain a
008: * copy of this document.
009: *
010: * 2. Redistributions in binary form must reproduce the
011: * above copyright notice, this list of conditions and the
012: * following disclaimer in the documentation and/or other
013: * materials provided with the distribution.
014: *
015: * 3. The name "Exolab" must not be used to endorse or promote
016: * products derived from this Software without prior written
017: * permission of Intalio, Inc. For written permission,
018: * please contact info@exolab.org.
019: *
020: * 4. Products derived from this Software may not be called "Exolab"
021: * nor may "Exolab" appear in their names without prior written
022: * permission of Intalio, Inc. Exolab is a registered
023: * trademark of Intalio, Inc.
024: *
025: * 5. Due credit should be given to the Exolab Project
026: * (http://www.exolab.org/).
027: *
028: * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
029: * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
030: * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
031: * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
032: * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
033: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
034: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
035: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
036: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
037: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
038: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
039: * OF THE POSSIBILITY OF SUCH DAMAGE.
040: *
041: * Copyright 2000 (C) Intalio, Inc. All Rights Reserved.
042: *
043: * $Id: InvoiceTest.java 6964 2007-04-23 22:23:38Z rjoachim $
044: */package codegen;
045:
046: import java.beans.PropertyChangeEvent;
047: import java.beans.PropertyChangeListener;
048: import java.io.FileReader;
049: import java.io.FileWriter;
050:
051: import org.exolab.castor.types.Date;
052: import org.exolab.castor.types.Duration;
053: import org.exolab.castor.types.Time;
054:
055: import test.AddressElement;
056: import test.MyInvoice;
057: import test.ShipTo;
058: import test.ShippingDate;
059: import test.ShippingMethod;
060: import test.business.Item;
061:
062: /**
063: * Example class that uses classes generated by the Castor source generator to
064: * unmarshal and marshal an XML document.
065: *
066: * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
067: * @version $Revision: 6964 $ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
068: */
069: public class InvoiceTest implements PropertyChangeListener {
070:
071: public void propertyChange(PropertyChangeEvent event) {
072: System.out
073: .println("PropertyChange: " + event.getPropertyName());
074: } // -- propertyChange
075:
076: public static void main(String[] args) {
077: try {
078: System.out.println("Unmarshalling Invoice");
079:
080: MyInvoice invoice = null;
081: invoice = MyInvoice
082: .unmarshal(new FileReader("invoice1.xml"));
083:
084: System.out.println();
085: System.out.println("unmarshalled...performing tests...");
086: System.out.println();
087:
088: // -- Display unmarshalled address to the screen
089: System.out.println("Invoice");
090: System.out.println("-------");
091: System.out.println();
092: System.out.println("Ship To:");
093:
094: ShipTo shipTo = invoice.getShipTo();
095:
096: System.out.println(" " + shipTo.getCustomer().getName());
097:
098: AddressElement address = shipTo.getCustomer()
099: .getAddressElement();
100:
101: System.out.println(" " + address.getStreet1());
102: String street2 = address.getSecondStreet();
103: if (street2 != null) {
104: System.out.println(" " + street2);
105: }
106: System.out.print(" " + address.getCity());
107: System.out.print(", " + address.getState());
108: System.out.println(" " + address.getZipCode());
109:
110: System.out.println(" " + shipTo.getCustomer().getPhone());
111:
112: System.out.println();
113: System.out.println("Item:");
114: Item[] item = invoice.getItem();
115: for (int i = 0; i < item.length; i++) {
116: String result = item[i].getInStock() ? "yes" : "no";
117: System.out.println(" In Stock: " + result);
118: System.out.println(" Category:"
119: + item[i].getCategory());
120: System.out.println(" ID:" + item[i].getId());
121: System.out.println(" Quantity:"
122: + item[i].getQuantity());
123: System.out.println(" Price:"
124: + item[i].getSpecialPrice());
125: }
126: System.out.println();
127: System.out.println("Shipping Method:");
128:
129: ShippingMethod method = invoice.getShippingMethod();
130: System.out.print(" " + method.getCarrier());
131: System.out.println(" " + method.getOption());
132: System.out.print(" Estimated Time: ");
133:
134: Duration duration = method.getEstimatedDelivery();
135:
136: int years = duration.getYear();
137: int months = duration.getMonth();
138: int days = duration.getDay();
139: int hours = duration.getHour();
140:
141: boolean printComma = false;
142:
143: if (years > 0) {
144: System.out.print(years + " year(s)");
145: printComma = true;
146: }
147:
148: if (months > 0) {
149: if (printComma) {
150: System.out.print(", ");
151: }
152: System.out.print(months + " month(s)");
153: printComma = true;
154: }
155:
156: if (days > 0) {
157: if (printComma) {
158: System.out.print(", ");
159: }
160: System.out.print(days + " day(s)");
161: printComma = true;
162: }
163:
164: if (hours > 0) {
165: if (printComma) {
166: System.out.print(", ");
167: }
168: System.out.print(hours + " hour(s)");
169: }
170:
171: System.out.println();
172:
173: System.out.println();
174: System.out.println("Shipping Date:");
175: ShippingDate date = invoice.getShippingDate();
176: Date day = date.getDate();
177: Time time = date.getTime();
178:
179: System.out.println(" Date :" + day.toString());
180: System.out.println(" Time :" + time.toString());
181: System.out.println();
182:
183: System.out.println("----End of Invoice----");
184: invoice.marshal(new FileWriter("invoice2.xml"));
185:
186: } catch (Exception e) {
187: e.printStackTrace();
188: }
189:
190: }
191:
192: }
|