wt.services.applicationcontext.implementation
Class WTServiceProvider

java.lang.Object
  extended bywt.services.applicationcontext.implementation.WTServiceProvider
All Implemented Interfaces:
ApplicationContextServiceProvider, Serializable
Direct Known Subclasses:
WTServiceProviderFromProperties

public class WTServiceProvider
extends Object
implements ApplicationContextServiceProvider, Serializable

An implementation of ApplicationContextServiceProvider which keeps track of services by keeping a collection of WTServiceInfo objects. It does not know how these objects are derived. WTServiceInfo objects can be manufactured in code or read in from some sort of file.

At the abstraction level of package applicationcontext, the requestor is just an object instance. This means that in applicationcontext the getService operations use the requestor object but there is no assumption about how that object is used to locate the service. Class WTServiceProvider in implementation uses the object to come up with an ordered set of class names. These class names are searched for a matching service from the most concrete to the most abstract.

Supported API: false

Extendable: false

See Also:
Serialized Form

Field Summary
private static String CLASSNAME
           
private static String RESOURCE
           
private  Hashtable service
           
private  com.objectspace.jgl.HashMap serviceImplementationSingletons
           
private  com.objectspace.jgl.HashMap serviceInfos
           
private  Hashtable serviceInfosForRequestor
           
private  com.objectspace.jgl.HashMap serviceInfosWOSelector
           
private static boolean VERBOSE
           
 
Fields inherited from interface wt.services.applicationcontext.ApplicationContextServiceProvider
SERVICE, WILD_CARD
 
Constructor Summary
WTServiceProvider()
          An abstract implementation of ApplicationContextServiceProvider.
 
Method Summary
 boolean addServiceInfo(WTServiceInfo serviceInfo)
          Add an externally derived service information entry.
protected  String createInfoKey(String serviceName, String selector, String requestorName)
           
protected  String createInfoKeyWOSelector(String serviceName, String requestorName)
           
protected  Vector getAllClasses(Object object)
           
protected  void getAllSuperClasses(Class aClass, Vector allClasses)
           
 Object getService(ApplicationContextChild contextChild, Object requestor, Class serviceClass, Object selector)
          Get an array of services based on context, requestor, selector, and logical service name.
 Object getService(ApplicationContextChild contextChild, Object requestor, String serviceName, Object selector)
          Get an array of services based on context, requestor, selector, and logical service name.
protected  Object getServiceImplementation(ApplicationContextChild contextChild, Object requestor, String serviceName, String implementationName, boolean isSingleton)
           
 String getServiceImplementationName(ApplicationContextChild contextChild, Object requestor, String serviceName, Object selector)
          Get the name of the service implementation class for a particular context, requestor, selector, and logical service name.
 Map getServiceImplementationNameMap(ApplicationContextChild contextChild, ACRequestor requestor, String serviceName, Object selector)
          Return the name of the service implementation.
 Map getServiceImplementationNameMap(ApplicationContextChild contextChild, Object[] requestors, String serviceName, Object selector)
          Return the name of the service implementation.
 WTServiceInfo[] getServiceInfos()
          Return service info entries.
protected  WTServiceInfo[] getServiceInfosForRequestor(ApplicationContextChild contextChild, Object requestor, String serviceName, String selector)
           
protected  com.objectspace.jgl.HashMap getServiceInfosWOSelector()
          Gets the object for the association that plays role: serviceInfosWOSelector.
 Map getServiceMap(ApplicationContextChild contextChild, ACRequestor requestor, Class serviceClass, Object selector)
          Return a service based on context, requestor and logical service type.
 Map getServiceMap(ApplicationContextChild contextChild, ACRequestor requestor, String serviceName, Object selector)
          Return an instance of a service based on context, requestor and logical service name.
 Map getServiceMap(ApplicationContextChild contextChild, Object[] requestors, Class serviceClass, Object selector)
          Return a service based on context, requestor and logical service type.
 Map getServiceMap(ApplicationContextChild contextChild, Object[] requestors, String serviceName, Object selector)
          Return an instance of a service based on context, requestor and logical service name.
 String[] getServiceNames()
          

Supported API: false
 Enumeration getServiceSelectors(ApplicationContextChild contextChild, String serviceName, Object requestor)
          

Supported API: false
protected  Object getSingletonImplementation(Class implementationClass)
          If the implementation class doesn't have a public constructor, looks for a static getInstance() method to use to instantiate the service.
 void printOn(PrintStream ps)
           
protected  void setServiceInfosWOSelector(com.objectspace.jgl.HashMap a_ServiceInfosWOSelector)
          Sets the object for the association that plays role: serviceInfosWOSelector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

CLASSNAME

private static final String CLASSNAME

serviceInfosWOSelector

private com.objectspace.jgl.HashMap serviceInfosWOSelector

serviceImplementationSingletons

private com.objectspace.jgl.HashMap serviceImplementationSingletons

serviceInfosForRequestor

private Hashtable serviceInfosForRequestor

serviceInfos

private com.objectspace.jgl.HashMap serviceInfos

service

private Hashtable service

VERBOSE

private static boolean VERBOSE
Constructor Detail

WTServiceProvider

public WTServiceProvider()
An abstract implementation of ApplicationContextServiceProvider. Class WTServiceProvider maintains a collection of WTServiceInfo objects. Each WTServiceInfo object represents one mapping from a logical service a requestor (class) name and an optional selector to the name of the class or resource which is appropriate.

Supported API: false

Method Detail

getServiceInfosWOSelector

protected com.objectspace.jgl.HashMap getServiceInfosWOSelector()
Gets the object for the association that plays role: serviceInfosWOSelector.

Supported API: false

Returns:
HashMap

setServiceInfosWOSelector

protected void setServiceInfosWOSelector(com.objectspace.jgl.HashMap a_ServiceInfosWOSelector)
Sets the object for the association that plays role: serviceInfosWOSelector.

Supported API: false

Parameters:
a_ServiceInfosWOSelector -

getServiceNames

public String[] getServiceNames()


Supported API: false

Specified by:
getServiceNames in interface ApplicationContextServiceProvider
Returns:
String[]

getService

public Object getService(ApplicationContextChild contextChild,
                         Object requestor,
                         String serviceName,
                         Object selector)
                  throws ServiceNotFoundException,
                         UnableToCreateServiceException
Get an array of services based on context, requestor, selector, and logical service name.

Prior to R3.0 this method was implemented to return only a single service, not an array of services.

The algorithm for resolving a service was as follows:

For R3.0 the algortihm has been modified to return multiple service implementation based on the following rules:

ApplicationContextServicesSupport implements its getService method to return the first element in the array of service implemenations returned by this method. This maintains backward compatibility with the R2.X implementation of this method.

ApplicationContextServicesSupport implements a new method, getServices, which returns all the service implementations resolved through the above rules.

Supported API: false

Specified by:
getService in interface ApplicationContextServiceProvider
Parameters:
contextChild - The context in which the service is being requested. May be null.
requestor - The target of the service request.
serviceName - The name of the logical service.
selector -
Returns:
Object
Throws:
ServiceNotFoundException
UnableToCreateServiceException

getService

public Object getService(ApplicationContextChild contextChild,
                         Object requestor,
                         Class serviceClass,
                         Object selector)
                  throws ServiceNotFoundException,
                         UnableToCreateServiceException
Get an array of services based on context, requestor, selector, and logical service name. See the javadoc for the other variation of getService in this class.

Supported API: false

Specified by:
getService in interface ApplicationContextServiceProvider
Parameters:
contextChild - The context in which the service is being requested.
requestor - The object on who's behalf the service is being requested.
serviceClass - The logical service class.
selector -
Returns:
Object
Throws:
ServiceNotFoundException
UnableToCreateServiceException

getServiceMap

public Map getServiceMap(ApplicationContextChild contextChild,
                         Object[] requestors,
                         String serviceName,
                         Object selector)
                  throws UnableToCreateServiceException
Return an instance of a service based on context, requestor and logical service name.

Supported API: false

Specified by:
getServiceMap in interface ApplicationContextServiceProvider
Parameters:
contextChild - The context in which the service is being requested.
requestors - The target of the service request.
serviceName - The name of the requested service.
selector - An optional selector to further identify the service.
Returns:
Map
Throws:
UnableToCreateServiceException

getServiceMap

public Map getServiceMap(ApplicationContextChild contextChild,
                         Object[] requestors,
                         Class serviceClass,
                         Object selector)
                  throws UnableToCreateServiceException
Return a service based on context, requestor and logical service type.

Supported API: false

Specified by:
getServiceMap in interface ApplicationContextServiceProvider
Parameters:
contextChild - The service context in which the getService request was initiated.
requestors - The object on who's behalf the service request is being made.
serviceClass - The logical service class being requested.
selector - An optional selector to further identify the service.
Returns:
Map
Throws:
UnableToCreateServiceException

getServiceMap

public Map getServiceMap(ApplicationContextChild contextChild,
                         ACRequestor requestor,
                         String serviceName,
                         Object selector)
                  throws UnableToCreateServiceException
Return an instance of a service based on context, requestor and logical service name.

Supported API: false

Specified by:
getServiceMap in interface ApplicationContextServiceProvider
Parameters:
contextChild - The context in which the service is being requested.
requestor -
serviceName - The name of the requested service.
selector - An optional selector to further identify the service.
Returns:
Map
Throws:
UnableToCreateServiceException

getServiceMap

public Map getServiceMap(ApplicationContextChild contextChild,
                         ACRequestor requestor,
                         Class serviceClass,
                         Object selector)
                  throws UnableToCreateServiceException
Return a service based on context, requestor and logical service type.

Supported API: false

Specified by:
getServiceMap in interface ApplicationContextServiceProvider
Parameters:
contextChild - The service context in which the getService request was initiated.
requestor -
serviceClass - The logical service class being requested.
selector - An optional selector to further identify the service.
Returns:
Map
Throws:
UnableToCreateServiceException

getServiceSelectors

public Enumeration getServiceSelectors(ApplicationContextChild contextChild,
                                       String serviceName,
                                       Object requestor)


Supported API: false

Specified by:
getServiceSelectors in interface ApplicationContextServiceProvider
Parameters:
contextChild -
serviceName -
requestor -
Returns:
Enumeration

getServiceImplementationName

public String getServiceImplementationName(ApplicationContextChild contextChild,
                                           Object requestor,
                                           String serviceName,
                                           Object selector)
Get the name of the service implementation class for a particular context, requestor, selector, and logical service name. See javadoc for getService to understand how a service implementation class is resolved.

Supported API: false

Specified by:
getServiceImplementationName in interface ApplicationContextServiceProvider
Parameters:
contextChild -
requestor -
serviceName -
selector -
Returns:
String

getServiceImplementationNameMap

public Map getServiceImplementationNameMap(ApplicationContextChild contextChild,
                                           Object[] requestors,
                                           String serviceName,
                                           Object selector)
Return the name of the service implementation. Usuall this is the fully qualified class name, but it may be any string (implying that a service can't be instantiated.

Supported API: false

Specified by:
getServiceImplementationNameMap in interface ApplicationContextServiceProvider
Parameters:
contextChild - The context in which the service request was initiated. May be used to determine which service implementation should be returned.
requestors - The requestor or target of the service. Used to determine which service implementation should be returned.
serviceName - The logical name of the desired service.
selector - An optional selector to further identify the service.
Returns:
Map

getServiceImplementationNameMap

public Map getServiceImplementationNameMap(ApplicationContextChild contextChild,
                                           ACRequestor requestor,
                                           String serviceName,
                                           Object selector)
Return the name of the service implementation. Usuall this is the fully qualified class name, but it may be any string (implying that a service can't be instantiated.

Supported API: false

Specified by:
getServiceImplementationNameMap in interface ApplicationContextServiceProvider
Parameters:
contextChild - The context in which the service request was initiated. May be used to determine which service implementation should be returned.
requestor -
serviceName - The logical name of the desired service.
selector - An optional selector to further identify the service.
Returns:
Map

addServiceInfo

public boolean addServiceInfo(WTServiceInfo serviceInfo)
Add an externally derived service information entry.

Supported API: false

Parameters:
serviceInfo - The service info to be added.
Returns:
boolean

getServiceInfos

public WTServiceInfo[] getServiceInfos()
Return service info entries.

Supported API: false

Returns:
WTServiceInfo[]

getServiceImplementation

protected Object getServiceImplementation(ApplicationContextChild contextChild,
                                          Object requestor,
                                          String serviceName,
                                          String implementationName,
                                          boolean isSingleton)
                                   throws UnableToCreateServiceException
Throws:
UnableToCreateServiceException

getServiceInfosForRequestor

protected WTServiceInfo[] getServiceInfosForRequestor(ApplicationContextChild contextChild,
                                                      Object requestor,
                                                      String serviceName,
                                                      String selector)

getAllClasses

protected Vector getAllClasses(Object object)

getAllSuperClasses

protected void getAllSuperClasses(Class aClass,
                                  Vector allClasses)

createInfoKeyWOSelector

protected String createInfoKeyWOSelector(String serviceName,
                                         String requestorName)

createInfoKey

protected String createInfoKey(String serviceName,
                               String selector,
                               String requestorName)

printOn

public void printOn(PrintStream ps)

getSingletonImplementation

protected Object getSingletonImplementation(Class implementationClass)
                                     throws ClassNotFoundException,
                                            IllegalAccessException,
                                            InstantiationException
If the implementation class doesn't have a public constructor, looks for a static getInstance() method to use to instantiate the service.

Throws:
ClassNotFoundException
IllegalAccessException
InstantiationException