O'Reilly logo

Java Extreme Programming Cookbook by Brian M. Coyner, Eric M. Burke

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generating EJB Home and Remote Interfaces

Problem

You need XDoclet to generate the EJB home and remote interfaces each time your bean class changes.

Solution

Mark up your bean implementation class with the necessary XDoclet tags and use XDoclet to generate the home and remote interfaces.

Discussion

Writing EJB home and remote interfaces is a cumbersome task. The remote, home, and bean code must stay in sync or the deployment of the bean fails. Depending on the server, you may or may not receive suitable error messages. Let’s look at an example of what needs to be written if XDoclet is not used.

Example 9-3 shows an example of a hand-coded remote interface. When writing remote interfaces, ensure that each method throws java.rmi.RemoteException. This may not seem like a huge task but the first time you forget to add the exception to the throws clause you will wish you never wrote this interface.

Example 9-3. Hand-coded remote interface

package com.oreilly.javaxp.xdoclet.ejbdoclet.ejb;

import javax.ejb.EJBObject;
import java.rmi.RemoteException;

public interface PaymentProcessing extends EJBObject {

   public boolean makePayment(String accountNumber, double payment) 
           throws RemoteException;
}

Example 9-4 shows an example of a hand-coded home interface. The home interface provides a view into the container for creating, finding, and removing beans. You must ensure that all “create” methods throw javax.ejb.CreateException, that “finder” methods throw javax.ejb.FinderException, and all methods ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required