Indeed the DataRemoteFactory should instantiates (and returns) an object of type DataRemoteImpl which extends UnicastRemoteObject and has though composition a reference to the DataRemoteAdapter class.
The problem takes place when the remote object is casted to suncertify.db.DataRemoteAdapter which through composition has an instance of DBAccess dba = new Data(); and implements all the method given by the Sun inteface.
Since the casting is failing I'm wondering what kind of type the received "DataRemote remote" has at runtime .When usinf getClass(0 on it , I see the : "class $Proxy1"
Joined: Oct 04, 2007
I found the solution!!! The DataRemoteImpl must be of type : DBAccess!!!
This is the way I implemented it:
suncertify.db.DBAccess <-- given by SUN suncertify.db.Data <-- implementation of DBAccess suncertify.db.DataRemoteAdapter extends Remote <-- interface which declares all methods declared in the DBAccess. because this uses the Remote interface I'll be able to throw RemoteException as required by RMI. suncertify.db.DataRemoteAdapterImpl implements DataRemoteAdapter <-- has a reference to the Data class and calls the Data's methods.