Realization of the Search NPO Use Case Package


The following subsections describe realization of use cases in the Search NPO package. Please refer to Chapter 1 and Chapter 2 for description of this package.

Search NPO Use Case

In this section, we look into the design and implementation of the Search NPO use case. The search function uses a stateful session bean for incrementally providing the result of the search to the presentation tier. The NPO data is retrieved using the Value List Handler pattern; the rationale for using this pattern is explained in the following discussion.

Discovering Business Interface Methods

From the use case, it is apparent that the presentation tier will be providing a search criteria to the business tier. If we were to use the collection-valued approach for retrieving entity beans, we would get references to a large number of entity beans; entity beans are heavy-weight objects demanding system resources for their construction and access. Since we are doing a read-only operation on the NPO data, it is convenient to access them directly using a DAO pattern [Core] that may use JDBC to access the NPO table data. Most often, the users will prefer some form of paging mechanism to browse through the result; this is convenient from the user perspective and from the perspective of keeping network traffic to a minimum by reducing the amount of data that goes across the network. One approach is to provision the result set with a single call to the database tier and then incrementally supply the results to the client. A design pattern that readily meets our requirement is the Value List Handler pattern [Core]; in this section, we discuss how this pattern is implemented for realizing the Search NPO use case.

We begin by creating a business interface that contains a search function that accepts the search criteria provided by the presentation tier and returns an integer to signal the presentation tier if it found any corresponding data. The following code segment shows the definition of the business method executeSearch on the business interface SearchNPO:

 public interface SearchNPO {     int executeSearch(SearchParameters searchDetails)     throws RemoteException, GCAppException; } 

The ValueListHandler class implements the following ValueListIterator interface. The ValueListIterator defines the methods required for navigating the result set.

 public interface ValueListIterator {     /* Returns the number of items in the collection */     public int getSize()         throws IteratorException, RemoteException;     /* Returns the current element based on the current index of iterator */     public NPOViewDTO getCurrentElement()         throws IteratorException, RemoteException;     /* Returns the requested number of elements occurring before the current position      * of the iterator */     public List getPreviousElements(int count)         throws IteratorException, RemoteException;     /* Returns the requested number elements occurring after the current position      * of the iterator */     public List getNextElements(int count)         throws IteratorException, RemoteException;     /* Repositions the iterator position to the beginning of the result list */     public void resetIndex()         throws IteratorException, RemoteException; } 

The methods described in this interface satisfy the navigational semantics necessary to implement the Search NPO use case. The ValueListHandler class provides a default implementation of ValueListIterator. Please check the accompanying CD-ROM for the complete source code of this class. Figure 7-13 illustrates the usage of the Value List Handler pattern in the context of the client requests.

click to expand
Figure 7-13: Value List Handler Pattern Usage

Implementing the Business Interface

The presentation tier imposes upon the SearchNPO session bean the need to maintain state information; therefore the SearchNPO bean is implemented as a stateful session bean. The SearchNPOBean implements the SearchNPO business interface, which in turn extends the ValueListIterator; the existence of all required methods in the SearchNPOBean will therefore be guaranteed at compile time. For servicing client requests, the SearchNPO session bean instantiates the NPOListHandler class, which is a subclass of ValueListHandler, and delegates navigation-related operations, such as getNextElements and getPreviousElements to NPOListHandler. The implementation of NPOListHandler is specific to accessing the NPO table using the NPODAO object. The NPODAO object uses JDBC for accessing the data. Please check the accompanying CD-ROM for complete source code.

Figure 7-14 shows the class diagram for realizing the Search NPO use case.

click to expand
Figure 7-14: Search NPO class diagram




Practical J2ee Application Architecture
Practical J2EE Application Architecture
ISBN: 0072227117
EAN: 2147483647
Year: 2003
Pages: 111
Authors: Nadir Gulzar

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net