com.sun.hk2.component
Class InjectionResolver<U extends java.lang.annotation.Annotation>

java.lang.Object
  extended by com.sun.hk2.component.InjectionResolver<U>
Type Parameters:
U - U is the annotation used to identify the injection targets.
Direct Known Subclasses:
InjectInjectionResolver, LeadInjectionResolver

public abstract class InjectionResolver<U extends java.lang.annotation.Annotation>
extends java.lang.Object

Implementation of this abstract class are handling injection resolution for a particular injection annotation Inject Injection targets are identified by the generic parameter and the constructor of this class. Potential injection targets are fields and methods of the injected type.

Author:
Jerome Dochez

Field Summary
 java.lang.Class<U> type
           
 
Constructor Summary
InjectionResolver(java.lang.Class<U> type)
          Construct a resolver with a particular injection type
 
Method Summary
 java.lang.reflect.Method getSetterMethod(java.lang.reflect.Method annotated, U annotation)
          Returns the setter method responsible for setting the resource identified by the passed annotation on the passed annotated method.
abstract
<V> V
getValue(java.lang.Object component, Inhabitant<?> onBehalfOf, java.lang.reflect.AnnotatedElement annotated, java.lang.reflect.Type genericType, java.lang.Class<V> type)
          Returns the value to inject in the field or method of component annotated with the annotated annotation.
 boolean isOptional(java.lang.reflect.AnnotatedElement annotated, U annotation)
          Returns true if the resolution of this injection identified by the passed annotation instance is optional
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

type

public final java.lang.Class<U extends java.lang.annotation.Annotation> type
Constructor Detail

InjectionResolver

public InjectionResolver(java.lang.Class<U> type)
Construct a resolver with a particular injection type

Parameters:
type - the injection annotation type
Method Detail

getSetterMethod

public java.lang.reflect.Method getSetterMethod(java.lang.reflect.Method annotated,
                                                U annotation)
Returns the setter method responsible for setting the resource identified by the passed annotation on the passed annotated method. This is useful when the annotation is specified on the getter for instance (due to external specification requirements for instance) while the setter should be used if values must be set using this injection resolver. By default, the setter method is the annotated method.

Parameters:
annotated - is the annotated Method
annotation - the annotation on the method
Returns:
the setter method to use for injecting the annotation identified resource

isOptional

public boolean isOptional(java.lang.reflect.AnnotatedElement annotated,
                          U annotation)
Returns true if the resolution of this injection identified by the passed annotation instance is optional

Parameters:
annotated - is the annotated java element Method or Field
annotation - the injection metadata
Returns:
true if the getValue() can return null without generating a faulty injection operation

getValue

public abstract <V> V getValue(java.lang.Object component,
                               Inhabitant<?> onBehalfOf,
                               java.lang.reflect.AnnotatedElement annotated,
                               java.lang.reflect.Type genericType,
                               java.lang.Class<V> type)
                    throws ComponentException
Returns the value to inject in the field or method of component annotated with the annotated annotation. // * @param habitat the habitat containing component / inhabitant

Parameters:
component - injection target instance
onBehalfOf - inhabitant doing the injection for
annotated - is the annotated java element Method or Field
genericType - the generic type of the expected return
type - type of the expected return
Returns:
the resource to be injected
Throws:
ComponentException - if the resource cannot be located.


Copyright © 2011 Oracle Corporation. All Rights Reserved.