001: /*
002: * Copyright (c) 2004 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) 2004 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 client;
029:
030: import java.util.*;
031: import javax.naming.Context;
032: import javax.naming.InitialContext;
033: import javax.rmi.PortableRemoteObject;
034: import util.*;
035: import roster.*;
036:
037: public class RosterClient {
038: public static void main(String[] args) {
039: try {
040:
041: Context initial = new InitialContext();
042: Object objref = initial.lookup("ejb/RosterBean");
043:
044: RosterRemoteHome home = (RosterRemoteHome) PortableRemoteObject
045: .narrow(objref, RosterRemoteHome.class);
046:
047: RosterRemote myRoster = home.create();
048:
049: insertInfo(myRoster);
050: getSomeInfo(myRoster);
051:
052: // getMoreInfo(myRoster);
053: System.exit(0);
054: } catch (Exception ex) {
055: System.err.println("Caught an exception:");
056: ex.printStackTrace();
057: }
058: }
059:
060: // main
061:
062: private static void getSomeInfo(RosterRemote myRoster) {
063: try {
064: ArrayList playerList;
065: ArrayList teamList;
066: ArrayList leagueList;
067:
068: playerList = myRoster.getPlayersOfTeam("T2");
069: printDetailsList(playerList);
070:
071: teamList = myRoster.getTeamsOfLeague("L1");
072: printDetailsList(teamList);
073:
074: playerList = myRoster.getPlayersByPosition("defender");
075: printDetailsList(playerList);
076:
077: leagueList = myRoster.getLeaguesOfPlayer("P28");
078: printDetailsList(leagueList);
079: } catch (Exception ex) {
080: System.err.println("Caught an exception:");
081: ex.printStackTrace();
082: }
083: }
084:
085: // getSomeInfo
086:
087: private static void getMoreInfo(RosterRemote myRoster) {
088: try {
089: LeagueDetails leagueDetails;
090: TeamDetails teamDetails;
091: PlayerDetails playerDetails;
092: ArrayList playerList;
093: ArrayList teamList;
094: ArrayList leagueList;
095: ArrayList sportList;
096:
097: leagueDetails = myRoster.getLeague("L1");
098: System.out.println(leagueDetails.toString());
099: System.out.println();
100:
101: teamDetails = myRoster.getTeam("T3");
102: System.out.println(teamDetails.toString());
103: System.out.println();
104:
105: playerDetails = myRoster.getPlayer("P20");
106: System.out.println(playerDetails.toString());
107: System.out.println();
108:
109: playerList = myRoster.getPlayersOfTeam("T2");
110: printDetailsList(playerList);
111:
112: teamList = myRoster.getTeamsOfLeague("L1");
113: printDetailsList(teamList);
114:
115: playerList = myRoster.getPlayersByPosition("defender");
116: playerList = myRoster.getAllPlayers();
117: playerList = myRoster.getPlayersNotOnTeam();
118: playerList = myRoster.getPlayersByPositionAndName(
119: "power forward", "Jack Patterson");
120: playerList = myRoster.getPlayersByCity("Truckee");
121: playerList = myRoster.getPlayersBySport("Soccer");
122: playerList = myRoster.getPlayersByLeagueId("L1");
123: playerList = myRoster
124: .getPlayersByHigherSalary("Ian Carlyle");
125: playerList = myRoster.getPlayersBySalaryRange(500.00,
126: 800.00);
127: playerList = myRoster.getPlayersOfTeamCopy("T5");
128:
129: leagueList = myRoster.getLeaguesOfPlayer("P28");
130: printDetailsList(leagueList);
131:
132: sportList = myRoster.getSportsOfPlayer("P28");
133: printDetailsList(sportList);
134: } catch (Exception ex) {
135: System.err.println("Caught an exception:");
136: ex.printStackTrace();
137: }
138: }
139:
140: // getMoreInfo
141:
142: private static void printDetailsList(ArrayList list) {
143: Iterator i = list.iterator();
144:
145: while (i.hasNext()) {
146: Object details = (Object) i.next();
147:
148: System.out.println(details.toString());
149: }
150:
151: System.out.println();
152: }
153:
154: // printDetailsList
155:
156: private static void insertInfo(RosterRemote myRoster) {
157: try {
158: // Leagues
159: myRoster.createLeague(new LeagueDetails("L1", "Mountain",
160: "Soccer"));
161:
162: myRoster.createLeague(new LeagueDetails("L2", "Valley",
163: "Basketball"));
164:
165: // Teams
166: myRoster.createTeamInLeague(new TeamDetails("T1",
167: "Honey Bees", "Visalia"), "L1");
168:
169: myRoster.createTeamInLeague(new TeamDetails("T2",
170: "Gophers", "Manteca"), "L1");
171:
172: myRoster.createTeamInLeague(new TeamDetails("T3", "Deer",
173: "Bodie"), "L2");
174:
175: myRoster.createTeamInLeague(new TeamDetails("T4", "Trout",
176: "Truckee"), "L2");
177:
178: myRoster.createTeamInLeague(new TeamDetails("T5", "Crows",
179: "Orland"), "L1");
180:
181: // Players, Team T1
182: myRoster.createPlayer(new PlayerDetails("P1", "Phil Jones",
183: "goalkeeper", 100.00));
184: myRoster.addPlayer("P1", "T1");
185:
186: myRoster.createPlayer(new PlayerDetails("P2",
187: "Alice Smith", "defender", 505.00));
188: myRoster.addPlayer("P2", "T1");
189:
190: myRoster.createPlayer(new PlayerDetails("P3",
191: "Bob Roberts", "midfielder", 65.00));
192: myRoster.addPlayer("P3", "T1");
193:
194: myRoster.createPlayer(new PlayerDetails("P4",
195: "Grace Phillips", "forward", 100.00));
196: myRoster.addPlayer("P4", "T1");
197:
198: myRoster.createPlayer(new PlayerDetails("P5",
199: "Barney Bold", "defender", 100.00));
200: myRoster.addPlayer("P5", "T1");
201:
202: // Players, Team T2
203: myRoster.createPlayer(new PlayerDetails("P6",
204: "Ian Carlyle", "goalkeeper", 555.00));
205: myRoster.addPlayer("P6", "T2");
206:
207: myRoster.createPlayer(new PlayerDetails("P7",
208: "Rebecca Struthers", "midfielder", 777.00));
209: myRoster.addPlayer("P7", "T2");
210:
211: myRoster.createPlayer(new PlayerDetails("P8",
212: "Anne Anderson", "forward", 65.00));
213: myRoster.addPlayer("P8", "T2");
214:
215: myRoster.createPlayer(new PlayerDetails("P9", "Jan Wesley",
216: "defender", 100.00));
217: myRoster.addPlayer("P9", "T2");
218:
219: myRoster.createPlayer(new PlayerDetails("P10",
220: "Terry Smithson", "midfielder", 100.00));
221: myRoster.addPlayer("P10", "T2");
222:
223: // Players, Team T3
224: myRoster.createPlayer(new PlayerDetails("P11", "Ben Shore",
225: "point guard", 188.00));
226: myRoster.addPlayer("P11", "T3");
227:
228: myRoster.createPlayer(new PlayerDetails("P12",
229: "Chris Farley", "shooting guard", 577.00));
230: myRoster.addPlayer("P12", "T3");
231:
232: myRoster.createPlayer(new PlayerDetails("P13",
233: "Audrey Brown", "small forward", 995.00));
234: myRoster.addPlayer("P13", "T3");
235:
236: myRoster.createPlayer(new PlayerDetails("P14",
237: "Jack Patterson", "power forward", 100.00));
238: myRoster.addPlayer("P14", "T3");
239:
240: myRoster.createPlayer(new PlayerDetails("P15",
241: "Candace Lewis", "point guard", 100.00));
242: myRoster.addPlayer("P15", "T3");
243:
244: // Players, Team T4
245: myRoster.createPlayer(new PlayerDetails("P16",
246: "Linda Berringer", "point guard", 844.00));
247: myRoster.addPlayer("P16", "T4");
248:
249: myRoster.createPlayer(new PlayerDetails("P17",
250: "Bertrand Morris", "shooting guard", 452.00));
251: myRoster.addPlayer("P17", "T4");
252:
253: myRoster.createPlayer(new PlayerDetails("P18",
254: "Nancy White", "small forward", 833.00));
255: myRoster.addPlayer("P18", "T4");
256:
257: myRoster.createPlayer(new PlayerDetails("P19",
258: "Billy Black", "power forward", 444.00));
259: myRoster.addPlayer("P19", "T4");
260:
261: myRoster.createPlayer(new PlayerDetails("P20",
262: "Jodie James", "point guard", 100.00));
263: myRoster.addPlayer("P20", "T4");
264:
265: // Players, Team T5
266: myRoster.createPlayer(new PlayerDetails("P21",
267: "Henry Shute", "goalkeeper", 205.00));
268: myRoster.addPlayer("P21", "T5");
269:
270: myRoster.createPlayer(new PlayerDetails("P22",
271: "Janice Walker", "defender", 857.00));
272: myRoster.addPlayer("P22", "T5");
273:
274: myRoster.createPlayer(new PlayerDetails("P23",
275: "Wally Hendricks", "midfielder", 748.00));
276: myRoster.addPlayer("P23", "T5");
277:
278: myRoster.createPlayer(new PlayerDetails("P24",
279: "Gloria Garber", "forward", 777.00));
280: myRoster.addPlayer("P24", "T5");
281:
282: myRoster.createPlayer(new PlayerDetails("P25",
283: "Frank Fletcher", "defender", 399.00));
284: myRoster.addPlayer("P25", "T5");
285:
286: // Players, no team
287: myRoster.createPlayer(new PlayerDetails("P26",
288: "Hobie Jackson", "pitcher", 582.00));
289:
290: myRoster.createPlayer(new PlayerDetails("P27",
291: "Melinda Kendall", "catcher", 677.00));
292:
293: // Players, multiple teams
294: myRoster.createPlayer(new PlayerDetails("P28",
295: "Constance Adams", "substitute", 966.00));
296: myRoster.addPlayer("P28", "T1");
297: myRoster.addPlayer("P28", "T3");
298: } catch (Exception ex) {
299: System.err.println("Caught an exception:");
300: ex.printStackTrace();
301: }
302: }
303: // insertInfo
304: }
305: // class
|