Java Reference
In-Depth Information
Listing 14.2
UserInfo.java
package jmxbook.ch14;
import java.rmi.*;
import javax.ejb.*;
public interface UserInfo extends EJBObject
{
public int getNumberOfLogins() throws RemoteException;
public boolean login() throws RemoteException;
public void logout() throws RemoteException;
public void setLoginAllowed( boolean isAllowed )
throws RemoteException;
}
The methods of a remote interface are used to manipulate the data represented
by the entity bean. Every EJB remote interface declares the methods that will
implement business logic. This remote interface declares a login() method and a
logout() method that are invoked when the user performs the applicable action.
The setLoginAllowed() method sets the login permissions for the user. For this
example, the only permission for a user is whether the user can successfully log
in. Essentially, this method disables or enables the user's account.
By writing the two interfaces for your EJB , you have declared the methods for
creating, finding, and manipulating the EJB .
UserInfoBean code
Listing 14.3 shows the entity bean implementation. This class must implement
all the methods necessary to adhere to the EJB specification, as well as the meth-
ods necessary for the business logic declared in the remote interface. Typically,
the entity bean implementation would provide the persistence mechanism; but
in this case, you will store the data in the object and rely on the container activa-
tion to maintain it in memory.
Listing 14.3
UserInfoBean.java
package jmxbook.ch14;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.ejb.*;
import javax.naming.*;
import javax.management.*;
import javax.sql.*;
Search WWH ::




Custom Search