aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI - Stub Generation - B & S Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI - Stub Generation - B & S" Watch "RMI - Stub Generation - B & S" New topic
Author

RMI - Stub Generation - B & S

Paul Truckle
Greenhorn

Joined: Feb 22, 2005
Posts: 24
Hi, I've written some code on the RMI server side and now need to generate stubs. My problem is that I know that the stub generation requires that I throw RemoteException. The supplied interface from Sun doesn't do this. Ive searched the knowledge based here, but most topics talke about creating a superinterface that does throw RemoteException and then changing DBMain to subclass this.... but after numerous reads and what I always thought was the case, you can't change the supplied interface from Sun. Currently thinking of a way around this, so any help or pointing in the right direction would be appreciated.

Cheers,


Paul.
Frans Janssen
Ranch Hand

Joined: Dec 29, 2004
Posts: 357
Paul,

One word: Adapter.

Frans.


SCJP 1.4, SCJD
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11509
    
  95

Hi Paul,

As Frans suggested, the Adapter Pattern is one solution to this problem.

Since I don't like one word answers to questions, here is a little more detail:

In this case, you could have an interface that looks similar to the supplied Sun interface however all it's methods do throw RemoteException. A class that implements this interface could be extremely simple: it would just call the relevant methods of the Data class - in effect, adapting the interface to the format you require.

I have still kept this vague. Have a think about it, and come back with further questions as required.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Paul Truckle
Greenhorn

Joined: Feb 22, 2005
Posts: 24
Hi. Yes, thanks .. I've sorted it. Basically, I created a further class that has an instance of the interface within it. The new class doesn't have the RemoteExceptions within it's methods, but the interface then references the methods that do have the RemoteExceptions (what's returned from rmi server). I've then repeated the methods of the interface within the new class without RemoteException and called the equivalent method in the interface reference...thus achieving my requirement. Is this your definition of Adapter ? This certainly resolves my problem by keeping the client side of the solution still referencing DBMain for remote and local versions.
Frans Janssen
Ranch Hand

Joined: Dec 29, 2004
Posts: 357
Hi Paul,

I do not understand your explanation of your design completely.

The simplest solution (I think) is:

(assumption: the interface given in the assignment is called DBMain)

  • Data implements DBMain
  • Adapter is a new class that has the same interface as DBMain, except for RemoteException that has been added to all methods
  • Adapter is a server-side remote object (extends UnicastRemoteObject)
  • Adapter has a reference to a Data object
  • All methods in Adapeter do no more than forwarding the call to the Data object


  • e.g. the implementation of the isLocked() method in Adapter could be this:



    I hope I did not give away too much

    Frans.
    Paul Truckle
    Greenhorn

    Joined: Feb 22, 2005
    Posts: 24
    Yep ... thanks....that's it....that's what I've done.
    Frans Janssen
    Ranch Hand

    Joined: Dec 29, 2004
    Posts: 357
    Originally posted by Paul Truckle:
    Yep ... thanks....that's it....that's what I've done.


    OK, good job then

    Frans.

    BTW, I see now that I forgot that the Adapter must implement your RMI interface. But I guess you already found that out yourself.
    [ February 25, 2005: Message edited by: Frans Janssen ]
    Paul Truckle
    Greenhorn

    Joined: Feb 22, 2005
    Posts: 24
    Correct.... that's why I talked about interfaces more in my answer.

    Thanks again.
     
    Consider Paul's rocket mass heater.
     
    subject: RMI - Stub Generation - B & S