Java Mailing List Archive

Home » Home (12/2007) » J2EE Pattern »

ServiceLocator end InitialContext

Giovani Salvador



Hi all...

In the ServiceLocator pattern i build a IntialContext in its private
contructor and use this
IntialContext to lookup "services". I have seen in the examples and im
my own use of
this pattern that it�s built an IntialContext without parameter. What
about if i have to "attach"
to another context? If i have to do this i have to pass a Properties
object in the InitialContext�s constructor, ok?
But my ServiceLocator class has only one private variable instance of an
InitialContext and this initialContext,
as i said before, is built in the ServiceLocator�s private contructor
and built withou parameter of context.



public class ServiceLocator {
private static ServiceLocator me;
InitialContext context = null;

private ServiceLocator()
throws ServiceLocatorException {
  try {
   context = new InitialContext();
  } catch(NamingException ne) {
   throw new ServiceLocatorException(...);

// Returns the instance of ServiceLocator class
public static ServiceLocator getInstance()
throws ServiceLocatorException {
  if (me == null) {
   me = new ServiceLocator();
  return me;



What do i have to do if i want to use another context? How to achieve
this in the ServiceLocator Pattern?
Remember this patterns is suggested to be a singleton!!!!!!!!


Giovani Salvador

Companion Site:
J2EE BluePrints:
List Archive:
Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)
©2008 - Jax Systems, LLC, U.S.A.