CONTENTS | PREV | NEXT | INDEX J2EE BluePrints



10.5 Implementation

In the implementation of the view, JSP pages rely on JavaBeans components to mirror model data. These components are named ESObjectWebImpl (where ESObject are the e-store objects Inventory, Account, Cart, and Order). As Code Example 10.10 illustrates, ESObjectWebImpl extends ESObjectModel and implements a listener interface so that views can be notified of changes to their corresponding models. For example, when an AccountWebImpl is created, it adds itself to the list of listeners interested in updates to the account model. When an account model changes, the manager of the view objects invokes the performUpdate method on all views that have registered as listeners of the account model. See Section 10.6.8 for further discussion of model-view synchronization.


public class AccountWebImpl extends AccountModel 
				implements ModelUpdateListener {
	private ModelManager mm;
	private Account acctEjb;

	public AccountWebImpl(ModelManager mm) {
		super(null, null, null);
		this.mm = mm;
		mm.addListener(JNDINames.ACCOUNT_EJBHOME, this);
	}

	public void performUpdate() {
			if (acctEjb == null) {
			acctEjb = mm.getAccountEJB();
		}
		try {
			if (acctEjb != null) copy(acctEjb.getDetails());
		} catch (RemoteException re) {
			throw new GeneralFailureException(re);
		}
	}
}
Code Example 10.10 AccountWebImpl

The model is implemented by enterprise beans named ESObject. These beans are supported by data access classes named ESObjectDAO and details classes named ESObjectModel. As described in "Value Objects", a client can retrieve the contents of an enterprise bean with one remote call that returns a details object.

JavaBeans components and details classes share aspects of their implementation (that is, the ESObjectModel classes), because the ESObjectModel classes capture the essential information required to represent e-store business objects in any tier.

The implementation of the catalog does not follow the pattern just described because it implemented in both a Web-centric and EJB-centric fashion. The Web-centric design is used for high performance since the catalog is read-only and the most frequently accessed object in the system. Thus the Web-centric JavaBeans component CatalogWebImpl accesses the data access class CatalogDAO directly instead of calling an enterprise bean.

Since the shopping cart enterprise bean needs access to the catalog and cannot access the Web-tier catalog it uses a catalog enterprise bean. Note that high performance is not as crucial in this case as compared to the earlier case but access to the catalog is still read-only.

The implementation of the catalog functionality is essentially the same in both cases, so both CatalogWebImpl and CatalogEJB extend CatalogImpl which implements the CatalogModel interface.

The relationships between the sample application business objects--view classes in the Web tier, model classes (and their respective helper classes) in the EJB tier, and database tables in the enterprise information system tier--are shown in Figure 10.9.

Figure 10.9 Sample Application Business Objects



CONTENTS | PREV | NEXT | INDEX
Copyright © 2001 Sun Microsystems, Inc. All Rights Reserved.