com.bea.wlp.services
Class Services

java.lang.Object
  extended by com.bea.wlp.services.Services

public final class Services
extends Object

A common factory for retrieving services.

The retrieval model is based on the service's type (Class object), and in some cases the current context and/or a service name.

Note that the actual instance of a service may go away (be garbage collected) if memory needs to be reclaimed. Therefore, services should be stateless, since any state they hold may be reclaimed by the garbage collector. If you need to interact with a particular service instance, you must hold the reference to that service for the duration of the conversation. But the need for this should be discouraged, as it is probably not thread-safe.


Method Summary
static
<T> T
getService(Class<T> serviceType)
          Retrieve a service of the given type.
static
<T> T
getService(Class<T> serviceType, String serviceName)
          Retrieve a named service of the given type.
static Collection<String> getServiceNames(Class<?> serviceType)
          Return all the known names of the named service of the given type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getService

public static <T> T getService(Class<T> serviceType)
Retrieve a service of the given type. Use this method for cases where the services are 'generic' to the type, and do not have a name. Named services, when looked up this way, may choose to return an arbitrary (or primary) service, or may choose to return null. This will depend on the nature of the service being retrieved.

This method simply calls getService(serviceType,null).

Type Parameters:
T - the type of the service
Parameters
serviceType - class object for the service being retrieved, generally an interface
Returns
An implementation of the requested service. Will be null if the service is unknown, or if an instance can not be provided (for example, because the service must be named, or the service is requested from an inappropriate context).
Throws
ClassCastException - if a service is found by name but is not if the given type.
ServicesException - if some other unrecoverable problem (like a serious configuration error) is encountered.

getServiceNames

public static Collection<String> getServiceNames(Class<?> serviceType)
Return all the known names of the named service of the given type. Unnamed services will return an empty collection. For dynamicly configured services, where all names may not be known ahead of time, the returned collection may be empty or incomplete.

Parameters
serviceType - class object for the service being queried, generally an interface
Returns
The known names for the service requested. May be an empty collection, but will not be null.
Throws
ServicesException - if some unrecoverable problem (like a serious configuration error) is encountered.

getService

public static <T> T getService(Class<T> serviceType,
                               String serviceName)
Retrieve a named service of the given type. Use this method for cases where there may be several instances (implementations, providers, etc) of a particular service. Such instances are identified by names.

When the name is null, this method should return an unnamed service, or some service instance designated as the primary service. Where this is not possible (that is, the service does not exist or a name is required), null will be returned. It is up to the individual service to determine (and document) proper behavior in this regard.

Type Parameters:
T - the type of the service
Parameters
serviceType - class object for the service being retrieved, generally an interface
serviceName - the name of the service instance requested, or null to lookup an unnamed or primary service instance.
Returns
The service requested. Will be null if the service is unknown, or if an instance can not be provided (for example, because a service with the given name does not exist, or the service is requested from an inappropriate context).
See Also
getService(Class), getServiceNames(Class)


Copyright © 2000, 2009, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.