*
The moose likes EJB and other Java EE Technologies and the fly likes Business Interface Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Business Interface Pattern" Watch "Business Interface Pattern" New topic
Author

Business Interface Pattern

Ram Chilukuri
Greenhorn

Joined: Nov 20, 2003
Posts: 2
Greetings everybody,
I am developing a stateless session bean with both local and remote component interfaces. I am planning on using Business Interface pattern. So, I was wondering if I need to create two business interfaces, one interface (BusinessInterfaceRemote) containing business methods that throw RemoteException, and the other interface (BusinessInterfaceLocal) which contains business methods that don't throw RemoteException.
Assuming that I will need two business interfaces, Local component interface will extend BusinessInterfaceLocal and remote component interface will extend BusinessInterfaceRemote. Which interface will my bean class implement?
Any suggestions are appreciated.
Thanks in advance !!
Ram
Bill Dudney
Author
Ranch Hand

Joined: Sep 05, 2003
Posts: 234
Hi Ram,
I think you will be much better off applying XDoclet to your problem than trying to maintain all the various flavors of interfaces for your session.


TTFN,<br /> <br />-bd-<br /> <br /><a href="http://www.amazon.com/exec/obidos/ASIN/0471449156/qid=1064343733/sr=2-1/ref=sr_2_1/002-8375300-3666449" target="_blank" rel="nofollow">Jakarta Pitfalls</a> | <a href="http://www.amazon.com/exec/obidos/tg/detail/-/0471146153/qid=1064343733/sr=1-2/ref=sr_1_2/002-8375300-3666449?v=glance&s=books" target="_blank" rel="nofollow">J2EE AntiPatterns</a> | <a href="http://www.amazon.com/exec/obidos/tg/detail/-/0471462071/qid=1064343733/sr=1-3/ref=sr_1_3/002-8375300-3666449?v=glance&s=books" target="_blank" rel="nofollow">Mastering JavaServer Faces</a> | <a href="http://bill.dudney.net/roller/page/bill" target="_blank" rel="nofollow">Blog</a> | <a href="http://www.jroller.com/page/BillDudney" target="_blank" rel="nofollow">Eclipse Blog</a> | <a href="http://www.sourcebeat.com/TitleAction.do?id=2" target="_blank" rel="nofollow">Eclipse 3 Live</a>
Ram Chilukuri
Greenhorn

Joined: Nov 20, 2003
Posts: 2
Hello Bill,
Thanks for your suggestion. I will look into XDoclet.
I still am confused as to which business interface (BusinessInterfaceLocal or BusinessInterfaceRemote) the bean should implement. Does it really matter which interface the bean should implement since there is no difference between the business method signatures?
Thanks a ton,
Ram
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Ram Chilukuri:
I still am confused as to which business interface (BusinessInterfaceLocal or BusinessInterfaceRemote) the bean should implement. Does it really matter which interface the bean should implement since there is no difference between the business method signatures?

First of all, +1 on the XDoclet suggestion. I can't begin to convey how much happier my programming time is not having to propogate new methods from the bean to the interfaces et al. Two thumbs way up! XDoclet will generate both your local and remote interfaces, your local and remote home interfaces, and more. It takes some work to get started, so definitely subscribe to the mailing list.
Now, since your remote interface is going to throw RemoteException but the local one won't, you can't use the same interface for both. What I did, however, was use the Service Delegate pattern (might be the wrong name, sorry) in front of my session beans. I started by taking the generated local interface as the business interface. Then there are two delegates that implement that interface: one remote and one local. The only difference between them is that the remote delegate catches RemoteExceptions and throws a ServiceException (unchecked application exception) with the RE as the cause.
Each delegate has a session bean stub that it creates the first time the service is requested. The delegates are regular Java Beans with accessors for the JNDI factory class, URL, and root. Those are used to connect to the bean. With that, each method simply delegates to the bean (thus the name).
Just last night when I was confronted with creating a third delegate for a new session bean I took the time to refactor the code. Now there is an abstract class hierarchy for the delegates:
ServiceDelegate
LocalServiceDelegate
RemoteServiceDelegate
Those declare the configuration property accessors and the framework for connecting to the bean (catching excceptions mostly). To create a pair of delegates for a new session bean, I create the interface from the generated local interface and create two classes: Local<bean>Delegate and Remote<bean>Delegate. Each extends the appropriate base class and implements the bean's business interface. All they need is one method to connect to the bean and then the actual business methods that are cut-n-paste as they all look the same.
The nice thing is that I can swap out the remote or local delegate with no chnanges to the client. Since I'm using DTOs to pass all data, there are no local/remote artifacts in the delegates themselves. I'm quite sure I could create a template for XDoclet to generate the delegates, too. Maybe that's next week.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Business Interface Pattern
 
Similar Threads
HFEJB common EJBObject SessionBean interface
HFEJB common EJBObject SessionBean interface
HF EJB, question about page 86
SessionBean exceptions
Throwing exception in EJB