Client View of Bean  «Prev  Next»

Lesson 3The home object and the home interface
ObjectiveDescribe the Home Object and the Home Interface.

Describe the Home Object and Home Interface

Skeleton of the home interface

Here is part of the home interface for the Hello bean created by the Hello bean developer:

import javax.ejb.EJBHome;
public interface HelloHome extends EJBHome {

Note that it is an interface, not a class.
The real home object class will be created as part of the deployment process.
The container will instantiate the home object instance when the bean is installed into the container.
The home interface always extends EJBHome for structural reasons.
EJBHome includes methods to access the bean's metadata [1] .

Remote objects

A remote object[2] is an object that has
  1. a stub and
  2. a skeleton
and is accessible over the network.
The location of the object needs to be known before its methods can be called.

Both the skeleton and the stub are uniquely associated with that specific remote object. When a client wishes to communicate with the remote object, it will use its unique stub, often known as a remote reference[3] . In Java terms, the remote reference is the reference to the stub instance in the JVM[4] . This is illustrated in the following diagram.

Client Remote reference communicates with the remote object over the Network.
  1. To access a remote object, the program needs its stub.
  2. To access EJBs, the program needs stubs for the home object and EJBObject.

Data type of the stub

The data type of the stub is unknown to the client. From the proxy pattern, the stub and the entity for which it is a proxy have the same interface.
Thus, if we know the interface of the remote object, we know the interface implemented by the stub. Therefore, considering the HelloHome interface code above, the Java type of the stub to the home object is HelloHome. We can write code as follows:

HelloHome home = (HelloHome) nameService.lookup("hello");

Advice on EJBHome

Examine now the methods of the EJBHome class in the javadoc J2EE API documentation to help you understand the methods inherited by the Home interface. In the next lesson, you will apply the reasoning above to the actual lookup of the home object from the Name Service.
[1]Metadata: The information about an object: its methods, parameters, return types, etc.
[2]Remote object: An object that provides a service through its methods and is located on another host on the network.
[3]Remote reference: The reference to an object, usually the stub, that knows where, and how to communicate with, a remote object.
[4]JVM: The Java Virtual Machine, a software implementation of a portable environment, that executes Java programs.