I have the Bodgitt & Scarper DBMain interface. I'm using a DabaseFactory class to create a local or RMI connection based on command line arguments. I would like a single interface class to be used for both local and remote.
As an example, there's a read method in DBMain
public String  read(int recNo) throws RecordNotFoundException;
and I have implemented
public class RecordNotFoundException extends IOException
So in terms of an exception hierarchy I should have
I've tried taking the exceptions, RecordNotFoundException & DuplicateKeyException thrown by each method in the DBMain interface and have them extend IOException. And I've extended the DBMain interface in a new DatabaseInterface to give some additional methods. My idea was that I could simply use DatabaseInterface and if in local mode throw an IOException in local mode, and RemoteException in RMI mode. I belive this is possible as I can also throw the same or a narrower exception. For exampe with the read Interface method which throws RecordNotFoundException.
But though the code compiles, when I run RMIC tool to generate stubs for remote mode I seem to get errors such as
error: suncertify.db.DBMain is not a valid remote interface: method java.lang.String read(int) must throw java.rmi.RemoteException
Personally I wouldn't make RecordNotFoundException & DuplicateKeyException subclasses of IOException IMO I feel that this is a bad design choice, is a RecordNotFoundException & DuplicateKeyException really an IOException. In my implementation I sub classed Exception directly.
My idea was that I could simply use DatabaseInterface and if in local mode throw an IOException in local mode, and RemoteException in RMI mode. I belive this is possible as I can also throw the same or a narrower exception. For exampe with the read Interface method which throws RecordNotFoundException.
For this to work I think you will need to have RecordNotFoundException extend RemoteException.
In my design I use a Connection Factory on the client which returns a Connection object. I give this object to my GUI Controller which then uses it to make data related calls for the GUI. I have two classes that implement the Connection interface, LocalConnection and RemoteConnection. My Connection interface contains all the methods the controller will need to serve the GUI's needs and each method signature throws a ConnectionException that way the client does not need to worry what type of exception was thrown whether it be a RemoteException or RecordNotFoundExcption.
Can you explain how your Connection Interface relates back to sun's DBMain interface and the Data.java file you are required to implement?
As an example, how is public String  read(int recNo) throws RecordNotFoundException; dealt with in your LocalConnection and RemoteConnection
thanks for your thoughts
BookingDataMgr, if a problem occurs it catches a BookingException and throws a new ConnectionException. For remote mode my RemoteConnection class uses a RemoteBookingMgr object which is bound in the registry this object throws a remote exceptions as required by rmi and BookingExceptions as it simply acts as a proxy delegating calls onto a BookingDataMgr class. If the RemoteConnection object encounters a problem such as a RemoteException, BookingException it throws a new ConnectionException that takes the caught exception. So I have the following design
controller throws ControllerException
ConnectionFactory(on client) - returns a LocalConnection object or RemoteConnection - throws ConnectionException
Server with Remote Booking Object object(Remote Mode only) throws RemoteException, Booking Exception
BookingDataMgr - throws BookingException
Data throws RecordNotFoundException etc