The enterprise bean class, CheckingAccountBean, implements the EntityBean
interface as well as the CommandTarget interface. The class contains the business
logic for the methods in the remote interface, the necessary life-cycle methods
(ejbActivate, ejbStore, and so on), and the executeCommand declared by the
CommandTarget interface. The executeCommand method is the only command-specific
code in the enterprise bean class. It attempts to run the performExecute method
on the command and throws a CommandException if an error occurs. If the performExecute
method runs successfully, the executeCommand method uses the hasOutputProperties
method to determine if there are output properties that must be returned.
If the command has output properties, the method returns the command object
to the client. The following code example displays the relevant parts of the
CheckingAccountBean class.
...
public class CheckingAccountBean implements EntityBean, CommandTarget {
// Bean variables
...
// Business methods from remote interface
...
// Life-cycle methods for CMP entity beans
...
// Method from the CommandTarget interface
public TargetableCommand executeCommand(TargetableCommand command)
throws RemoteException, CommandException
{
try {
command.performExecute();
}
catch (Exception ex) {
if (ex instanceof RemoteException) {
RemoveException remoteException = (RemoteException)ex;
if (remoteException.detail != null) {
throw new CommandException(remoteException.detail);
}
throw new CommandException(ex);
}
}
if (command.hasOutputProperties()) {
return command;
}
return null;
}
}