Java Reference
In-Depth Information
This entity bean represents a row in a relational database table with two col-
umns: clientid and state. The
EJB
consists of its
home
interface, its
remote
inter-
face, and the main bean class, which are named
WorkflowHome
,
Workflow
, and
WorkflowBean
, respectively.
The home interface
The following is
Workflow
EJB
's home interface:
package jmxbook.ch14;
import javax.ejb.*;
import java.rmi.*;
import java.util.*;
public interface WorkflowHome extends EJBHome
{
public Workflow create( String clientID ) throws CreateException,
RemoteException;
public Workflow findByPrimaryKey( String clientID )
throws FinderException,
RemoteException;
}
The
EJB
home interface enables clients to look up or create a
WorkflowBean
for
use. The home interface gives you one method for creating a
WorkflowBean
instance and one method for looking up an existing instance. Both methods take
a
String clientID
as an argument. In our scenario, this parameter represents a
unique user ID for this particular workflow process.
The MBean that manages this
EJB
will always use the lookup method rather
than the create method, because the
EJB
has to exist in order to create the MBean.
The remote interface
The following is the remote interface for the
EJB
:
package jmxbook.ch14;
import java.rmi.*;
import javax.ejb.*;
public interface Workflow extends EJBObject
{
public void advanceState() throws RemoteException;
public String getState() throws RemoteException;
public void setState( String state ) throws RemoteException;
}
The
EJB
remote interface declares the methods that
EJB
uses to interact with the
bean. The
advanceState()
method tells the
Workflow
EJB
to move the workflow to
the next step in the overall process, the
getState()
method returns the current