Java Reference
In-Depth Information
layer is to decouple the presentation tier from the business tier. This thin layer is com-
prised of business delegates.
As you saw in Listing 4-2, the business delegate is a POJO client-side proxy for the
business tier. It uses the service locator to access the EJB objects. With the Spring Frame-
work, the service locator works transparently to the business delegate. The EJB objects
looked up by the service locator are injected in the business delegate by the Spring IOC
container. This EJB object is used to delegate the business logic invocation. So, a business
delegate knows how to work with a remoting API such as an EJB. The business delegate
also handles exceptions that are raised during EJB method invocation. It will generally
convert these exceptions into an application-specific runtime exception.
Another critical responsibility of a business delegate is to provide a consistent API for
the page controllers. To achieve this goal, it will apply the object design best practice of
program to interface (P2I). Listing 10-12 shows the business delegate interface.
As shown in Listing 4-12, the business delegate replicates the same methods as the
actual remote business object.
Listing 4-12. UnderwritingBusinessDelegate.java
public interface UnderwritingBusinessDelegate {
public void underwriteNewPolicy(String productCd,String name,int age);
}
Listing 4-13 shows the business delegate implementation class. The business dele-
gate intercepts any exceptions raised by the distributed business objects and transforms
them into RuntimeException because in most cases it is not possible to recover from them.
Listing 4-13. UnderwritingBusinessDelegateImpl.java
public class UnderwritingBusinessDelegateImpl
implements UnderwritingBusinessDelegate{
private UnderwritingRemoteHome uwrRemoteHome;
public UnderwritingRemoteHome getUwrRemoteHome() {
return uwrRemoteHome;
}
public void setUwrRemoteHome(UnderwritingRemoteHome uwrRemoteHome) {
this.uwrRemoteHome = uwrRemoteHome;
}
public void underwriteNewPolicy(String productCd, String name, int age) {
try {
UnderwritingRemote bean = this.uwrRemoteHome.create();
bean.underwriteNewPolicy(productCd, name, age);
 
Search WWH ::




Custom Search