aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RemoteException Problem... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RemoteException Problem..." Watch "RemoteException Problem..." New topic
Author

RemoteException Problem...

Song Jing Lim
Ranch Hand

Joined: Feb 11, 2003
Posts: 56
I got a interface (a.java) that got a method (x) which will throws a custome exception (FileNotFoundException) only.
Well, another interface (b.java) that extends Remote and above interface (a.java).
Then my concrate class will implement b.java as RMI implementation class. Well problem came out, the method (x) can't throw RemoteException because method (x) at interface a didn't throw RemoteException (only and only FileNotFoundException).
note: method x at interface a are restrict to not allow be change (method x can only throw FileNotFoundException).
note; FileNotFoundException, I extend from Exception
Any ideal how I can solve above problem???


Rgds,<br />Song Jing
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Well by the nature of the Remote, if you extend remote, then you must through RemoteException in your public methods.
If this class is implementing another interface, then that interface either has to throw RemoteException, or a super class which leaves Exception.
Personally I had my interface throw Exception, then in my implementation classes I can now throw any type of Exception that I like.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Song Jing Lim
Ranch Hand

Joined: Feb 11, 2003
Posts: 56
The problem is the interface is define by Sun and I can't change it as I had confirm by Sun Education Worldwide Manager.
For example one of the method at DBMain.java (interface) will have the signature:
public String [] read(int recNo) throws RecordNotFoundException;
The remote implementation class need to throw the RemoteException else can't be compile by RMIC.
Any ideal I can do?
I had try to extends RecordNotFoundException from Exception and IOException but both also not work.
Any help on that?
Thx
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11278
    
  59

Hi Song Jing
From when we were discussing this in this thread, we had gotten to the point where:

Andrew: Write Data.java to implement the interface as provided by Sun, without changes.
Once you have done that, you can start thinking about what methods you want to provide to clients, and what exceptions need to be thrown. Then create your own interface to define those methods and those exceptions.
Song Jing: So the actualy data access class is create by me which is either using inheritan (extend) or using composition from the class requrie by Sun. So like wrapping class.
ie. my 'real' data access interface class call papter.java and implement by database.java. Inside database.java I can either extend the data.java or create a private object of data.java for composition.

So you have interface DBMain, and you have implemented it's methods in your class Data.java
Now you are trying to develop another class to provide the remote access to the Data class. For the sake of having something to talk about, I am going to call this RemoteData (you can call it anything you want). This is the class that is wrapping Data class as we discussed earlier.
And your question is: how can the method read() in RemoteData throw RemoteException, when it is not declared to throw that in DBMain?
However there is nothing to say that RemoteData has to implement DBMain.
DBMain is the interface that you have to implement in order to create the Data class. Any class that needs to get direct access to the Data class (such as RemoteData, or Sun's automated testing tools) can write to the DBMain interface.
But you are not forced to provide those same methods to remote clients (we were in the old assignment, but it does not appear to be a requirement of the new assignment). You could decide to provide the same methods (and to be honest, I dont see any reason not to), but you dont have to.
So the question then becomes: what methods do you provide to your remote clients, and how do you let them know?
Tackling these in the reverse order: how do you let other programmers know what methods they can use? Simple: create an interface (let's call it RemoteReference). Then RemoteData can implement RemoteReference, and your remote clients can code to the RemoteReference interface.
Now, if you decide that the read() method in RemoteReference should throw RemoteException - go right ahead: you own RemoteReference interface, so you can do that without any problems.
Is this making sense?
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Is this making sense?

Makes sense to me.
Mark
Song Jing Lim
Ranch Hand

Joined: Feb 11, 2003
Posts: 56
Ya...
Thx again
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RemoteException Problem...
 
Similar Threads
throwing IOException instead of RemoteException in Remote Methods
import on demand
B&S 2.2.2 - Network Layer Query
Not able to COMPILE!!!
public class in Java program file