Java Reference
In-Depth Information
return getPostsInDiscussion(boardName, discussionID);
In this method, we add a post to a discussion. We first find the home interface
for the discussion and execute a finder by primary key. We then add a post
with this interface. Note that we have conveniently collected all of the ele-
ments of the post within a small helper object called post , to help simplify the
public com.bitterjava.bbs.Board getBoard(String name)
throws java.rmi.RemoteException, FinderException {
com.bitterjava.bbs.ejb.Board boardEjb =
getBoardHome().findByPrimaryKey(new BoardKey(name));
return marshallDataObject(boardEjb);
Here, we use a technique to convert an EJB to one of our helper objects. We use
one of three marshallDataObject methods. An example is shown further here.
private BoardHome getBoardHome() {
if (boardHome == null) {
try {
Properties env = mySessionCtx.getEnvironment();
String providerURL = env.getProperty("providerURL");
String boardHomeName = env.getProperty("boardHomeName");
Properties p = new Properties();
p.put("java.naming.provider.url", providerURL);
javax.naming.InitialContext ic =
new javax.naming.InitialContext(p);
java.lang.Object homeObject = ic.lookup(boardHomeName);
boardHome = (BoardHome) javax.rmi.PortableRemoteObject.narrow(
(org.omg.CORBA.Object)homeObject, BoardHome.class);
} catch (Exception e) {}
return boardHome;
The Java home objects are named resources, so we can find them through the
naming context and the JNDI interface. Many of these property values are
established in our deployment descriptors.
Vector getPostsInDiscussion(String boardName, int discussionID)
throws java.rmi.RemoteException, javax.ejb.FinderException {
java.util.Vector posts = new java.util.Vector();
try {
Search WWH ::

Custom Search