GeeCON Prague 2014*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Business Delegate in JEE5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Business Delegate in JEE5" Watch "Business Delegate in JEE5" New topic
Author

Business Delegate in JEE5

Sharma Ashutosh
Bartender

Joined: Apr 06, 2001
Posts: 346
I have a very basic question.
My solution will be having this layered architecture(following JEE5)

JSP->Controller->Business Delegate->Session Bean->DAO->entity

I am using JSF at the web tier. Session Beans means stateless and stateful session beans and they are following Service Facade design pattern.

Seperate DAO layer as i didn't wanted to clutter Session Beans with entitymanager.

I am using Business Delegate for two reasons:
1) Exception handling and converting unchecked exceptions appropriately.
2) In case when the device is something else than thin client(web browser)
following Adam's blog and not using any retired patterns

Question
1) Can the Session Beans(Service Facade) be injected directly into Business Delegate? or do i have to have service locator pattern?
2) Is this okay or i am making some real blunder?

Ashutosh Sharma
SCJP 1.2, SCEA 5, Brainbench certified J2EE Developer, Documentum Certified Professional
Blog : http://scea5-passingpart2and3.blogspot.com/
Amit Harsola
Greenhorn

Joined: Dec 02, 2010
Posts: 19
Hi Ashutosh,

Such details are not allowed in this forum. It is against Oracle policy

Regards,
Amit
Anil Chowdary
Ranch Hand

Joined: Jan 20, 2009
Posts: 43
Quite frankly I don't feel that the question violates any policy. Its a general question on how to use patterns. The problem domain is not mentioned anyway, so I don't see any issues.

Ashutosh, Coming to the issue:-
First of all, You need to be sure if you really want to go with a Business delegate for your case. The reason being, after EJB3.0 both delegator and service locator becomes redundant(Until unless your web layer and EJBs are deployed on 2 separate servers). So decide on this one before.
Second, if you decide to go ahead with Delegator, it is recommended to use Service locator to get the EJB.


Regards,
Anil Chowdary K

OCMJEA/SCEA, SCWCD, SCJP
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
A Business Delegate on the Presentation-tier and a Business Delegate on the Business-tier serve different purposes.

1) Can the Session Beans(Service Facade) be injected directly into Business Delegate? or do i have to have service locator pattern?


Yes, a Presentation-tier Business Delegate can and should have a reference to the Session Facade object.

No, you do not have to implement the Service Locator pattern here. I suggest that you do not use Service Locator here.
Sharma Ashutosh
Bartender

Joined: Apr 06, 2001
Posts: 346
Thanks Anil and Jimmy for your answers.
Have you gone thru the book from Adam-Bien(Real World JEE patterns)? Good amount of J2EE(1.4 or prior) patterns has been retired in JEE5 onwards - Business Delegate and Service locator is also retired now.
For all the non managed components(not managed by the application server)-like Business Delegate-we can't rely on DI and inject the Service Facade or Service into them. And that is the reason-we need to use the Service Locator pattern here.

I already mentioned my reasons for using Business Delegate pattern:
1) Exception handling and converting unchecked exceptions appropriately.
2) In case when the device is something else than thin client(web browser).


I asked the same question to Adam Bien via email and he also confirmed this. when we are using non-managed components like Business Delegate-we can't use DI and we have to do lookup via ServiceLocator Design pattern.
Anil Chowdary
Ranch Hand

Joined: Jan 20, 2009
Posts: 43
Ashutosh,

Thats correct, You can't DI components which are not managed. So using service locator is a good option.

Regards,
Anil Chowdary K
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
You could certainly apply Dependecy Injection with Service Locator and a Business Delegate. There is no dependency on something called a
"managed" or "non-managed" aspect.

Aside, object-oriented design patterns are not dependent on, and do not specifiy any technology. They are not dependent upon any particular programming language.

JNDI code directly in the Business Delegate eliminates the need for a Service Locator implementation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Business Delegate in JEE5