KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > titan > travelagent > RTravelAgentBean


1 package com.titan.travelagent;
2
3 import com.titan.cabin.CabinRemote;
4 import com.titan.cabin.CabinHomeRemote;
5 import java.rmi.RemoteException;
6 import javax.naming.InitialContext;
7 import javax.naming.Context;
8 import javax.ejb.EJBException;
9 import java.util.Properties;
10 import java.util.Vector;
11
12 public class RTravelAgentBean 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 =
24                 jndiContext.lookup("java:comp/env/ejb/CabinHomeRemote");
25
26
27             CabinHomeRemote home = (CabinHomeRemote)
28                 javax.rmi.PortableRemoteObject.narrow(obj,CabinHomeRemote.class);
29
30             Vector vect = new Vector();
31             for (int i = 1; ; i++) {
32                 Integer pk = new Integer(i);
33                 CabinRemote cabin = null;
34                 try {
35                     cabin = home.findByPrimaryKey(pk);
36                 } catch(javax.ejb.FinderException fe) {
37                     System.out.println(">>>> Caught exception: "+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 &&
44                     cabin.getBedCount() == bedCount) {
45                     String details = i+","+cabin.getName()+","+cabin.getDeckLevel();
46                     vect.addElement(details);
47                 }
48             }
49         
50             String [] list = new String[vect.size()];
51             vect.copyInto(list);
52             return list;
53        
54         } catch(Exception e) {
55             throw new EJBException(e);
56         }
57     }
58
59     public void ejbRemove() {}
60     public void ejbActivate(){}
61     public void ejbPassivate(){}
62     public void setSessionContext(javax.ejb.SessionContext cntx){}
63 }
64
Popular Tags