org.sapia.ubik.rmi.naming
Class ServiceLocator

java.lang.Object
  extended by org.sapia.ubik.rmi.naming.ServiceLocator

public class ServiceLocator
extends java.lang.Object

This class implements the Service Locator pattern. It acts as a universal lookup "helper", in conjunction with pluggable ServiceHandler instances. The ServiceLocator encapsulates one to many service handlers; for a given lookup, the locator retrieves the appropriate locator and then delegates the lookup to the latter, returning the result to the caller.

Service handlers are plugged into the locator in one of the following ways:

For example, given the following service handler: com.acme.MyServiceHandler, the configuration could be created has follows:

 System.setProperty("ubik.rmi.naming.service.handler.acme", "com.acme.MyServiceHandler");
 
Then, latter on, a lookup can be performed using this class:
 Object remote = ServiceLocator.lookup("acme://localhost:7070");
 
As shown above, the "acme" uri that was used to register the handler is then used in the lookup. Using the scheme of the passed in URI, the lookup(...) method delegates the operation to the proper handler.

IMPORTANT: If service handlers are configured through system properties, it is important to do so before invoking the ServiceLocator class in any way: the latter retrieves the configured handlers in a static initializer, which would prevent the handlers from being discovered if configured after the ServiceLocator class' initialization.

Author:
Yanick Duchesne
Copyright:
Copyright © 2002-2003 Sapia Open Source Software. All Rights Reserved.
License:
Read the license.txt file of the jar or visit the license page at the Sapia OSS web site

Field Summary
static java.lang.String HANDLER_PATTERN
          Corresponds to the prefix of properties specifying service handlers.
static java.lang.String UBIK_SCHEME
          The URI scheme for the default service handler: ubik.
static int UNDEFINED_PORT
          This constant identifies an unidentified port.
 
Constructor Summary
ServiceLocator()
           
 
Method Summary
static java.lang.Object lookup(java.lang.String url)
          Performs the lookup for the given path.
static void registerHandler(java.lang.String scheme, ServiceHandler handler)
          Registers the given handler with the passed in scheme.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNDEFINED_PORT

public static final int UNDEFINED_PORT
This constant identifies an unidentified port.

See Also:
Constant Field Values

HANDLER_PATTERN

public static final java.lang.String HANDLER_PATTERN
Corresponds to the prefix of properties specifying service handlers. The prefix is: 'ubik.rmi.naming.service.handler'.

See Also:
Constant Field Values

UBIK_SCHEME

public static final java.lang.String UBIK_SCHEME
The URI scheme for the default service handler: ubik.

See Also:
JNDIHandler, Constant Field Values
Constructor Detail

ServiceLocator

public ServiceLocator()
Method Detail

lookup

public static java.lang.Object lookup(java.lang.String url)
                               throws javax.naming.NameNotFoundException,
                                      javax.naming.NamingException
Performs the lookup for the given path.

Parameters:
url - the url of the object to look up.
Returns:
an Object
Throws:
javax.naming.NameNotFoundException - if no object could be found for the given url.
javax.naming.NamingException - if an error occurs while performing the lookup.

registerHandler

public static void registerHandler(java.lang.String scheme,
                                   ServiceHandler handler)
                            throws java.lang.IllegalStateException
Registers the given handler with the passed in scheme.

Parameters:
scheme - a URI scheme.
handler - a ServiceHandler.
Throws:
java.lang.IllegalStateException - if a handler is already registered with the given scheme.


Copyright © 2010 Sapia OSS. All Rights Reserved.