Java Reference
In-Depth Information
D The execute method is next. The generic trigger to the command, this method is
used to fire business logic that will execute a query, fire a message or transaction, or
perform any kind of local or remote activity.
E For this program, we simply set the query, execute it, and retrieve the results into
our vector instance variables. The logic could not be simpler. In chapter 8, we dis-
cuss ways to distribute commands with stateless session EJB s.
Some command patterns tend to combine the initialize and execute meth-
ods into a single execute method. I tend to keep them separated because it
gives me additional flexibility. I can add some validation here to make sure that
my command was set up properly. This validation is especially important when
I am counting on user input to populate my commands.
public String getAuthor(int index)
throws
IndexOutOfBoundsException,
ArrayIndexOutOfBoundsException {
return (String) author.elementAt(index);
}
public String getBoard(int index)
throws
IndexOutOfBoundsException,
ArrayIndexOutOfBoundsException {
return (String) board.elementAt(index);
}
public String getSubject(int index)
throws
IndexOutOfBoundsException,
ArrayIndexOutOfBoundsException {
return (String) subject.elementAt(index);
;
}
public int getSize() {
return author.size();
}
}
These methods are at the heart of the command API . You can think of them as
input and output parameters for an RPC . Before the execute method, a series
of set methods are called. Then, initialize and execute are called. After the
execute method, a series of get methods are called.
I created this class manually, but it could have easily been created from a
wizard. Outstanding characteristics are the generic interface and simplicity,
which makes them easily adapted to development tools. The standard design
Search WWH ::




Custom Search