Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2008, Red Hat, Inc., and individual contributors
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.jboss.weld.injection;
 
 import static org.jboss.weld.injection.Exceptions.rethrowException;
 import static org.jboss.weld.util.reflection.Reflections.cast;
 
 import java.util.Map;
 
 
 
High-level representation of an injected method. This class does not need to be serializable because it is never injected.

Author(s):
Pete Muir
Jozef Hartinger
 
 public class MethodInjectionPoint<T, X> extends AbstractCallableInjectionPoint<T, X, Method> {
 
     private final AnnotatedMethod<X> annotatedMethod;
     private final Method accessibleMethod;
 
     private volatile Map<Class<?>, Methodmethods;
 
     protected MethodInjectionPoint(EnhancedAnnotatedMethod<T, X> enhancedMethodBean<?> declaringBeanClass<?> declaringComponentClassboolean observerOrDisposerInjectionPointFactory factoryBeanManagerImpl manager) {
         super(enhancedMethoddeclaringBeandeclaringComponentClassobserverOrDisposerfactorymanager);
         this. = enhancedMethod.slim();
         this. = AccessController.doPrivileged(new GetAccessibleCopyOfMember<Method>(.getJavaMember()));
     }
 
     public T invoke(Object declaringInstanceBeanManagerImpl managerCreationalContext<?> creationalContextClass<? extends RuntimeExceptionexceptionTypeToThrow) {
         return invokeWithSpecialValue(declaringInstancenullnullmanagercreationalContextexceptionTypeToThrow);
     }
 
     public T invokeWithSpecialValue(Object declaringInstanceClass<? extends AnnotationannotatedParameterObject parameterBeanManagerImpl managerCreationalContext<?> ctxClass<? extends RuntimeExceptionexceptionTypeToThrow) {
         CreationalContext<?> invocationContext = manager.createCreationalContext(null);
         try {
             return cast(.invoke(declaringInstancegetParameterValues(annotatedParameterparametermanagerctxinvocationContext)));
         } catch (IllegalArgumentException e) {
             rethrowException(eexceptionTypeToThrow);
         } catch (IllegalAccessException e) {
             rethrowException(eexceptionTypeToThrow);
         } catch (InvocationTargetException e) {
             rethrowException(eexceptionTypeToThrow);
         } finally {
             invocationContext.release();
         }
         return null;
     }
 
     public T invokeOnInstance(Object declaringInstanceBeanManagerImpl managerCreationalContext<?> creationalContextClass<? extends RuntimeExceptionexceptionTypeToThrow) {
         return invokeOnInstanceWithSpecialValue(declaringInstancenullnullmanagercreationalContextexceptionTypeToThrow);
     }
 
     public T invokeOnInstanceWithSpecialValue(Object declaringInstanceClass<? extends AnnotationannotatedParameterObject parameterBeanManagerImpl managerCreationalContext<?> ctxClass<? extends RuntimeExceptionexceptionTypeToThrow) {
         CreationalContext<?> invocationContext = manager.createCreationalContext(null);
         try {
             Method method = getMethodFromClass(declaringInstance.getClass());
             return cast(method.invoke(declaringInstancegetParameterValues(annotatedParameterparametermanagerctxinvocationContext)));
         } catch (IllegalArgumentException e) {
             rethrowException(eexceptionTypeToThrow);
         } catch (SecurityException e) {
             rethrowException(eexceptionTypeToThrow);
         } catch (IllegalAccessException e) {
             rethrowException(eexceptionTypeToThrow);
         } catch (InvocationTargetException e) {
             rethrowException(eexceptionTypeToThrow);
         } catch (NoSuchMethodException e) {
            rethrowException(eexceptionTypeToThrow);
        } finally {
            invocationContext.release();
        }
        return null;
    }

    
Helper method for getting the current parameter values from a list of annotated parameters.

Parameters:
parameters The list of annotated parameter to look up
manager The Bean manager
Returns:
The object array of looked up values
    protected Object[] getParameterValues(Class<? extends AnnotationspecialParamObject specialValBeanManagerImpl managerCreationalContext<?> ctxCreationalContext<?> invocationContext) {
        Object[] parameterValues = new Object[getParameterInjectionPoints().size()];
        Iterator<ParameterInjectionPoint<?, X>> iterator = getParameterInjectionPoints().iterator();
        for (int i = 0; i < parameterValues.lengthi++) {
            ParameterInjectionPoint<?, ?> param = iterator.next();
            if (specialParam != null && param.getAnnotated().isAnnotationPresent(specialParam)) {
                parameterValues[i] = specialVal;
            } else if (param.getAnnotated().isAnnotationPresent(TransientReference.class)){
                parameterValues[i] = param.getValueToInject(managerinvocationContext);
            } else {
                parameterValues[i] = param.getValueToInject(managerctx);
            }
        }
        return parameterValues;
    }
    @Override
    public AnnotatedMethod<X> getAnnotated() {
        return ;
    }
    private Method getMethodFromClass(Class<?> clazzthrows NoSuchMethodException {
        final Map<Class<?>, Methodmethods = this.;
        Method method = this..get(clazz);
        if (method == null) {
            // the same method may be written to the map twice, but that is ok
            // lookupMethod is very slow
            Method delegate = .getJavaMember();
            method = SecurityActions.lookupMethod(clazzdelegate.getName(), delegate.getParameterTypes());
            if (!Modifier.isPublic(method.getModifiers())) {
                method = AccessController.doPrivileged(new GetAccessibleCopyOfMember<Method>(method));
            }
            final Map<Class<?>, MethodnewMethods = ImmutableMap.<Class<?>, Method>builder().putAll(methods).put(clazzmethod).build();
            this. = newMethods;
        }
        return method;
    }
New to GrepCode? Check out our FAQ X