Last week, we looked at a way (recommended in "Core J2EE Patterns: Best
Practices and Design Strategies," new from O'Reilly & Associates) to
optimize Java Naming and Directory Interface (JNDI) lookup by
implementing a singleton object in Enterprise JavaBeans (EJB) systems.
Such a ServiceLocator object makes possible some economies of scale in
JNDI activity and eases the process of requesting objects from the EJB
environment.
A client makes requests of the ServiceLocator class by first
instantiating it:
ServiceLocator serviceLocator = ServiceLocator.getInstance();
Then, the client requests an EJBHome object from the ServiceLocator
class:
ProjectHome projectHome = (ProjectHome)
serviceLocator.getHome(ServiceLocator.Services.PROJECT );
After that, you have an EJBHome object ready for interaction with the
client. All of the tedious JNDI stuff is out of the way.