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 TravelAgentBean implements javax.ejb.SessionBean 13 { 14 15 public void ejbCreate() 16 { 17 } 19 20 public String [] listCabins(int shipID, int bedCount) 21 { 22 try 23 { 24 javax.naming.Context jndiContext = new InitialContext (); 25 Object 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 vect = new Vector (); 33 for (int i = 1; ; i++) 34 { 35 Integer pk = new Integer (i); 36 CabinRemote cabin = null; 37 try 38 { 39 cabin = home.findByPrimaryKey(pk); 40 } 41 catch(javax.ejb.FinderException fe) 42 { 43 System.out.println("Caught exception: "+fe.getMessage()+" for pk="+i); 44 break; 45 } 46 if (cabin != null && 48 cabin.getShipId() == shipID && 49 cabin.getBedCount() == bedCount) 50 { 51 String details = 52 i+","+cabin.getName()+","+cabin.getDeckLevel(); 53 vect.addElement(details); 54 } 55 } 56 57 String [] list = new String [vect.size()]; 58 vect.copyInto(list); 59 return list; 60 61 } 62 catch(Exception e) 63 { 64 throw new EJBException (e); 65 } 66 } 67 68 public void ejbRemove(){} 69 public void ejbActivate(){} 70 public void ejbPassivate(){} 71 public void setSessionContext(javax.ejb.SessionContext cntx){} 72 } 73 | Popular Tags |