eWebProgrammer eweb  

EJB Session Beans  «Prev  Next»
Lesson 3The home object and the home interface
ObjectiveDescribe the Home Object and the 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 .
Metadata: The information about an object: its methods, parameters, return types, etc.
Remote objects
A remote object 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.
Remote object: An object that provides a service through its methods and is located on another host on the network.
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 . In Java terms, the remote reference is the reference to the stub instance in the JVM . This is illustrated in the following diagram.
Remote reference: The reference to an object, usually the stub, that knows where, and how to communicate with, a remote object.
JVM: The Java Virtual Machine, a software implementation of a portable environment, that executes Java programs.
Remote reference
Remote reference
  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.