Business delegate pattern

Last updated

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]

Contents

Structure

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

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

Business delegate

Control and protection are provided through business delegate which can have two types of structures, 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

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

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

Consequences

Some consequences are as follows:

Concerns

Following concerns can be considered:

Sample code

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:

publicclassResourceDelegate{// Remote reference for Session FacadeprivateResourceSessionsession;// Class for Session Facade's Home objectprivatestaticfinalClasshomeClazz=corepatterns.apps.psa.ejb.ResourceSessionHome.class;// Default Constructor. Looks up home and connects// to session by creating a new onepublicResourceDelegate()throwsResourceException{try{ResourceSessionHomehome=(ResourceSessionHome)ServiceLocator.getInstance().getHome("Resource",homeClazz);session=home.create();}catch(ServiceLocatorExceptionex){// Translate Service Locator exception into// application exceptionthrownewResourceException(...);}catch(CreateExceptionex){// Translate the Session create exception into// application exceptionthrownewResourceException(...);}catch(RemoteExceptionex){// Translate the Remote exception into// application exceptionthrownewResourceException(...);}}publicBusinessDelegate(Stringid)throwsResourceException{super();reconnect(id);}publicStringgetID(){try{returnServiceLocator.getId(session);}catch(Exceptione){// Throw an application exception}}publicvoidreconnect(Stringid)throwsResourceException{try{session=(ResourceSession)ServiceLocator.getService(id);}catch(RemoteExceptionex){// Translate the Remote exception into// application exceptionthrownewResourceException(...);}}publicResourceTOsetCurrentResource(StringresourceId)throwsResourceException{try{returnsession.setCurrentResource(resourceId);}catch(RemoteExceptionex){// Translate the service exception into// application exceptionthrownewResourceException(...);}}publicResourceTOgetResourceDetails()throwsResourceException{try{returnsession.getResourceDetails();}catch(RemoteExceptionex){// Translate the service exception into// application exceptionthrownewResourceException(...);}}publicvoidsetResourceDetails(ResourceTOvo)throwsResourceException{try{session.setResourceDetails(vo);}catch(RemoteExceptionex){thrownewResourceException(...);}}publicvoidaddNewResource(ResourceTOvo)throwsResourceException{try{session.addResource(vo);}catch(RemoteExceptionex){thrownewResourceException(...);}}// all other proxy method to session bean...}

[1]

Remote interface for ResourceSession:

publicclassResourceDelegate{// Remote reference for Session FacadeprivateResourceSessionsession;// Class for Session Facade's Home objectprivatestaticfinalClasshomeClazz=corepatterns.apps.psa.ejb.ResourceSessionHome.class;// Default Constructor. Looks up home and connects// to session by creating a new onepublicResourceDelegate()throwsResourceException{try{ResourceSessionHomehome=(ResourceSessionHome)ServiceLocator.getInstance().getHome("Resource",homeClazz);session=home.create();}catch(ServiceLocatorExceptionex){// Translate Service Locator exception into// application exceptionthrownewResourceException(...);}catch(CreateExceptionex){// Translate the Session create exception into// application exceptionthrownewResourceException(...);}catch(RemoteExceptionex){// Translate the Remote exception into// application exceptionthrownewResourceException(...);}}publicBusinessDelegate(Stringid)throwsResourceException{super();reconnect(id);}publicStringgetID(){try{returnServiceLocator.getId(session);}catch(Exceptione){// Throw an application exception}}publicvoidreconnect(Stringid)throwsResourceException{try{session=(ResourceSession)ServiceLocator.getService(id);}catch(RemoteExceptionex){// Translate the Remote exception into// application exceptionthrownewResourceException(...);}}publicResourceTOsetCurrentResource(StringresourceId)throwsResourceException{try{returnsession.setCurrentResource(resourceId);}catch(RemoteExceptionex){// Translate the service exception into// application exceptionthrownewResourceException(...);}}publicResourceTOgetResourceDetails()throwsResourceException{try{returnsession.getResourceDetails();}catch(RemoteExceptionex){// Translate the service exception into// application exceptionthrownewResourceException(...);}}publicvoidsetResourceDetails(ResourceTOvo)throwsResourceException{try{session.setResourceDetails(vo);}catch(RemoteExceptionex){thrownewResourceException(...);}}publicvoidaddNewResource(ResourceTOvo)throwsResourceException{try{session.addResource(vo);}catch(RemoteExceptionex){thrownewResourceException(...);}}// all other proxy method to session bean...}

[1]

See also

Related Research Articles

Jakarta Enterprise Beans is one of several Java APIs for modular construction of enterprise software. EJB is a server-side software component that encapsulates business logic of an application. An EJB web container provides a runtime environment for web related software components, including computer security, Java servlet lifecycle management, transaction processing, and other web services. The EJB specification is a subset of the Java EE specification.

The Java Remote Method Invocation is a Java API that performs remote method invocation, the object-oriented equivalent of remote procedure calls (RPC), with support for direct transfer of serialized Java classes and distributed garbage-collection.

In object oriented programming, the factory method pattern is a design pattern that uses factory methods to deal with the problem of creating objects without having to specify their exact class. Rather than by calling a constructor, this is done by calling a factory method to create an object. Factory methods can either be specified in an interface and implemented by child classes, or implemented in a base class and optionally overridden by derived classes. It is one of the 23 classic design patterns described in the book Design Patterns and is sub-categorized as a creational pattern.

<span class="mw-page-title-main">Java syntax</span> Set of rules defining correctly structured program

The syntax of Java is the set of rules defining how a Java program is written and interpreted.

<span class="mw-page-title-main">Dependency injection</span> Software programming technique

In software engineering, dependency injection is a programming technique in which an object or function receives other objects or functions that it requires, as opposed to creating them internally. Dependency injection aims to separate the concerns of constructing objects and using them, leading to loosely coupled programs. The pattern ensures that an object or function that wants to use a given service should not have to know how to construct those services. Instead, the receiving 'client' is provided with its dependencies by external code, which it is not aware of. Dependency injection makes implicit dependencies explicit and helps solve the following problems:

The event dispatching thread (EDT) is a background thread used in Java to process events from the Abstract Window Toolkit (AWT) graphical user interface event queue. It is an example of the generic concept of event-driven programming, that is popular in many other contexts than Java, for example, web browsers, or web servers.

A tuple space is an implementation of the associative memory paradigm for parallel/distributed computing. It provides a repository of tuples that can be accessed concurrently. As an illustrative example, consider that there are a group of processors that produce pieces of data and a group of processors that use the data. Producers post their data as tuples in the space, and the consumers then retrieve data from the space that match a certain pattern. This is also known as the blackboard metaphor. Tuple space may be thought as a form of distributed shared memory.

The object pool pattern is a software creational design pattern that uses a set of initialized objects kept ready to use – a "pool" – rather than allocating and destroying them on demand. A client of the pool will request an object from the pool and perform operations on the returned object. When the client has finished, it returns the object to the pool rather than destroying it; this can be done manually or automatically.

Exception handling syntax is the set of keywords and/or structures provided by a computer programming language to allow exception handling, which separates the handling of errors that arise during a program's operation from its ordinary processes. Syntax for exception handling varies between programming languages, partly to cover semantic differences but largely to fit into each language's overall syntactic structure. Some languages do not call the relevant concept "exception handling"; others may not have direct facilities for it, but can still provide means to implement it.

The anemic domain model is described as a programming anti-pattern where the domain objects contain little or no business logic like validations, calculations, rules, and so forth. The business logic is thus baked into the architecture of the program itself, making refactoring and maintenance more difficult and time-consuming.

Jakarta Mail is a Jakarta EE API used to send and receive email via SMTP, POP3 and IMAP. Jakarta Mail is built into the Jakarta EE platform, but also provides an optional package for use in Java SE.

The Simple API for Grid Applications (SAGA) is a family of related standards specified by the Open Grid Forum to define an application programming interface (API) for common distributed computing functionality.

This article describes the syntax of the C# programming language. The features described are compatible with .NET Framework and Mono.

The front controller software design pattern is listed in several pattern catalogs and is related to the design of web applications. It is "a controller that handles all requests for a website," which is a useful structure for web application developers to achieve flexibility and reuse without code redundancy.

Java Database Connectivity (JDBC) is an application programming interface (API) for the Java programming language which defines how a client may access a database. It is a Java-based data access technology used for Java database connectivity. It is part of the Java Standard Edition platform, from Oracle Corporation. It provides methods to query and update data in a database, and is oriented toward relational databases. A JDBC-to-ODBC bridge enables connections to any ODBC-accessible data source in the Java virtual machine (JVM) host environment.

Mockito is an open source testing framework for Java released under the MIT License. The framework allows the creation of test double objects in automated unit tests for the purpose of test-driven development (TDD) or behavior-driven development (BDD).

Hector is a high-level client API for Apache Cassandra. Named after Hector, a warrior of Troy in Greek mythology, it is a substitute for the Cassandra Java Client, or Thrift, that is encapsulated by Hector. It also has Maven repository access.

<span class="mw-page-title-main">Java Excel API</span>

Java Excel API allows users to read, write, create, and modify sheets in an Excel (.xls) workbook at runtime. It doesn't support .xlsx format.

Composite entity is a Java EE Software design pattern and it is used to model, represent, and manage a set of interrelated persistent objects rather than representing them as individual fine-grained entity beans, and also a composite entity bean represents a graph of objects.

Castor is a data binding framework for Java with some features like Java to Java-to-XML binding, Java-to-SQL persistence, paths between Java objects, XML documents, relational tables, etc. Castor is one of the oldest data binding projects.

References

  1. 1 2 3 4 5 6 7 8 9 "Core J2EE Patterns – Business Delegate". Oracle. Oracle. Retrieved 22 June 2016.
  2. Screening Technical Design Document – Version 2.0. Indiana, USA: Indiana state. p. 7.
  3. 1 2 3 Kayal, D. (2008). Pro Java EE Spring Patterns . New York: Apress. pp.  161–166.