0 Replies Latest reply on Nov 3, 2004 1:49 PM by trickard

    Cast questions

    trickard Newbie

      I have a situation that works but I have no idea why. I am hoping for an explanation.

      Our system has a session bean that manages an entity bean. All external calls pass through the session bean. There is an Info value object which is used to pass information into and out of the entity bean. The remote interface for the entity bean simply consists of a get and set method using this value object.

      public class ProductEligibilityInfo implements Serializable {
      
      
       private String stock_code;
       private String special_print_code;
       private Long item_process_id;
      ...
      }
      
      public interface ProductEligibility extends EJBObject {
      
       public ProductEligibilityInfo getInfo() throws RemoteException;
      
       public void setInfo(ProductEligibilityInfo rebate_info) throws RemoteException;
      
      }
      
      public class ProductEligibilityPK implements Externalizable, Serializable {
       private String stock_code;
       private String special_print_code;
       private long item_process_id;
      ...
      }
      
      




      In one call the session bean calls a finder function on the entity bean and the entity bean returns an enumeration of PK objects. The session bean iterates through the enumeration and assigns the element (PK object) to a remote interface object (rif). rif.getInfo() is called and the returned object is assigned to a new vector.

      while (enumOfPK.hasMoreElements() )
      {
       RemoteIF rif = (RemoteIF)enumOfPK.nextElement();
       vector.add(rif.getInfo());
      }
      


      This somehow works! How can I cast the PK object to a RemoteIF and not get a class cast exception.

      When I step through the bean code , the eclipse debugger can identify each of the objects types correctly. This is what the debugger displays when I highlight the $Proxy object in the returned enumeration.

      ProductEligibility:[ProductEligibilityPK: stock_code ' 58T'
      special_print_code '0005'
      item_process_id '9']

      When I highlight the vector that is being built with the rif.getInfo() call after the add the debugger displays.

      [[ProductEligibilityInfo: stock_code ' 58T'
      special_print_code '0005'
      item_process_id '4']]


      The Info object and the PK object have identical data layouts which I guess is how we have lucked out for the last 3 years.