Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Structure  



1.1  Components  



1.1.1  Business delegate  





1.1.2  Lookup service  





1.1.3  Business service  









2 Consequences  





3 Concerns  





4 Sample code  





5 See also  





6 References  














Business delegate pattern






Deutsch
Magyar
Português
 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 


Business delegate is a Java EE design pattern. [1] This pattern is directed towards reducing the coupling in between business services and the connected presentation tier, and to hide the implementation details of services (including lookup and accessibility of EJB architecture).[1][2] Business delegates acts as an adaptor to invoke business objects from the presentation tier.[3]

Structure[edit]

Requests to access underlying business services are sent from clients, and lookup services are used by business delegates to locate the business service components.[1]

Components[edit]

Basic components are Business delegate, Lookup service and business service.

Business delegate[edit]

Control and protection are provided through business delegate which can have two types of constructures, without ID and with ID, where ID is a string version of the reference to a remote object such as EJBHome or EJBObject.[1]

Lookup service[edit]

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.[1]

Business service[edit]

This a business-tier component, such as an enterprise bean or a JMS component, which provides the required service to the client.[1]

Consequences[edit]

Some consequences are as follows:

Concerns[edit]

Following concerns can be considered:

Sample code[edit]

A sample code for a Professional Services Application (PSA), where a Web-tier client needs to access a session bean that implements the session facade pattern, is provided below.

Resource Delegate:

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) {
            // 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
    ...
}

[1]

Remote interface for ResourceSession:

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) {
            // 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
    ...
}

[1]

See also[edit]

References[edit]

  1. ^ a b c d e f g h i "Core J2EE Patterns – Business Delegate". Oracle. Oracle. Retrieved 22 June 2016.
  • ^ Screening Technical Design Document – Version 2.0. Indiana, USA: Indiana state. p. 7.
  • ^ a b c Kayal, D. (2008). Pro Java EE Spring Patterns. New York: Apress. pp. 161–166.

  • Retrieved from "https://en.wikipedia.org/w/index.php?title=Business_delegate_pattern&oldid=1213673566"

    Category: 
    Software design patterns
    Hidden category: 
    Articles with example Java code
     



    This page was last edited on 14 March 2024, at 13:07 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki