Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Enterprise JavaBeans™ Specification, Version 2.0 - Sun Microsystems.pdf
Скачиваний:
14
Добавлен:
24.05.2014
Размер:
2.71 Mб
Скачать

Sun Microsystems Inc

Overview

Enterprise JavaBeans 2.0, Public Draft

Example Session Scenario

Chapter 7 Example Session Scenario

This chapter describes an example development and deployment scenario of a session bean. We use the scenario to explain the responsibilities of the bean provider and those of the container provider.

The classes generated by the container provider’s tools in this scenario should be considered illustrative rather than prescriptive. Container providers are free to implement the contract between a session bean and its container in a different way, provided that it achieves an equivalent effect (from the perspectives of the bean provider and the client-side programmer).

7.1 Overview

Wombat Inc. has developed the CartBean session Bean. The CartBean is deployed in a container provided by the Acme Corporation.

7.2 Inheritance relationship

An example of the inheritance relationship between the interfaces and classes is illustrated in the following diagram:

89

5/31/00

Sun Microsystems Inc.

Example Session Scenario

Enterprise JavaBeans 2.0, Public Draft

Inheritance relationship

Figure 17 Example of Inheritance Relationships Between EJB Classes

java.rmi.Remote

java.io.Serializable

JDK

EJBMetaData

EnterpriseBean

Enterprise

JavaBeans

 

EJBObject

 

EJBHome

 

 

 

SessionBean

 

 

enterprise bean

Cart

provider

(Wombat Inc.)

CartHome

CartBean

 

 

AcmeRemote

container

AcmeMetaData

AcmeHome

AcmeBean

provider

(Acme)

produced by

Acme tools

AcmeCartHome AcmeRemoteCart

AcmeCartMetaData

AcmeCartBean

extends or implements interface

extends implementation, code generation, or delegation

Java interface

Java class

5/31/00

90

Sun Microsystems Inc

Inheritance relationship

Enterprise JavaBeans 2.0, Public Draft

Example Session Scenario

7.2.1 What the session Bean provider is responsible for

Wombat Inc. is responsible for providing the following:

Define the session Bean’s remote interface (Cart). The remote interface defines the business methods callable by a client. The remote interface must extend the javax.ejb.EJBObject interface, and follow the standard rules for a RMI-IIOP remote interface. The remote interface must be defined as public.

Write the business logic in the session Bean class (CartBean). The enterprise Bean class may, but is not required to, implement the enterprise Bean’s remote interface (Cart). The enterprise Bean must implement the javax.ejb.SessionBean interface, and define the ejbCreate<METHOD>(...) methods invoked at an EJB object creation.

Define a home interface (CartHome) for the enterprise Bean. The home interface must be defined as public, extend the javax.ejb.EJBHome interface, and follow the standard rules for RMI-IIOP remote interfaces.

Define a deployment descriptor specifying any declarative metadata that the session Bean provider wishes to pass with the Bean to the next stage of the development/deployment workflow.

7.2.2 Classes supplied by container provider

The following classes are supplied by the container provider Acme Corp:

The AcmeHome class provides the Acme implementation of the javax.ejb.EJBHome methods.

The AcmeRemote class provides the Acme implementation of the javax.ejb.EJBObject methods.

The AcmeBean class provides additional state and methods to allow Acme’s container to manage its session Bean instances. For example, if Acme’s container uses an LRU algorithm, then AcmeBean may include the clock count and methods to use it.

The AcmeMetaData class provides the Acme implementation of the javax.ejb.EJBMetaData methods.

7.2.3 What the container provider is responsible for

The tools provided by Acme Corporation are responsible for the following:

Generate the class (AcmeRemoteCart) that implements the session bean’s remote interface. The tools also generate the classes that implement the communication protocol specific artifacts for the remote interface.

Generate the implementation of the session Bean class suitable for the Acme container (AcmeCartBean). AcmeCartBean includes the business logic from the CartBean class mixed with the services defined in the AcmeBean class. Acme tools can use inheritance, delegation, and code generation to achieve a mix-in of the two classes.

91

5/31/00

Sun Microsystems Inc.

Example Session Scenario

Enterprise JavaBeans 2.0, Public Draft

Inheritance relationship

Generate the class (AcmeCartHome) that implements the session bean’s home interface. The tools also generate the classes that implement the communication protocol specific artifacts for the home interface.

Generate the class (AcmeCartMetaData) that implements the javax.ejb.EJBMetaData interface for the Cart Bean.

Many of the above classes and tools are container-specific (i.e., they reflect the way Acme Corp implemented them). Other container providers may use different mechanisms to produce their runtime classes, and these classes will likely be different from those generated by Acme’s tools.

5/31/00

92