001: /*
002: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. U.S.
003: * Government Rights - Commercial software. Government users are subject
004: * to the Sun Microsystems, Inc. standard license agreement and
005: * applicable provisions of the FAR and its supplements. Use is subject
006: * to license terms.
007: *
008: * This distribution may include materials developed by third parties.
009: * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks
010: * or registered trademarks of Sun Microsystems, Inc. in the U.S. and
011: * other countries.
012: *
013: * Copyright (c) 2005 Sun Microsystems, Inc. Tous droits reserves.
014: *
015: * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel
016: * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de
017: * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions
018: * en vigueur de la FAR (Federal Acquisition Regulations) et des
019: * supplements a celles-ci. Distribue par des licences qui en
020: * restreignent l'utilisation.
021: *
022: * Cette distribution peut comprendre des composants developpes par des
023: * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE
024: * sont des marques de fabrique ou des marques deposees de Sun
025: * Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
026: */
027:
028: package orderclient;
029:
030: import java.util.*;
031: import javax.naming.Context;
032: import javax.naming.InitialContext;
033: import javax.rmi.PortableRemoteObject;
034: import order.LineItem;
035: import order.OrderRemote;
036: import order.OrderRemoteHome;
037:
038: public class OrderClient {
039: public static void main(String[] args) {
040: try {
041: ArrayList lineItems = new ArrayList();
042:
043: lineItems.add(new LineItem("p23", 13, 12.00, 1, "123"));
044: lineItems.add(new LineItem("p67", 47, 89.00, 2, "123"));
045: lineItems.add(new LineItem("p11", 28, 41.00, 3, "123"));
046:
047: Context initial = new InitialContext();
048: Object objref = initial.lookup("ejb/SimpleOrder");
049:
050: OrderRemoteHome home = (OrderRemoteHome) PortableRemoteObject
051: .narrow(objref, OrderRemoteHome.class);
052:
053: OrderRemote duke = home.create("123", "c44", "open",
054: totalItems(lineItems), lineItems);
055:
056: displayItems(duke.getLineItems());
057: System.out.println();
058:
059: Collection c = home.findByProductId("p67");
060: Iterator i = c.iterator();
061:
062: while (i.hasNext()) {
063: OrderRemote order = (OrderRemote) i.next();
064: String id = (String) order.getPrimaryKey();
065:
066: System.out.println(id);
067: }
068:
069: System.exit(0);
070: } catch (Exception ex) {
071: System.err.println("Caught an exception.");
072: ex.printStackTrace();
073: }
074: }
075:
076: static double totalItems(ArrayList lineItems) {
077: double total = 0.00;
078: ListIterator iterator = lineItems.listIterator(0);
079:
080: while (iterator.hasNext()) {
081: LineItem item = (LineItem) iterator.next();
082:
083: total += item.getUnitPrice();
084: }
085:
086: return total;
087: }
088:
089: static void displayItems(ArrayList lineItems) {
090: ListIterator iterator = lineItems.listIterator(0);
091:
092: while (iterator.hasNext()) {
093: LineItem item = (LineItem) iterator.next();
094:
095: System.out.println(item.getOrderId() + " "
096: + item.getItemNo() + " " + item.getProductId()
097: + " " + item.getUnitPrice());
098: }
099: }
100: }
|