FileDocCategorySizeDatePackage
Client_4.javaAPI DocExample1995Sat Mar 06 09:47:34 GMT 1999com.titan.travelagent

Client_4.java

package com.titan.travelagent;

import com.titan.cabin.CabinHome;
import com.titan.cabin.Cabin;
import com.titan.cabin.CabinPK;

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

public class Client_4 {

    public static void main(String [] args){
        try{
            Context ctx  = getInitialContext();

            TravelAgentHome agentHome =
             (TravelAgentHome) ctx.lookup("TravelAgentHome");
            TravelAgent agent_1 = agentHome.create();
            TravelAgent agent_2 = agentHome.create();
            boolean x = agent_1.isIdentical(agent_2);
            // x will equal true; the two EJB object are equal

            CabinHome c_home =
             (CabinHome) ctx.lookup("CabinHome");

            CabinPK pk = new CabinPK();
            pk.id = 101;
            Cabin cabin_1 = c_home.findByPrimaryKey(pk);
            Cabin cabin_2 = c_home.findByPrimaryKey(pk);
            x = cabin_1.isIdentical(cabin_2);
            // x will equal true; the two EJB objects are equal

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

    public static void getTheEJBHome(TravelAgent agent)
        throws RemoteException, RemoveException {

        // 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);
    }
}