EJB Design Issue to avoid try catch block for RemoteException

Software

jboss 4.0.5

JDK 1.5_06

Problem

I have a Stateful Session Class which till now was used as a normal Desktop Client but now I am trying to convert this class into Stateful Session class.

So to convert that class into Statefull class in such a way that the same class can be used as a normal desktop class as well as for EJB Layer

One of the option got from http://www.unix.org.ua/orelly/java-ent/ebeans/ch09_05.htm

Create a common interface and let the remote interface and the Bean class extends that particular interface

But the probs is that I have called such functions from many classes and so I will have to add this try catch block in many parts of the code for the RemoteException thrown. Is there any way out by which i can avoid this try catch block as it invariably take me very long time to complete the cycle

Thanks in advance

CSJakharia

[938 byte] By [CSJakhariaa] at [2007-11-26 16:27:11]
# 1

Not really, but you can dance around it. What I do is use the command pattern. And create a command processor.

class CommandProcessor {

void process(ICommand command) {

try {

command.perform();

}

catch(RemoteException re){

//Do something

}

}

public interface ICommand {

public void perform() throws RemoteException;

}

This will concentrate all the RemoteExceptions into one place. But you gotta do something with the exception. Maybe show an error dialog or, throw a new one, or whatever is up to you.

In your code you would have

public long getCost(){

CostCommand cm = new CostCommand();

getCmdProcessor().process(cm);

return cm.cost;

}

_dnoyeBa at 2007-7-8 22:51:22 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

> Problem

> I have a Stateful Session Class which till now was

> used as a normal Desktop Client but now I am trying

> to convert this class into Stateful Session class.

You are trying to convert a stateful session class into a stateful session class? Can you clarify exactly what it is your are trying to accomplish?

> So to convert that class into Statefull class in such

> a way that the same class can be used as a normal

> desktop class as well as for EJB Layer

Why? What problem are you trying to solve? Are you aware that EJB 3 is a complete redesign of EJB? This was done because the previous versions of EJB are bad. It sounds like you are trying to couple your application logic to an old verison of EJB. Why do you want to do this?

Is there some reason you can't take your code and just make it a normal Java class and build your EJB to use it? I'm not sure I understand your problem but it sounds like you are making it harder than it needs to be.

dubwaia at 2007-7-8 22:51:22 > top of Java-index,Other Topics,Patterns & OO Design...