com.sun.jersey.spi.service
Interface ComponentProvider


public interface ComponentProvider

A provider for the instantiation and management of components.

The runtime will defer to a registered component provider (if present) for every component (application-defined or infrastructure-defined) that needs to be instantiated. If the component provider does not support the requested component it should return a null value and the runtime will attempt to directly instantiate and manage the component.

A ComponentProvider instance may be registed by passing the instance to the WebApplication.initiate(com.sun.jersey.api.core.ResourceConfig, ComponentProvider) method.

Applications may extend the ServletContainer and override the method ServletContainer.initiate(ResourceConfig, WebApplication) to initiate the WebApplication with the ComponentProvider instance.

See Also:
WebApplication, ServletContainer

Nested Class Summary
static class ComponentProvider.Scope
          The scope contract for the instantiation of a component.
 
Method Summary
<T> T
getInjectableInstance(T instance)
          Get the injectable instance to inject JAX-RS and Jersey specific instances on to fields.
<T> T
getInstance(ComponentContext cc, ComponentProvider.Scope scope, java.lang.Class<T> c)
          Get the instance of a class.
<T> T
getInstance(ComponentProvider.Scope scope, java.lang.Class<T> c)
          Get the instance of a class.
<T> T
getInstance(ComponentProvider.Scope scope, java.lang.reflect.Constructor<T> contructor, java.lang.Object[] parameters)
          Get the instance of a class using a constructor and a corresponding array of parameter values.
 void inject(java.lang.Object instance)
          Perform injection on an instance.
 

Method Detail

getInstance

<T> T getInstance(ComponentProvider.Scope scope,
                  java.lang.Class<T> c)
              throws java.lang.InstantiationException,
                     java.lang.IllegalAccessException
Get the instance of a class. Injection will be performed on the instance.

Parameters:
scope - the scope of the instance
c - the class
Returns:
the instance, or null if the component cannot be instantaited and managed.
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException

getInstance

<T> T getInstance(ComponentProvider.Scope scope,
                  java.lang.reflect.Constructor<T> contructor,
                  java.lang.Object[] parameters)
              throws java.lang.InstantiationException,
                     java.lang.IllegalArgumentException,
                     java.lang.IllegalAccessException,
                     java.lang.reflect.InvocationTargetException
Get the instance of a class using a constructor and a corresponding array of parameter values. Injection will be performed on the instance.

The array of parameter values must be the same length as that required by the constructor. Some parameter values may be null, indicating that the values are not set and must be set by the component provider before construction occurs.

Parameters:
scope - the scope of the instance
contructor - the constructor to instantiate the class
parameters - the array parameter values passed to the constructor
Returns:
the instance, or null if the component cannot be instantaited and managed.
Throws:
java.lang.InstantiationException
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

getInstance

<T> T getInstance(ComponentContext cc,
                  ComponentProvider.Scope scope,
                  java.lang.Class<T> c)
              throws java.lang.InstantiationException,
                     java.lang.IllegalAccessException
Get the instance of a class. Injection will be performed on the instance. Additional context is provided that may be used to determine the instance to return.

Implementations wishing to ignore the component context may defer to the implemented method {@link #getInstance(Scope, Class).

Parameters:
cc - the component context
scope - the scope of the instance
c - the class
Returns:
the instance, or null if the component cannot be instantaited and managed.
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException

getInjectableInstance

<T> T getInjectableInstance(T instance)
Get the injectable instance to inject JAX-RS and Jersey specific instances on to fields.

If the injectable instance is the same as the instance that was passed in then the provider MUST return that instance.

Parameters:
instance - the instance returned by one of the getInstance methods.
Returns:
the injectable instance.

inject

void inject(java.lang.Object instance)
Perform injection on an instance. This may be used when a component is instantiated by means other than the component provider.

Parameters:
instance - the instance to perform injection on.