KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > javax > ejb > EJBObject

javax.ejb
Interface EJBObject

All Superinterfaces:
Remote
All Known Subinterfaces:
Management
See Also:
Top Examples, Source Code

public EJBHome getEJBHome()
                   throws RemoteException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Handle getHandle()
                 throws RemoteException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[644]Returns the String that represents the given EJBObject handle in serialized format
By Anonymous on 2004/02/04 11:19:21  Rate
// Returns the String that represents the given 
 // EJBObject's handle in serialized format. 
 public String getId ( EJBObject session )  throws ServiceLocatorException  {  
     String id = null; 
     try  {  
         javax.ejb.Handle handle = session.getHandle (  ) ; 
         ByteArrayOutputStream fo = new ByteArrayOutputStream (  ) ; 
         ObjectOutputStream so = new ObjectOutputStream ( fo ) ; 
         so.writeObject ( handle ) ; 
         so.flush (  ) ; 
         so.close (  ) ; 
         id = new String ( fo.toByteArray (  )  ) ; 
      }  catch  ( RemoteException rex )   {  
         throw new ServiceLocatorException ( rex ) ; 
      }  catch  ( IOException ioex )   {  
         throw new ServiceLocatorException ( ioex ) ; 
      }  
  
  
     return id; 
  } 


public Object getPrimaryKey()
                     throws RemoteException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isIdentical(EJBObject obj)
                    throws RemoteException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[648]Serialize and Deserialize the Handle for a EJB bean
By Anonymous on 2004/02/04 12:33:51  Rate
Context jndiContext = getInitialContext (  ) ;   
  
  
  Object ref = jndiContext.lookup ( "myEntityBeanHomeRemote" ) ; 
  myEntityBeanHomeRemote home =  ( myEntityBeanHomeRemote )  
     PortableRemoteObject.narrow ( ref,myEntityBeanHomeRemote.class ) ; 
  
  
  System.out.println ( "Testing serialization of EJBObject handle" ) ; 
  
  
  Integer pk_1 = new Integer ( 100 ) ; 
  myEntityBeanRemote myEntityBean_1 = home.findByPrimaryKey ( pk_1 ) ; 
  
  
  // Serialize the Handle for myEntityBean 100 to a file. 
  Handle handle = myEntityBean_1.getHandle (  ) ; 
  FileOutputStream fos = new FileOutputStream ( "handle100.ser" ) ; 
  ObjectOutputStream outStream = new ObjectOutputStream ( fos ) ; 
  System.out.println ( "Writing handle to file..." ) ; 
  outStream.writeObject ( handle ) ; 
  outStream.flush (  ) ; 
  fos.close (  ) ; 
  handle = null; 
  
  
  // Deserialize the Handle for myEntityBean 100. 
  FileInputStream fis = new FileInputStream ( "handle100.ser" ) ; 
  ObjectInputStream inStream = new ObjectInputStream ( fis ) ; 
  System.out.println ( "Reading handle from file..." ) ; 
  handle =  ( Handle ) inStream.readObject (  ) ; 
  fis.close (  ) ; 
  
  
  // Reobtain a remote reference to myEntityBean 100 and read its name. 
  System.out.println ( "Acquiring reference using deserialized handle..." ) ; 
  ref = handle.getEJBObject (  ) ; 
  myEntityBeanRemote myEntityBean_2 =  ( myEntityBeanRemote )  
     PortableRemoteObject.narrow ( ref, myEntityBeanRemote.class ) ; 
  
  
  if ( myEntityBean_1.isIdentical ( myEntityBean_2 )  )   
   {  
     System.out.println ( "myEntityBean_1.isIdentical ( myEntityBean_2 )  returns true - This is correct" ) ; 
   }   
  else  
   {  
     System.out.println ( "myEntityBean_1.isIdentical ( myEntityBean_2 )  returns false - This is wrong!" ) ; 
   }  
  
  
 


public void remove()
            throws RemoteException,
                   RemoveException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags