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.

Author:
Paul.Sandoz@Sun.Com

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 onto fields of the instance.
<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.

Type Parameters:
T - the type to inject.
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 - if the component could not be instantiated.
java.lang.IllegalAccessException - if there was an error accessing the definition of the component class.

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.

Type Parameters:
T - the type to inject.
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 - if the component could not be instantiated.
java.lang.IllegalAccessException - if there was an error accessing the definition of the component constructor.
java.lang.IllegalArgumentException - if the number of parameters differ or a parameter instance does not conform to the approprate type.
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 getInstance(Scope, Class).

Type Parameters:
T - the type to inject.
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 - if the component could not be instantiated.
java.lang.IllegalAccessException - if there was an error accessing the definition of the component class.

getInjectableInstance

<T> T getInjectableInstance(T instance)
Get the injectable instance to inject onto fields of the instance.

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

Type Parameters:
T - the type to inject.
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.


Copyright © 2008 Sun Microsystems, Inc. All Rights Reserved.