FileDocCategorySizeDatePackage
Client_3.javaAPI DocExample1472Sat Mar 06 09:47:18 GMT 1999com.titan.travelagent

Client_3.java

package com.titan.travelagent;

import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.ejb.CreateException;
import java.rmi.RemoteException;
import java.util.Properties;

public class Client_3 {

    public static void main(String [] args){
        try{
            Context jndiContext = getInitialContext();
            TravelAgentHome home =
             (TravelAgentHome)jndiContext.lookup("TravelAgentHome");

            // get a remote reference to the bean (EJB object)
            TravelAgent agent = home.create();
            // pass the remote reference to some method
            getTheEJBHome(agent);

            }catch(java.rmi.RemoteException re){re.printStackTrace();}
             catch(Throwable t){t.printStackTrace();}
    }

        public static void getTheEJBHome(TravelAgent agent)
            throws RemoteException {

            // the home interface is out of scope in this method
            // so it must be obtained from the EJB object
            TravelAgentHome home = (TravelAgentHome) agent.getEJBHome( );
            // do something useful with the home interface
        }

    public static Context getInitialContext()
       throws javax.naming.NamingException{

        Properties p = new Properties();
        // ... specify the JNDI properties specific to the vendor
        return new javax.naming.InitialContext(p);
    }
}