Best way to lookup EJBs
Hi,
We have a series of session beans which would be used by both Web clients
residing in the same container as the EJBs and remote Java application clients.
I want to have a single class which would be used by both these clients to lookup the EJBs. Can somebody suggest a way to do it..
Thanks,
Chandrika
[343 byte] By [
ch75a] at [2007-9-27 8:07:35]

Use the ServiceLocator design pattern. Here is a simplified version. Write one Singleton class, say HomeFinder.java. Initialize the HomeFinder class with the applicationName.
Next define a series of getXXXHome methods like getPortfolioHome(), getAccountHome() etc. Inside these methods, you will look up the home by passing a key. For Example, getProperty(applicationName + "portfolio") or getProperty(applicationName + "account").
All the keys and its values can be defined in a HashMap or better to load it from a properties file. One example of Key/Value combination would be "portfolio=applicationName/ejb/portfoliobean".
This way you can have one class load up the EJBeanHomes for any number of applications. This works because you
1) initialize the HomeFinder with the application Name.
2) Define one set of properties prefixed with the first application's Name and define another set of properties with the second application's Name
Regards, Venky