Show TOC Start of Content Area

Background documentation Enterprise Bean Structure  Locate the document in its SAP Library structure

A typical session or entity enterprise bean consists of an enterprise bean class file, component and home interfaces, and deployment descriptor(s). It may also contain several helper classes.

Message-driven beans do not have component and home interfaces. Message-driven beans are assigned to a JMS Destination to receive the messages, which are sent to this Destination. Their instances, if not involved in a client session, are all identical to the client.

Component Interfaces

The session or entity bean’s component interface contains the business methods that are accessed by the clients. A bean can have a remote or a local component interface, or both – that is, one enterprise bean can provide both a remote and a local view to the clients. Local interfaces enable session and entity beans to be accessed by other enterprise beans that are running on the same server process. Thus, EJB applications avoid the overhead from remote method invocations.

The remote component interface is implemented by the J2EE Engine EJB Container in a generated class called EJBObject. The bean’s remote interface extends the javax.ejb.EJBObject interface, the subinterface of the java.rmi.Remote interface. The EJB Container also generates the client’s stubs and the server-side proxy objects and thus makes them accessible for remote clients.

The local component interface is implemented by the J2EE Engine EJB Container in a generated class called EJBLocalObject. The bean’s local interface extends the javax.ejb.EJBLocalObject interface.

Home Interfaces

The bean’s home interface serves as a factory for the bean’s EJBObject or EJBLocalObject and is accessed through JNDI. Session and entity beans can have home or local home interface. The home interface extends the javax.ejb.EJBHome interface or the javax.ejb.EJBLocalHome interface.

The client obtains a reference to the home or local home interface using JNDI, then calls its create() method to get a reference to an object that implements the component interface. The implementation of the home interface is handled by the J2EE Engine EJB Container. The home or local home interfaces also define the methods, which clients use to remove and find EJB objects. Entity beans additionally can define some business methods in their home or local home interfaces.

Enterprise Bean Class

The bean class implements the corresponding bean interface (session beans implement javax.ejb.SessionBean interface, entity beans implement javax.ejb.EntityBean interface) and the business methods declared in the component interface. The bean class should implement the create() methods declared in the bean’s home or local home interface in its ejbCreate() methods. The ejbCreate() methods should have the same signature as the corresponding create() methods. When the container generates an implementation of the home or local home interface, it calls the bean’s ejbCreate() method for each corresponding create() method in the home or local home interface. The same applies to the bean’s remove() and ejbRemove() methods and the bean’s find methods.

The J2EE Engine EJB Container provides the client’s access to the business methods implemented in the bean’s class.

Deployment Descriptors

Deployment descriptors are XML files containing metadata that describes enterprise bean components. They contain two basic types of information. The first describes the enterprise beans’ structure and the second describe how the enterprise beans are composed in the application.

As the information provided by the J2EE standard deployment descriptors may not be sufficient for the EJB application to work properly, the J2EE Engine supports additional XML descriptors. They provide either additional information for tuning the application or J2EE Engine-specific properties.

Enterprise Bean Deployment Descriptors

Deployment Descriptor

Functions

ejb-jar.xml

Defined by the Enterprise JavaBeans™ Specification.

Describes all enterprise beans in the EJB JAR file and their specifics.

ejb-j2ee-engine.xml

A J2EE Engine-specific XML.

Describes additional information about session and entity beans, but is required if the EJB JAR file contains message-driven beans.

persistent.xml

A J2EE Engine-specific XML.

Describes the database mappings of container-managed entity beans.

application.xml

Defined by the J2EE™ Specification.

In terms of enterprise beans defines only the URI to the ejb-jar.xml in the application.

application-j2ee-engine.xml

A J2EE Engine-specific XML.

In terms of enterprise beans defines only whether failover is enabled for the entire application and respectively for the enterprise beans in the application.

 

Enterprise beans are assembled in an application. Several beans are packed in a JAR file and one or more JAR files are packed in an EAR file, which is the application archive. Both JAR and EAR files must contain a META-INFdirectory, in which the deployment descriptors are located. The ejb-jar.xml, ejb-j2ee-engine.xml, and persistent.xml are located in the META-INFdirectory of the JAR file and describe the beans archived in that JAR file. The application.xml and application-j2ee-engine.xml are located in the META-INFdirectory of the EAR file and contain meta-information concerning the whole J2EE application.

 

End of Content Area