Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.infinispan.cdi.util;
  
  import java.util.List;
  
  import  javax.enterprise.context.spi.CreationalContext;
  import  javax.enterprise.inject.spi.AnnotatedMethod;
  import  javax.enterprise.inject.spi.Bean;
 import  javax.enterprise.inject.spi.BeanManager;
 import  javax.enterprise.inject.spi.InjectionPoint;
 
 
 import static org.infinispan.cdi.util.Reflections.EMPTY_OBJECT_ARRAY;

Allows an AnnotatedMethod to be injected using the CDI type safe resolution rules.

ParameterValueRedefiner allows the default value to be overridden by the caller of invoke(Object, CreationalContext, ParameterValueRedefiner).

Parameters:
<X> the declaring type
Author(s):
Pete Muir
 
 public class InjectableMethod<X> {
 
     private final AnnotatedMethod<X> method;
     private final List<InjectionPoint> parameters;
     private final BeanManager beanManager;

    
Instantiate a new InjectableMethod.

Parameters:
method the method which will be injected upon a call to invoke(Object, CreationalContext)
bean the bean which defines the injectable method
beanManager the BeanManager to use to obtain the parameter values
 
     public InjectableMethod(AnnotatedMethod<X> method, Bean<?> declaringBean, BeanManager beanManager) {
         this(method, Beans.createInjectionPoints(methoddeclaringBeanbeanManager), beanManager);
     }

    
Instantiate a new InjectableMethod.

Parameters:
method the method which will be injected upon a call to invoke(Object, CreationalContext)
parameters a collection of injection points representing the parameters of the method
beanManager the BeanManager to use to obtain the parameter values
 
     public InjectableMethod(AnnotatedMethod<X> methodCollection<InjectionPoint> parameters, BeanManager beanManager) {
         this. = method;
         this. = new ArrayList<InjectionPoint>(parameters);
         this. = beanManager;
     }

    
Get the bean manager used by this injectable method.

Returns:
the bean manager in use
 
     protected BeanManager getBeanManager() {
         return ;
     }

    
Get the injectable parameters of this method.

Returns:
a collection of injection points representing the parameters of this method
 
     protected List<InjectionPoint> getParameters() {
         return ;
     }

    
Invoke the method, causing all parameters to be injected according to the CDI type safe resolution rules.

Parameters:
<T> the return type of the method
receiver the instance upon which to call the method
creationalContext the creational context to use to obtain injectable references for each parameter
Returns:
the result of invoking the method or null if the method's return type is void
Throws:
RuntimeException if this Method object enforces Java language access control and the underlying method is inaccessible or if the underlying method throws an exception or if the initialization provoked by this method fails.
IllegalArgumentException if the method is an instance method and the specified receiver argument is not an instance of the class or interface declaring the underlying method (or of a subclass or implementor thereof); if an unwrapping conversion for primitive arguments fails; or if, after possible unwrapping, a parameter value cannot be converted to the corresponding formal parameter type by a method invocation conversion.
NullPointerException if the specified receiver is null and the method is an instance method.
ExceptionInInitializerError if the initialization provoked by this method fails.
    public <T> T invoke(Object receiver, CreationalContext<T> creationalContext) {
        return invoke(receivercreationalContextnull);
    }

    
Invoke the method, calling the parameter redefiner for each parameter, allowing the caller to override the default value obtained via the CDI type safe resolver.

Parameters:
<T> the return type of the method
receiver the instance upon which to call the method
creationalContext the creational context to use to obtain injectable references for each parameter
Returns:
the result of invoking the method or null if the method's return type is void
Throws:
RuntimeException if this Method object enforces Java language access control and the underlying method is inaccessible or if the underlying method throws an exception or if the initialization provoked by this method fails.
IllegalArgumentException if the method is an instance method and the specified receiver argument is not an instance of the class or interface declaring the underlying method (or of a subclass or implementor thereof); if an unwrapping conversion for primitive arguments fails; or if, after possible unwrapping, a parameter value cannot be converted to the corresponding formal parameter type by a method invocation conversion.
NullPointerException if the specified receiver is null and the method is an instance method.
ExceptionInInitializerError if the initialization provoked by this method fails.
    public <T> T invoke(Object receiver, CreationalContext<T> creationalContextParameterValueRedefiner redefinition) {
        List<ObjectparameterValues = new ArrayList<Object>();
        for (int i = 0; i < getParameters().size(); i++) {
            if (redefinition != null) {
                ParameterValue value = new ParameterValue(igetParameters().get(i), getBeanManager());
                parameterValues.add(redefinition.redefineParameterValue(value));
            } else {
                parameterValues.add(getBeanManager().getInjectableReference(getParameters().get(i), creationalContext));
            }
        }
        @SuppressWarnings("unchecked")
        T result = (T) Reflections.invokeMethod(true.getJavaMember(), receiverparameterValues.toArray());
        return result;
    }
New to GrepCode? Check out our FAQ X