Java Mailing List Archive

http://www.junlu.com/

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

ServiceLocator end InitialContext

Giovani Salvador

2004-07-14

Replies:

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.

Example

....

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!!!!!!!!



Thanks

Giovani Salvador

====================================================================
Companion Site: http://www.corej2eepatterns.com
J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns
List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html
Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.