background image

The Business Interface

<< Session Bean Examples | Session Bean Class >>
<< Session Bean Examples | Session Bean Class >>

The Business Interface

The Business Interface
The Cart business interface is a plain Java interface that defines all the business methods
implemented in the bean class. If the bean class implements a single interface, that interface is
assumed to the business interface. The business interface is a local interface unless it is
annotated with the javax.ejb.Remote annotation; the javax.ejb.Local annotation is
optional in this case.
The bean class may implement more than one interface. If the bean class implements more than
one interface, either the business interfaces must be explicitly annotated either @Local or
@Remote
, or the business interfaces must be specified by decorating the bean class with @Local
or @Remote. However, the following interfaces are excluded when determining if the bean class
implements more than one interface:
java.io.Serializable
java.io.Externalizable
Any of the interfaces defined by the javax.ejb package
The source code for the Cart business interface follows:
package com.sun.tutorial.javaee.ejb;
import java.util.List;
import javax.ejb.Remote;
@Remote
public interface Cart {
public void initialize(String person) throws BookException;
public void initialize(String person, String id)
throws BookException;
public void addBook(String title);
public void removeBook(String title) throws BookException;
public List<String> getContents();
public void remove();
}
Session Bean Class
The session bean class for this example is called CartBean. Like any stateful session bean, the
CartBean
class must meet these requirements:
The class is annotated @Stateful.
The class implements the business methods defined in the business interface.
The cart Example
The Java EE 5 Tutorial · September 2007
658