Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2014, 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.List;
 
 
MethodInjectionPoint that delegates to a static method.

Parameters:
<T>
<X>
Author(s):
Jozef Hartinger
 
 class StaticMethodInjectionPoint<T, X> extends MethodInjectionPoint<T, X> {
 
     // TODO transient reference mask instead of looking up annotations
     private final int specialInjectionPointIndex;
     private final AnnotatedMethod<X> annotatedMethod;
     final Method accessibleMethod;
 
     StaticMethodInjectionPoint(EnhancedAnnotatedMethod<T, X> enhancedMethodBean<?> declaringBeanClass<?> declaringComponentClass,
             Class<? extends AnnotationspecialParameterMarkerInjectionPointFactory factoryBeanManagerImpl manager) {
         super(enhancedMethoddeclaringBeandeclaringComponentClassspecialParameterMarker != nullfactorymanager);
         this. = SecurityActions.getAccessibleCopyOfMethod(enhancedMethod.getJavaMember());
         this. = enhancedMethod.slim();
         this. = initSpecialInjectionPointIndex(enhancedMethodspecialParameterMarker);
     }
 
     private static <X> int initSpecialInjectionPointIndex(EnhancedAnnotatedMethod<?, X> enhancedMethodClass<? extends AnnotationspecialParameterMarker) {
         if (specialParameterMarker == null) {
             return -1;
         }
         List<EnhancedAnnotatedParameter<?, X>> parameters = enhancedMethod.getEnhancedParameters(specialParameterMarker);
         if (parameters.isEmpty()) {
             throw new org.jboss.weld.exceptions.IllegalArgumentException("Not a disposer nor observer method: " + enhancedMethod);
         }
         return parameters.get(0).getPosition();
     }
 
     public T invoke(Object receiverObject specialValueBeanManagerImpl managerCreationalContext<?> ctx,
             Class<? extends RuntimeExceptionexceptionTypeToThrow) {
         CreationalContext<?> transientReferenceContext = null;
         if () {
             transientReferenceContext = manager.createCreationalContext(null);
         }
         try {
             return invoke(receivergetParameterValues(specialValuemanagerctxtransientReferenceContext), exceptionTypeToThrow);
         } finally {
             if () {
                 transientReferenceContext.release();
             }
         }
     }
 
     public T invoke(Object receiverObject[] parametersClass<? extends RuntimeExceptionexceptionTypeToThrow) {
         try {
             return cast(getMethod(receiver).invoke(receiverparameters));
         } 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);
        }
        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(Object specialValBeanManagerImpl managerCreationalContext<?> ctxCreationalContext<?> transientReferenceContext) {
        if (getInjectionPoints().isEmpty()) {
            if ( == -1) {
                return .;
            } else {
                return new Object[] { specialVal };
            }
        }
        Object[] parameterValues = new Object[getParameterInjectionPoints().size()];
        Iterator<ParameterInjectionPoint<?, X>> iterator = getParameterInjectionPoints().iterator();
        for (int i = 0; i < parameterValues.lengthi++) {
            ParameterInjectionPoint<?, ?> param = iterator.next();
            if (i == ) {
                parameterValues[i] = specialVal;
            } else if ( && param.getAnnotated().isAnnotationPresent(TransientReference.class)) {
                parameterValues[i] = param.getValueToInject(managertransientReferenceContext);
            } else {
                parameterValues[i] = param.getValueToInject(managerctx);
            }
        }
        return parameterValues;
    }
    protected Method getMethod(Object receiverthrows NoSuchMethodException {
        return ;
    }
    @Override
    public AnnotatedMethod<X> getAnnotated() {
        return ;
    }
New to GrepCode? Check out our FAQ X