File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes 5 bean client steps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "5 bean client steps" Watch "5 bean client steps" New topic

5 bean client steps

Swamy Nathan
Ranch Hand

Joined: May 16, 2004
Posts: 187
On p55 of HFEJB K&B it shows 5 steps to use a bean.
The book also says that if the client is another bean the code will be slightly different.


Will someone advise me on whether I am correct or not:--

[ October 01, 2004: Message edited by: Swamy Nathan ]
Kathy Sierra
Cowgirl and Author

Joined: Oct 10, 2002
Posts: 1589
I think this is almost right...

One thing I'd specify is that if the servlet client is a part of the same J2EE App Server, than the servlet and the bean clients will be identical, and what you refer to as SimpleClient (like our standalone plain old Java app) should really be called "A non-J2EE client", which could mean a standalone Swing GUI, or a servlet.

So, the two issues that you've specified are correct;

1) How do you get the InitialContext?
2) What do you code in the lookup String?

So, here we go:

1) InitialContext:

For J2EE clients (which could mean another bean, a servlet running in the servlet Container of the same J2EE server, or even a "J2EE application client", you can ask for the default InitialContext. The Contianer *knows* it's own JNDI context.

But for NON-J2EE clients, of course, you must specify *somehow* the location and class type of the driver for that server. You can do this in several ways: invoking InitialContext() overridden constructor that takes a Properties object; invoking the no-arg constructor and assuming that it will find the file that has the correct info, or specifying command-line arguments that set those properties. This is really dependent on your app server.

2) For the lookup String, NON-J2EE clients must specify the JNDI name configured on deployment of the app. J2EE clients will use the java:com/env lookup, because that allows them to use a coded name that can (in the DD) be mapped to something else later.

Does that help? We should make a table like you've done and put it on our web page... or add to the next edition of the book. It's a great idea!
Swamy Nathan
Ranch Hand

Joined: May 16, 2004
Posts: 187
Is there any easier way to post tabular info here?
Swamy Nathan
Ranch Hand

Joined: May 16, 2004
Posts: 187
Is there any easier way to post tabular info here?
I agree. Here's the link:
subject: 5 bean client steps
It's not a secret anymore!