File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RemoteStub class and ClassCastException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RemoteStub class and ClassCastException" Watch "RemoteStub class and ClassCastException" New topic
Author

RemoteStub class and ClassCastException

Aruna Raghavan
Ranch Hand

Joined: May 14, 2002
Posts: 194
Hi,
I am having a small problem and I think I know why. I need someone to verify this.
I originally coded my LockManager to use a Connection object reference as clientId. My Connection object extends a UnicastRemoteObject class. Its stub extends a RemoteStub class.
On the client side, I tried to access the connection after looking up my ConnectionFactoryImpl by just doing a
connectionFactoryImpl.getConnection(). This resulted in a ClassCastException. I think it's because the Connection and Stub extend differnet Remote classes as stated above. I did not use a ConnectionInterface as it seemed unnecessary. Connection implements RemoteDataInterface which inturn extends DataInterface (as Peter suggested in one of his recent answers). As long as I access the Connection itself as DataInterface on the client side, every thing works cool.
I also had to put the getLockManager() method on my ConnectionFactoryImpl because my client no longer knows the Connection, it only knows it as a DataInterface. LockManager now takes DataInterface as clientID (under the covers it is still Connection, client just does not know it as such.)
Please let me know if you aee any problems with this. Thanks,
Aruna.


Aruna A. Raghavan<br />SCJP, SCJD, SCWCD
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Are you trying to cast the stub to Connection? That will throw a ClassCastException alright. The stub implements your interface, but is rooted off a completely different class.
- Peter
Aruna Raghavan
Ranch Hand

Joined: May 14, 2002
Posts: 194
Peter,
Yes, that was precisely what I was doing.
Aruna.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RemoteStub class and ClassCastException