FileDocCategorySizeDatePackage
Client_7.javaAPI DocExample2121Sat Mar 06 09:46:30 GMT 1999com.titan.cabin

Client_7

public class Client_7 extends Object

Fields Summary
Constructors Summary
Methods Summary
public static javax.naming.ContextgetInitialContext()


        Properties p = new Properties();
        // ... specify the JNDI properties specific to the vendor
        return new javax.naming.InitialContext(p);
    
public static voidmain(java.lang.String[] args)

        try{

            // obtain cabin 100
            Context jndiContext = getInitialContext();
            CabinHome home = (CabinHome)jndiContext.lookup("CabinHome");
            CabinPK pk_1 = new CabinPK();
            pk_1.id = 100;
            Cabin cabin_1 = home.findByPrimaryKey(pk_1);

            // serialize the Handle for cabin 100 to a file.
            Handle handle = cabin_1.getHandle();
            FileOutputStream fos = new FileOutputStream("handle100.ser");
            ObjectOutputStream outStream = new ObjectOutputStream(fos);
            outStream.writeObject(handle);
            outStream.flush();
            fos.close();
            handle = null;

            // deserialize the Handle for cabin 100
            FileInputStream fis = new FileInputStream("handle100.ser");
            ObjectInputStream inStream = new ObjectInputStream(fis);
            handle = (Handle)inStream.readObject();
            fis.close();

            // re-obtain a remote refernce to cabin 100 and read its name
            Cabin cabin_2 = (Cabin)handle.getEJBObject();
            System.out.println(cabin_2.getName());

        }catch(java.rmi.RemoteException re){re.printStackTrace();}
         catch(javax.naming.NamingException ne)
              {ne.printStackTrace();}
         catch(Throwable t){t.printStackTrace();}