The largest Interview Solution Library on the web


« Previous | 1 | 2 | 3 | Next »

Enterprise JavaBeans Clients


Introduction

Enterprise JavaBeans clients may be stand-alone applications, servlets, applets, or even other enterprise beans. For instance, the HotelClerk session bean shown earlier was a client of the Room entity beans. All clients use the server bean's home interface to obtain references to the server bean. This reference has the server bean's remote interface datatype, therefore the client interacts with the server bean solely through the methods defined in the remote interface.

The remote interface defines the business methods, such as accessor and mutator methods for changing a customer's name, or business methods that perform tasks like using the HotelClerk bean to reserve a room at a hotel. Below is an example of how a Customer bean might be accessed from a client application. In this case the home interface is CustomerHome and the remote interface is Customer.

CustomerHome home;
Object ref;
// Obtain a reference to the CustomerHome
ref = jndiContext.lookup("java:comp/env/ejb/Customer");
// Cast object returned by the JNDI lookup to the
// appropriate datatype
home = PortableRemoteObject.narrow(ref, CustomerHome.class);
// Use the home interface to create a
// new instance of the Customer bean.
Customer customer = home.create(customerID);
// Use a business method on the Customer.
customer.setName(someName);

A client first obtains a reference to the home interface by using JNDI ENC to look up the server beans. In EJB 1.1, Java RMI-IIOP is the specified programming model. As a consequence, all CORBA references types must be supported. CORBA references cannot be cast using Java native casting. Instead the PortableRemoteObject.narrow() method must be used to explicitly narrow a reference from one type to its subtype. Because JNDI always returns an Object type, all bean references should be explicitly narrowed to support portability between containers.

After the home interface is obtained, the client uses the methods defined on the home interface to create, find, or remove the server bean. Invoking one of the create() methods on the home interface returns to the client a remote reference to the server bean, which the client uses to perform its job.
« Previous | 1 | 2 | 3 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com