org.glassfish.hk2
Interface Provider<T>

All Known Subinterfaces:
ManagedComponentProvider<T>

public interface Provider<T>

Extends the Factory contract, offering the ability to

  • obtain the runtime Descriptor describing the attributes of the registered component/service, and
  • provides a means to access the class type instance. Note that the class instance might be managed in a context other than the current thread classloader context.

    Author:
    Jerome Dochez, Jeff Trent, Mason Taube
    See Also:
    ManagedComponentProvider

    Method Summary
     T get()
              The system calls this method to obtain a reference to the component/service.
     java.util.Collection<java.lang.annotation.Annotation> getAnnotations()
              The collection of annotations for this type.
     Descriptor getDescriptor()
              The Descriptor fully characterizes the attributes of this Provider.
     java.lang.Class<? extends T> type()
              The class type of the implementation.
     

    Method Detail

    get

    T get()
          throws ComponentException
    The system calls this method to obtain a reference to the component/service.

    Returns:
    null is a valid return value. This is useful when a factory primarily does a look-up and it fails to find the specified component, yet you don't want that by itself to be an error. If the injection wants a non-null value (i.e., @Inject(optional=false)).
    Throws:
    ComponentException - If the factory failed to get/create an instance and would like to propagate the error to the caller.

    getDescriptor

    Descriptor getDescriptor()
    The Descriptor fully characterizes the attributes of this Provider.

    Returns:
    a non-null Descriptor describing the complete set of attributes of the provider.

    type

    java.lang.Class<? extends T> type()
    The class type of the implementation. it is responsible also for determining how (i.e., which loader) to use.

    The class type for what the Factory actually produces.

    Note that there is some cost to this call during the first invocation since it needs to perform classloading. Care should therefore be exercised accordingly.

    Returns:
    the class type for what this Provider produces, or null only in the case where the Provider is a facade to a user defined factory that

    getAnnotations

    java.util.Collection<java.lang.annotation.Annotation> getAnnotations()
    The collection of annotations for this type. Note that this may not be the same as the annotations on the type().

    Returns:
    a non-null collection of annotation classes for this provider type.


    Copyright © 2011 Oracle Corporation. All Rights Reserved.