001: package enroller;
002:
003: /*
004: * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved. U.S.
005: * Government Rights - Commercial software. Government users are subject
006: * to the Sun Microsystems, Inc. standard license agreement and
007: * applicable provisions of the FAR and its supplements. Use is subject
008: * to license terms.
009: *
010: * This distribution may include materials developed by third parties.
011: * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks
012: * or registered trademarks of Sun Microsystems, Inc. in the U.S. and
013: * other countries.
014: *
015: * Copyright (c) 2004 Sun Microsystems, Inc. Tous droits reserves.
016: *
017: * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel
018: * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de
019: * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions
020: * en vigueur de la FAR (Federal Acquisition Regulations) et des
021: * supplements a celles-ci. Distribue par des licences qui en
022: * restreignent l'utilisation.
023: *
024: * Cette distribution peut comprendre des composants developpes par des
025: * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE
026: * sont des marques de fabrique ou des marques deposees de Sun
027: * Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
028: */
029:
030: import javax.naming.Context;
031: import javax.naming.InitialContext;
032: import javax.rmi.PortableRemoteObject;
033: import java.util.*;
034:
035: public class EnrollerClient {
036: public static void main(String[] args) {
037: try {
038:
039: Context initial = new InitialContext();
040: //Context initial = new InitialContext();
041: Object objref = initial.lookup("ejb/SimpleStudent");
042: StudentRemoteHome sHome = (StudentRemoteHome) PortableRemoteObject
043: .narrow(objref, StudentRemoteHome.class);
044:
045: StudentRemote denise = sHome.create("823", "Denise Smith");
046:
047: objref = initial.lookup("ejb/SimpleCourse");
048:
049: CourseRemoteHome cHome = (CourseRemoteHome) PortableRemoteObject
050: .narrow(objref, CourseRemoteHome.class);
051:
052: CourseRemote power = cHome.create("220",
053: "Power J2EE Programming");
054:
055: objref = initial.lookup("ejb/SimpleEnroller");
056:
057: EnrollerRemoteHome eHome = (EnrollerRemoteHome) PortableRemoteObject
058: .narrow(objref, EnrollerRemoteHome.class);
059:
060: EnrollerRemote enroller = eHome.create();
061:
062: enroller.enroll("823", "220");
063: enroller.enroll("823", "333");
064: enroller.enroll("823", "777");
065: enroller.enroll("456", "777");
066: enroller.enroll("388", "777");
067:
068: System.out.println(denise.getName() + ":");
069:
070: ArrayList courses = denise.getCourseIds();
071: Iterator i = courses.iterator();
072:
073: while (i.hasNext()) {
074: String courseId = (String) i.next();
075: CourseRemote course = cHome.findByPrimaryKey(courseId);
076:
077: System.out.println(courseId + " " + course.getName());
078: }
079:
080: System.out.println();
081:
082: CourseRemote intro = cHome.findByPrimaryKey("777");
083:
084: System.out.println(intro.getName() + ":");
085: courses = intro.getStudentIds();
086: i = courses.iterator();
087:
088: while (i.hasNext()) {
089: String studentId = (String) i.next();
090: StudentRemote student = sHome
091: .findByPrimaryKey(studentId);
092:
093: System.out.println(studentId + " " + student.getName());
094: }
095:
096: System.exit(0);
097: } catch (Exception ex) {
098: System.err.println("Caught an unexpected exception!");
099: ex.printStackTrace();
100: }
101: }
102: }
|