KickJava   Java API By Example, From Geeks To Geeks.

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


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