Java Reference
In-Depth Information
java.util.Enumeration e = getPostHome().findAllForDiscussion(
boardName, discussionID);
while ( e.hasMoreElements() ) {
java.lang.Object o = e.nextElement() ;
com.bitterjava.bbs.ejb.Post postEjb = resolvePost(o) ;
com.bitterjava.bbs.Post post = marshallDataObject(postEjb) ;
posts.addElement(post) ;
}
} catch (NullPointerException e) {}
return posts;
}
In this method, we're collecting all of the posts in a single discussion. The
while loop in bold would have been executed right on an interface boundary
in our original design. The original methods that performed the tasks of the
methods in italics were all distributed in our original design.
private com.bitterjava.bbs.Board marshallDataObject(Board boardEjb)
throws RemoteException {
com.bitterjava.bbs.Board board = new com.bitterjava.bbs.Board();
board.setName(boardEjb.getName());
java.util.Vector discussions = new java.util.Vector();
java.util.Collection discussionEjbs = boardEjb.getDiscussions();
java.util.Iterator iter = discussionEjbs.iterator();
while (iter.hasNext()) {
java.lang.Object o = iter.next();
com.bitterjava.bbs.ejb.Discussion discussionEjb =
resolveDiscussion(o);
com.bitterjava.bbs.Discussion discussion =
marshallDataObject(discussionEjb);
discussions.addElement(discussion);
}
board.setDiscussions(discussions);
return board;
}
Here, we're taking an EJB object and creating generic data objects from a col-
lection of EJB s. This approach provides a helper for generic data objects, so
that we can easily hide the implementation of our model.
private Post resolvePost(Object o) {
return (Post)javax.rmi.PortableRemoteObject.narrow(
(org.omg.CORBA.Object)o, Post.class);
}
}
This method helps us resolve the remote address of the object passed to our
method.
Search WWH ::




Custom Search