Introduction to Enterprise JavaBeans

WebObjects provides all the tools you need to develop and deploy enterprise applications. However, WebObjects is not the only technology available. Other companies provide tools that accomplish the same task, albeit using different methods and requiring specialized deployment environments. Therefore, it’s difficult for a WebObjects application to talk to an application developed and deployed under a different environment. J2EE and EJB bridge the schism between environments from different vendors.

J2EE standardizes the way Web applications communicate with the resources they need to operate. Akin to JDBC, the goal of J2EE is to provide an infrastructure that applications from different developers can utilize to get their work done.

This chapter contains the following sections:

Enterprise JavaBeans

Enterprise JavaBeans is an important part of J2EE. It provides an environment in which components from several manufacturers can be assembled into a working application. The application assembler, with deep knowledge of the requirements of the business, can choose the component that best matches the task at hand. For instance, they could use transaction-processing beans from one company; customer, order, and product beans from another company; and shipping beans from a third company. They would then end up with an application capable of accepting orders, charging the customer, and process shipments without having to write code.

Enterprise beans are specialized components that can encapsulate session information, workflow, and persistent data. A bean client is an application that uses enterprise beans to access database data or an enterprise bean that relies on the functionality provided by another enterprise bean. An enterprise bean has three parts:

The container is a conceptual entity that mediates between enterprise-bean instances and client applications. Clients never access bean instances directly. Instead, they interact with proxies provided by the container. This allows the bean container to perform its duties in the most efficient way. The client doesn’t have to know how the container implements its functions; all it needs to know is how to talk to the container.

In addition, beans have a deployment descriptor. This is an XML file that gives the container information about each bean and data-source connection details, among many other items.

There are two major types of enterprise beans: session beans and entity beans.

An enterprise-bean developer can focus on the high-level business logic needed to implement the services that a bean provides instead of on low-level system or data- store calls (those functions can be left to the container).

One of the most important functions of the container is transaction management and access control. WebObjects includes the OpenEJB open-source container system. OpenEJB consists of four main components:

Enterprise JavaBeans in WebObjects

You can use WebObjects development tools to develop enterprise beans from scratch or to integrate third-party EJB-based solutions in a WebObjects application. Bean development in WebObjects is divided in two phases: development and deployment.

You develop enterprise beans by writing .java files and deployment descriptor files. Project Builder provides you with templates for these files. You can also obtain the source code or JAR files for enterprise beans from a third party. As an alternative, you can develop data models from which entity-bean source files can be generated. For more information, see Developing an Entity Bean From a Data Model.

You deploy one or more beans by generating a bean framework, which contains the beans’ JAR files and deployment descriptor files, and placing it somewhere in a development computer’s file system; for example, in /Library/Frameworks. After you deploy a bean framework, it’s available to be integrated in client applications or other enterprise beans for their use.

Client applications can be developed in two ways: using an internal bean container, or using an external container: