Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

PortableRemoteObject.narrow()

 
Ravi Patel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Little help please,

I understand that when using remote references (stubs) to EJB's they must be narrowed in the following mannor:

InitialContext ctx = new InitialContext();
Object obj = ctx.lookup(SomeObject);
SpecificObject so = (SpecificObject) PortableRemoteObject.narrow(obj, SpecificObject.class);

However, do you also have to use PortableRemoteObject.narrow() when obtaining a datasource, or some other kind of object?

Thanks in advance!
 
siva kumar
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not required

In case of Data Source and LocalHome
 
Ravi Patel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

Why is it not required when obtaining a datasource but it is for remote home interfaces obtained using ctx.lookup()?
 
Susanta Chatterjee
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The EJB spec requires the RMI-IIOP to conform with CORBA standard and Corba standard supports languages (besides C++ or Java) which does not support direct casting. So, in order to be compliant with RMI-IIOP, if one has to cast a remote reference (which may not be a direct subclass of EJBHome) to a subclass of EJBHome, (s)he has to use PortableRemoteObject.narrow method to do that. This is required as the application server JVM may obtain the reference to the home over RMI-IIOP protocol and the actual implementation of the Home object may reside in an environment outside this JVM.

But, in case of situations like pooled connections or local home, the implemented object reside in the same JVM, which means you can always use downcasting (polymorphism) and use a direct cast to your home class type.

Hope this helps, but I am sure there will be someone who can better explain this.
[ October 04, 2004: Message edited by: Susanta Chatterjee ]
 
Ravi Patel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

Things are slightly clearer but I still am slightly confused.

I thought you could obtain a datasource from a remote application server?

If this was the case, would you have to do the following?

PortableRemoteObject.narrow(ref, javax.sql.Datasource.class)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!