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

Sun Microsystem Inc

Enterprise JavaBeans Architecture contracts Enterprise JavaBeans v1.1, Final Release

Overview

A client always uses the same API for object creation, lookup, method invocation, and removal, regardless of how an enterprise bean is implemented or what function it provides to the client.

4.2 Enterprise JavaBeans Architecture contracts

This section provides an overview of the Enterprise JavaBeans architecture contracts. The contracts are described in detail in the following chapters of this document.

4.2.1 Client-view contract

This is a contract between a client and a container. The client-view contract provides a uniform development model for applications using enterprise Beans as components. This uniform model enables the use of higher level development tools and allows greater reuse of components.

The enterprise bean client view is remotable—both local and remote programs can access an enterprise bean using the same view of the enterprise bean.

A client of an enterprise bean can be another enterprise bean deployed in the same or different Container. Or it can be an arbitrary Java technology-enabled program, such as an application, applet, or servlet. The client view of an enterprise bean can also be mapped to non-Java client environments, such as CORBA clients that are not written in the Java programming language.

The enterprise Bean Provider and the container provider cooperate to create the enterprise bean’s client view. The client view includes:

Home interface

Remote interface

Object identity

Metadata interface

Handle

The enterprise bean’s home interface defines the methods for the client to create, remove, and find EJB objects of the same type (i.e. they are implemented by the same enterprise bean). The home interface is specified by the Bean Provider; the Container creates a class that implements the home interface. The home interface extends the javax.ejb.EJBHome interface.

A client can locate an enterprise Bean home interface through the standard Java Naming and Directory InterfaceTM (JNDI) API.

31

11/24/99

Sun Microsystems Inc.

Overview

Enterprise JavaBeans v1.1, Final Release Enterprise JavaBeans Architecture contracts

An EJB object is accessible via the enterprise bean’s remote interface. The remote interface defines the business methods callable by the client. The remote interface is specified by the Bean Provider; the Container creates a class that implements the remote interface. The remote interface extends the javax.ejb.EJBObject interface. The javax.ejb.EJBObject interface defines the operations that allow the client to access the EJB object’s identity and create a persistent handle for the EJB object.

Each EJB object lives in a home, and has a unique identity within its home. For session beans, the Container is responsible for generating a new unique identifier for each session object. The identifier is not exposed to the client. However, a client may test if two object references refer to the same session object. For entity beans, the Bean Provider is responsible for supplying a primary key at entity object creation time[1]; the Container uses the primary key to identify the entity object within its home. A client may obtain an entity object’s primary key via the javax.ejb.EJBObject interface. The client may also test if two object references refer to the same entity object.

A client may also obtain the enterprise bean’s metadata interface. The metadata interface is typically used by clients who need to perform dynamic invocation of the enterprise bean. (Dynamic invocation is needed if the classes that provide the enterprise client view were not available at the time the client program was compiled.)

4.2.2 Component contract

This subsection describes the contract between an enterprise Bean and its Container. The main requirements of the contract follow. (This is only a partial list of requirements defined by the specification.)

The requirement for the Bean Provider to implement the business methods in the enterprise bean class. The requirement for the Container provider to delegate the client method invocation to these methods.

The requirement for the Bean Provider to implement the ejbCreate, ejbPostCreate, and ejbRemove methods, and to implement the ejbFind<METHOD> methods if the bean is an entity with bean-managed persistence. The requirement for the Container provider to invoke these methods during an EJB object creation, removal, and lookup.

The requirement for the Bean Provider to define the enterprise bean’s home and remote interfaces. The requirement for the Container Provider to provide classes that implement these interfaces.

For sessions, the requirement for the Bean Provider to implement the Container callbacks

defined in the javax.ejb.SessionBean interface, and optionally the

[1]In special situations, the primary key type can be specified at deployment time (see subsection 9.4.7.3).

11/24/99

32

Sun Microsystem Inc

Enterprise JavaBeans Architecture contracts Enterprise JavaBeans v1.1, Final Release

Overview

javax.ejb.SessionSynchronization interfaces. The requirement for the Container to invoke these callbacks at the appropriate times.

For entities, the requirement for the Bean Provider to implement the Container callbacks defined in the javax.ejb.EntityBean interface. The requirement for the Container to invoke these callbacks at the appropriate times.

The requirement for the Container Provider to implement persistence for entity beans with container-managed persistence.

The requirement for the Container Provider to provide the javax.ejb.SessionContext interface to session bean instances, and the javax.ejb.EntityContext interface to entity bean instances. The context interface allows the instance to obtain information from the container.

The requirement for the Container to provide to the bean instances the JNDI API context that contains the enterprise bean’s environment.

The requirement for the Container to manage transactions, security, and exceptions on behalf of the enterprise bean instances.

The requirement for the Bean Provider to avoid programming practices that would interfere with the Container’s runtime management of the enterprise bean instances.

4.2.3 Ejb-jar file

An ejb-jar file is a standard format used by EJB tools for packaging enterprise Beans with their declarative information. The ejb-jar file is intended to be processed by application assembly and deployment tools.

The ejb-jar file is a contract used both between the Bean Provider and the Application Assembler, and between the Application Assembler and the Deployer.

The ejb-jar file includes:

Java class files for the enterprise Beans and their remote and home interfaces.

An XML deployment descriptor. The deployment descriptor provides both the structural and application assembly information about the enterprise beans in the ejb-jar file. The application assembly information is optional. (Typically, only ejb-jar files with assembled applications include this information.)

4.2.4 Contracts summary

The following figure illustrates the Enterprise JavaBeans contracts.

33

11/24/99