JavaBeans

We will again use excellent articles from JavaWorld to introduce JavaBeans. We will look at the first part, while the second part is left for the students as an excercise.
  1. Building a bevy of beans 1
  2. Building a bevy of beans 2
The following link gets yoou to a description of Java Reflection. It is used heavily for beans introspection. It can be used whenever you need to discover a behavior of a class, which was not known at the compilation time.

Exterprise JavaBeans

The following link points to a good introduction to Enterprise JavaBeans published in the online version of Java Report: An application that wants to use JavaBeans needs a support from naming services to locate interfaces that allow for bean creation and location on distributed servers. The following is another article from Java Report describing JNDI:

Exterprise JavaBeans Specifications (excerpts)

The following is a part of specifications for Enterprise JavaBeans from Sun.

Goals

Overall goals for the Enterprise JavaBeans (EJB) architecture:

Goals for Release 1.0

Focus on the following aspects:

Session and entity objects

Enterprise JavaBeans 1.0 defines two types of enterprise beans: The support for session objects is mandatory for an EJB 1.0 compliant container. The
support for entity objects is optional for an EJB 1.0 compliant container, but it will be-come
mandatory for EJB 2.0 compliant containers.

Session objects

A typical session object has the following characteristics: A typical EJB server and container provide a scalable runtime environment to execute a large number of session objects concurrently.

Entity objects

A typical entity object has the following characteristics: A typical EJB server and container provide a scalable runtime environment for a large number of concurrently active entity objects.
 
 

Roles and scenarios

Roles

The Enterprise JavaBeans architecture defines six distinct roles in the application de-velopment and deployment workflow. Each role may be performed by a different party. Enterprise JavaBeans specifies the contracts that ensure that the product of each role is compatible with the product of the other roles. In some scenarios, a single party may perform several roles. For example, the container provider and the EJB server provider may be the same vendor. Or a single programmer may perform the role of the enterprise bean provider and the role of the application assembler.

Enterprise bean provider

An enterprise bean provider is typically an application domain expert. An enterprise bean provider develops reusable components called enterprise beans. An enterprise bean implements a business task, or a business entity.

An enterprise bean provider is not an expert at system-level programming. Therefore, an enterprise bean provider usually does not program transactions, concurrency, secu-rity, distribution and other services into the enterprise beans. An enterprise bean pro-vider relies on an EJB container provider for these services.

The output of an enterprise bean provider is an ejb-jar file that contains enterprise beans. Each bean includes its Java classes, its remote and home interfaces, its deploy-ment descriptor, and its environment properties. The enterprise beans must conform to the Enterprise JavaBeans component contract to ensure that they can be installed into any compliant EJB container.

Application assembler

An application assembler is a domain expert who composes applications that use enter-prise beans. The application assembler works with the enterprise bean’s client view contract. Although the assembler must be familiar with the functionality provided by the enterprise beans’ remote and home interfaces, he or she does not have to have any knowledge of the enterprise beans’ implementation.

The output of the application assembler can be new enterprise beans, or applications that are not enterprise beans (for example, servlets, applets, or scripts). The assembler may also write a GUI for the applications.

The application assembly can be done before or after the deployment of the enterprise beans into an operational environment.

Deployer

A deployer is an expert at a specific operational environment, and is responsible for the deployment of enterprise beans and their containers. A deployer typically uses tools provided by the container provider to adapt enterprise beans to a specific operational environment.

For example, a deployer is responsible for mapping the security roles assumed by the enterprise beans to those required by the organization that will be using the enterprise beans. A deployer typically reads the attribute settings in the enterprise beans’ deploy-ment descriptors and modifies the values of the enterprise beans’ environment proper-ties. In some cases, a qualified deployer may customize the business logic of the enterprise beans at their deployment. Such a deployer would typically use the container tools to write relatively simple application code that wraps the enterprise bean’s business methods.

EJB server provider

An EJB server provider is a specialist in the area of distributed transaction manage-ment, distributed objects, and other lower-level system-level services. A typical EJB server provider is an OS vendor, middleware vendor, or database vendor. Typically, the EJB server provider will provide a container that implements the EJB session container[4.2.2] contract, and may also provide an entity container[4.2.2] for one or more data sources supported on the EJB server. An EJB server provider will typically publish its lower-level interfaces to allow third parties to develop containers. These interfaces are not currently specified by Enterprise JavaBeans and are vendor specific. A later release of Enterprise JavaBeans may standardize the interfaces between a container and an EJB server.

EJB container provider

The expertise of a container provider is system-level programming, possibly combined with some application-domain expertise. The focus of a container provider is on the de-velopment of a scalable, secure, transaction-enabled container system. The container provider insulates the enterprise bean from the specifics of an underlying EJB server by providing a simple, standard API between the enterprise bean and the container (this API is the Enterprise JavaBeans component contract). For enterprise entity beans with container-managed persistence, the entity container is responsible for persistence of the entity beans installed in the container. The container provider’s tools are used to generate code that moves data between the enterprise bean’s instance variables, and a database or an existing application. The container provider may be an expert in the area of providing access to enterprise’s existing data sources or application systems (such as CICS or SAP). A container provider is responsible for providing support for versioning of enterprise beans. For example, the container provider should allow enterprise bean classes to be upgraded without invalidating existing clients or losing existing enterprise bean ob-jects.

The container provider typically provides tools that allow the system administrator to monitor and manage the container and the beans running in the container at runtime. Enterprise JavaBeans defines the component contract that must be supported by every compliant EJB container. Enterprise JavaBeans allows container vendors to develop specialized containers that extend this contract. Examples of specialized containers in-clude a container that supports an application-domain specific framework, a container that bridges the EJB environment with an existing application system (such a container allows modeling of the existing applications as enterprise beans), a container that im-plements an Object/Relational mapping, or container that is built on top of an object-oriented database system.

System administrator

The role of a system administrator is to oversee the well-being of a running system. The system administrator typically uses runtime monitoring and management tools provid-ed by the EJB server and container providers to accomplish this task.

Scenario 1: Development, deployment, assembly

Wombat Inc. is an enterprise bean provider that specializes in the development of soft-ware components for the banking sector. Wombat Inc. has developed the AccountBean and TellerBean enterprise beans, and packages them in an ejb-jar file.

Wombat sells the enterprise beans to banks that may use containers and EJB servers from multiple vendors. One of the banks uses a container from the Acme Corporation. Acme’s tools that are part of Acme’s container product facilitate the deployment of en-terprise beans from any provider, including Wombat Inc. The deployment process re-sults in generating additional classes used internally by the Acme container. The additional classes allow the Acme container to manage enterprise bean objects at runt-ime, as defined by the EJB component contract.

Since the AccountBean and TellerBean enterprise beans by themselves are not a com-plete application, the bank MIS department may use Acme’s tools to assemble the Ac-countBean and TellerBean enterprise beans with other enterprise beans (possibly from another vendor) and possibly with some non-EJB existing software, into a complete ap-plication. The MIS department takes on both the EJB deployer and application assem-bler roles.
 

Fundamentals

This chapter defines the scope of the Enterprise JavaBeans specification.

Enterprise beans as components

Enterprise JavaBeans is an architecture for component based distributed computing. Enterprise beans are components of distributed transaction-oriented enterprise applica-tions.

Component characteristics

The essential characteristics of an enterprise bean are:

Flexible component model

The enterprise bean architecture is flexible enough to implement components such as the following: Although the state management protocol defined by the Enterprise JavaBeans architec-ture is simple, it provides an enterprise bean developer great flexibility in managing a bean’s state.

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

Enterprise JavaBeans contracts

This section describes the Enterprise JavaBeans Release 1.0 contracts.

Client’s view contract

This is a contract between a client and a container. The client’s view contract provides a uniform development model for applications using enterprise beans as components. This uniform model enables using higher level development tools, and will allow great-er reuse of components.

Both the enterprise bean provider and the container provider have obligations to fulfill the contract. This contract includes:

A client expects that an enterprise bean object has a unique identifier. The container provider is responsible for generating a unique identifier for each EJB object. For entity enterprise beans (See Subsection 4.3.2), the EJB provider is responsible for supplying a unique primary key that the container embeds into the EJB object’s identifier. A client locates an enterprise bean container through the standard Java Naming and Di-rectory Interface TM (JNDI). Within a container, the primary key is used to identify each EJB object.

An enterprise bean and its container cooperate to implement the create, find, and re-move operations callable by clients.

An enterprise bean provider defines a remote interface that defines the business meth-ods callable by a client. The enterprise bean provider is also responsible for writing the implementation of the business methods in the enterprise bean class. The container is responsible for allowing the clients to invoke an enterprise bean through its associated remote interface. The container delegates the invocation of a business method to its im-plementation in the enterprise bean class.

An enterprise bean provider is responsible for supplying an enterprise bean’s home in-terface. The enterprise bean’s home interface extends the javax.ejb.EJBHome inter-face. A home interface defines zero or more create(...) methods, one for each way to create an EJB object. A home interface for entity beans defines zero or more finder methods, one for each way to lookup an EJB object, or a collection of EJB objects of a particular type.

The enterprise bean provider is responsible for the implementation of the ejbCreate(...) methods in the enterprise bean class, whose signature must match those of the cre-ate(...) methods defined in the bean’s home interface. The container is responsible for delegating a client-invoked create(...) method to the matching ejbCreate(...) method on an enterprise bean instance.

The enterprise entity bean provider is responsible for the implementation of the ejbFindMETHOD(...) methods in the enterprise bean class, whose signature must match those of the findMETHOD(...) finder methods defined in the bean’s home inter-face. The container is responsible for delegating a client-invoked findMETHOD(...) method to the matching ejbFindMETHOD(...) method on an enterprise bean instance.

Component contract

This is a contract between an enterprise bean and its container. This contract includes:

Ejb-jar file

An ejb-jar file is a standard format used by EJB tools for packaging enterprise beans with their declarative deployment information. All EJB tools must support ejb-jar files.

The ejb-jar contract includes:

The following figure illustrates the Enterprise JavaBeans contracts that are defined in Release 1.0.

Note that while the figure illustrates only a remote client running outside of the contain-er, the client-side API is also applicable to clients who themselves are enterprise beans installed in an EJB container.