Business delegate pattern: Difference between revisions

Content deleted Content added
m v2.03 - WP:WCW project (Syntaxhighlight tag without correct match)
 
(8 intermediate revisions by 4 users not shown)
Line 1:
'''Business delegate''' is a [[Java Platform, Enterprise Edition|Java EE]] design pattern.
<ref name=":o_cjp">{{Cite web|url = http://www.oracle.com/technetwork/java/businessdelegate-137562.html|title = Core J2EE Patterns – Business Delegate|access-date = |accessdate = 22 June 2016|website = Oracle|publisher = Oracle|last = |first = }}</ref> This pattern is directingdirected totowards reducereducing the [[Coupling (computer programming)|coupling]] in between business services and the connected presentation tier, and to hide the implementation details of services (including lookup and accessibility of [[Enterprise JavaBeans|EJB]] architecture).<ref name=":o_cjp"/><ref name=":stdd">{{Cite book|title = Screening Technical Design Document – Version 2.0|last = |first = |publisher = Indiana state|year = |___location = Indiana, USA|volume = |pages = 7}}</ref> Business delegates acts as an adaptor to invoke business objects from the presentation tier.<ref name=":pjeesp">{{Cite book|title = Pro Java EE Spring Patterns|url = https://archive.org/details/projavaeespringp00kaya|url-access = limited|last = Kayal|first = D.|publisher = Apress|year = 2008|___location = New York|volume = |pages = [https://archive.org/details/projavaeespringp00kaya/page/n182 161]–166}}</ref>
 
==Structure==
Line 9:
 
====Business delegate====
Control and protection are provided through business delegate which can have two types of constructuresstructures, without ID and with ID, where ID is a string version of the reference to a remote object such as EJBHome or EJBObject.<ref name=":o_cjp"/>
 
====Lookup Serviceservice====
Business service is located by lookup service which is used by the business delegate. The implementation details of business service lookup is encapsulated by lookup service.<ref name=":o_cjp"/>
 
====Business Serviceservice====
This a business-tier component, such as an enterprise bean or a JMS component, which provides the required service to the client.<ref name=":o_cjp"/>
 
Line 33:
Resource Delegate:
<syntaxhighlight lang="java">
 
public class ResourceDelegate {
 
// Remote reference for Session Facade
private ResourceSession session;
 
// Class for Session Facade's Home object
private static final Class homeClazz =
corepatterns.apps.psa.ejb.ResourceSessionHome.class;
 
// Default Constructor. Looks up home and connects
// to session by creating a new one
public ResourceDelegate() throws ResourceException {
try {
ResourceSessionHome home = (ResourceSessionHome)
ServiceLocator.getInstance().getHome(
"Resource", homeClazz);
session = home.create();
} catch (ServiceLocatorException ex) {
// Translate Service Locator exception into
// application exception
throw new ResourceException(...);
} catch (CreateException ex) {
// Translate the Session create exception into
// application exception
throw new ResourceException(...);
} catch (RemoteException ex) {
// Translate the Remote exception into
// application exception
throw new ResourceException(...);
}
}
}
 
public BusinessDelegate(String id)
throws ResourceException {
public BusinessDelegate(String id)
super();
throws ResourceException {
super reconnect(id);
reconnect(id);
}
 
public String getID() {
try {
return ServiceLocator.getId(session);
} catch (Exception e) {
// Throw an application exception
}
}
 
public void reconnect(String id)
throws ResourceException {
try {
session = (ResourceSession)
ServiceLocator.getService(id);
} catch (RemoteException ex) {
// Translate the Remote exception into
// application exception
throw new ResourceException(...);
}
}
 
public ResourceTO setCurrentResource(
String resourceId)
throws ResourceException {
try {
return session.setCurrentResource(resourceId);
} catch (RemoteException ex) {
// Translate the service exception into
// application exception
throw new ResourceException(...);
}
}
 
public ResourceTO getResourceDetails()
throws ResourceException {
 
try {
return session.getResourceDetails();
} catch(RemoteException ex) {
// Translate the service exception into
// application exception
throw new ResourceException(...);
}
}
 
public void setResourceDetails(ResourceTO vo)
throws ResourceException {
try {
session.setResourceDetails(vo);
} catch(RemoteException ex) {
throw new ResourceException(...);
}
}
 
public void addNewResource(ResourceTO vo)
throws ResourceException {
try {
session.addResource(vo);
} catch(RemoteException ex) {
throw new ResourceException(...);
}
}
 
// all other proxy method to session bean
...
}
</syntaxhighlight><ref name=":o_cjp"/>
Remote interface for ResourceSession:
<syntaxhighlight lang="java">
 
public class ResourceDelegate {
 
// Remote reference for Session Facade
private ResourceSession session;
 
// Class for Session Facade's Home object
private static final Class homeClazz =
corepatterns.apps.psa.ejb.ResourceSessionHome.class;
 
// Default Constructor. Looks up home and connects
// to session by creating a new one
public ResourceDelegate() throws ResourceException {
try {
ResourceSessionHome home = (ResourceSessionHome)
ServiceLocator.getInstance().getHome(
"Resource", homeClazz);
session = home.create();
} catch(ServiceLocatorException ex) {
// Translate Service Locator exception into
// application exception
throw new ResourceException(...);
} catch(CreateException ex) {
// Translate the Session create exception into
// application exception
throw new ResourceException(...);
} catch(RemoteException ex) {
// Translate the Remote exception into
// application exception
throw new ResourceException(...);
}
}
 
public BusinessDelegate(String id)
throws ResourceException {
super();
reconnect(id);
}
 
public String getID() {
try {
return ServiceLocator.getId(session);
} catch (Exception e) {
// Throw an application exception
}
}
}
 
public void reconnect(String id)
throws ResourceException {
try {
session = (ResourceSession) ServiceLocator.getService(id);
} catch (RemoteException ex) {
ServiceLocator.getService(id);
// Translate the Remote exception into
} catch (RemoteException ex) {
// application exception
// Translate the Remote exception into
throw new ResourceException(...);
// application exception
throw new ResourceException(...);}
}
}
 
public ResourceTO setCurrentResource(
String resourceId)
public ResourceTO setCurrentResource(
throws ResourceException {
String resourceId)
throws ResourceException try {
return session.setCurrentResource(resourceId);
try {
} catch (RemoteException ex) {
return session.setCurrentResource(resourceId);
// Translate the service exception into
} catch (RemoteException ex) {
// application exception
// Translate the service exception into
throw new ResourceException(...);
// application exception
throw new ResourceException(...);}
}
}
 
public ResourceTO getResourceDetails()
throws ResourceException {
 
try {
return session.getResourceDetails();
} catch (RemoteException ex) {
// Translate the service exception into
// application exception
throw new ResourceException(...);
}
}
}
 
public void setResourceDetails(ResourceTO vo)
throws ResourceException {
try {
session.setResourceDetails(vo);
} catch (RemoteException ex) {
throw new ResourceException(...);
}
}
}
 
public void addNewResource(ResourceTO vo)
throws ResourceException {
try {
session.addResource(vo);
} catch (RemoteException ex) {
throw new ResourceException(...);
}
}
}
 
// all other proxy method to session bean
...
}
</syntaxhighlight><ref name=":o_cjp"/>