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

Sun Microsystems Inc.

Session Bean Component Contract

Enterprise JavaBeans 2.0, Public Draft

The responsibilities of the bean provider

The following diagram illustrates the sequence for a container removing an instance from the method-ready pool.

Figure 16 OID for a Container Removing an Instance of a STATELESS Session bean from ready pool

container-provided classes

EJB

EJB

container session

synchro-

instance transaction

Home

Object

context

nization

service

 

 

 

 

 

ejbRemove()

6.10 The responsibilities of the bean provider

This section describes the responsibilities of session bean provider to ensure that a session bean can be deployed in any EJB Container.

6.10.1 Classes and interfaces

The session bean provider is responsible for providing the following class files:

Session bean class.

Session bean’s remote interface.

Session bean’s home interface.

6.10.2 Session bean class

The following are the requirements for session bean class:

The class must implement, directly or indirectly, the javax.ejb.SessionBean interface.

5/31/00

82

Sun Microsystems Inc

The responsibilities of the bean provider

Enterprise JavaBeans 2.0, Public Draft

Session Bean Component Contract

The class must be defined as public, must not be final, and must not be abstract.

The class must have a public constructor that takes no parameters. The Container uses this constructor to create instances of the session bean class.

The class must not define the finalize() method.

The class may, but is not required to, implement the session bean’s remote interface[4].

The class must implement the business methods and the ejbCreate methods.

If the class is a stateful session bean, it may optionally implement the javax.ejb.SessionSynchronization interface.

The session bean class may have superclasses and/or superinterfaces. If the session bean has superclasses, then the business methods, the ejbCreate<METHOD> methods, the methods of the SessionBean interface, and the methods of the optional SessionSynchronization interface may be defined in the session bean class, or in any of its superclasses.

The session bean class is allowed to implement other methods (for example helper methods invoked internally by the business methods) in addition to the methods required by the EJB specification.

6.10.3 ejbCreate<METHOD> methods

The session bean class must define one or more ejbCreate<METHOD>(...) methods whose signatures must follow these rules:

The method name must have ejbCreate as its prefix.

The method must be declared as public.

The method must not be declared as final or static.

The return type must be void.

The method arguments must be legal types for RMI/IIOP.

The throws clause may define arbitrary application exceptions, possibly including the javax.ejb.CreateException.

Compatibility Note: EJB 1.0 allowed the ejbCreate method to throw the java.rmi.RemoteException to indicate a non-application exception. This practice was deprecated in EJB 1.1—an EJB 1.1 or EJB 2.0 compliant enterprise bean should throw the javax.ejb.EJBException or another RuntimeException to indicate non-application exceptions to the Container (see Section 17.2.2).

[4]If the session bean class does implement the remote interface, care must be taken to avoid passing of this as a method argument or result. This potential error can be avoided by choosing not to implement the remote interface in the session bean class.

83

5/31/00

Sun Microsystems Inc.

Session Bean Component Contract

Enterprise JavaBeans 2.0, Public Draft

The responsibilities of the bean provider

6.10.4 Business methods

The session bean class may define zero or more business methods whose signatures must follow these rules:

The method names can be arbitrary, but they must not start with “ejb” to avoid conflicts with the callback methods used by the EJB architecture.

The business method must be declared as public.

The method must not be declared as final or static.

The argument and return value types for a method must be legal types for RMI/IIOP.

The throws clause may define arbitrary application exceptions.

Compatibility Note: EJB 1.0 allowed the business methods to throw the java.rmi.RemoteException to indicate a non-application exception. This practice was deprecated in EJB 1.1—an EJB 1.1 or EJB 2.0 compliant enterprise bean should throw the javax.ejb.EJBException or another RuntimeException to indicate non-application exceptions to the Container (see Section 17.2.2).

6.10.5 Session bean’s remote interface

The following are the requirements for the session bean’s remote interface:

The interface must extend the javax.ejb.EJBObject interface.

The methods defined in this interface must follow the rules for RMI/IIOP. This means that their argument and return values must be of valid types for RMI/IIOP, and their throws clauses must include the java.rmi.RemoteException.

The remote interface is allowed to have superinterfaces. Use of interface inheritance is subject to the RMI/IIOP rules for the definition of remote interfaces.

For each method defined in the remote interface, there must be a matching method in the session bean’s class. The matching method must have:

The same name.

The same number and types of arguments, and the same return type.

All the exceptions defined in the throws clause of the matching method of the session bean class must be defined in the throws clause of the method of the remote interface.

6.10.6 Session bean’s home interface

The following are the requirements for the session bean’s home interface:

The interface must extend the javax.ejb.EJBHome interface.

5/31/00

84