01: package com.titan.travelagent;
02:
03: import com.titan.cabin.CabinLocal;
04: import com.titan.cabin.CabinHomeLocal;
05: import java.rmi.RemoteException;
06: import javax.naming.InitialContext;
07: import javax.naming.Context;
08: import javax.ejb.EJBException;
09: import java.util.Properties;
10: import java.util.Vector;
11:
12: public class TravelAgentBean implements javax.ejb.SessionBean {
13:
14: public void ejbCreate() throws javax.ejb.CreateException {
15: // Do nothing.
16: }
17:
18: public String[] listCabins(int shipID, int bedCount) {
19:
20: try {
21:
22: javax.naming.Context jndiContext = new InitialContext();
23: Object obj = jndiContext
24: .lookup("java:comp/env/ejb/CabinHomeLocal");
25:
26: CabinHomeLocal home = (CabinHomeLocal) javax.rmi.PortableRemoteObject
27: .narrow(obj, CabinHomeLocal.class);
28:
29: Vector vect = new Vector();
30: for (int i = 1;; i++) {
31: Integer pk = new Integer(i);
32: CabinLocal cabin = null;
33: try {
34: cabin = home.findByPrimaryKey(pk);
35: } catch (javax.ejb.FinderException fe) {
36: System.out.println(">>>> Caught exception: "
37: + fe.getMessage() + " for pk=" + i);
38: break;
39: }
40:
41: // Check to see if the bed count and ship ID match
42: if (cabin != null &&
43: // cabin.getShipId() == shipID && //getShipId only exist in Remote interface
44: cabin.getBedCount() == bedCount) {
45: String details = i + "," + cabin.getName() + ","
46: + cabin.getDeckLevel();
47: vect.addElement(details);
48: }
49: }
50:
51: String[] list = new String[vect.size()];
52: vect.copyInto(list);
53: return list;
54:
55: } catch (Exception e) {
56: throw new EJBException(e);
57: }
58: }
59:
60: public void ejbRemove() {
61: }
62:
63: public void ejbActivate() {
64: }
65:
66: public void ejbPassivate() {
67: }
68:
69: public void setSessionContext(javax.ejb.SessionContext cntx) {
70: }
71: }
|