Java Reference
In-Depth Information
B This is the class for the implementation of our EJB . We have two major
requirements:
Satisfy the EntityBean interface . The compiler will enforce this rule.
Satisfy the interface of the remote interface . This will be enforced by the
EJB extensions.
C This adds a discussion to a board. This method satisfies the namesake in the
remote interface. Note that the method signatures match exactly. This is a require-
ment, and is enforced by the EJB environment.
D Because we're satisfying an interface, all of the methods must be present, even if we
don't use them.
E When our bean is added to the container, we'd like to be able to read all of the dis-
cussions in a board. We use discussionHome 's interface to find all of the discus-
sions in the board, and then we use the returned enumeration to populate our
board. Likewise, we'll remove them when we remove the board EJB from the
container.
F All of our attributes are wrapped with accessor methods. This practice makes it
easier for us to provide remote interfaces and to consistently wrap services around
the elements of our interface.
G This method finds a given discussion. Here, we simply scan the collection for the
discussion that we want. No database access is required, because the container is
managing that complexity for us.
H We need the discussionHome 's interfaces to get the discussions related to a board.
Since a home object is a named resource, we'll get a naming context and use it to
find our discussionHome object. This type of method is called a finder .
I This method removes a discussion from the board.
Bean class for Discussion
Most of the code for the Discussion class is the same. Here are the interesting
methods:
public int addPost(String author, java.util.Date date, String subject,
String text) throws RemoteException, CreateException {
int nextID = 0;
for (int i = 0; i < posts.size(); i++) {
Post post = (Post)posts.elementAt(i);
int postID = post.getPostID();
nextID = Math.max(nextID, postID+1);
}
Search WWH ::




Custom Search