Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jboss.weld.interceptor.reader;
  
  import java.util.List;
  import java.util.Map;
  
  
 

Author(s):
Marius Bogoevici
Marko Luksa
 
 public class InterceptorMetadataUtils {
     protected static final String OBJECT_CLASS_NAME = Object.class.getName();
 
     private InterceptorMetadataUtils() {
     }
 
     public static boolean isInterceptorMethod(InterceptionType interceptionTypeMethod methodboolean forTargetClass) {
         if (interceptionType.isLifecycleCallback()) {
             if (forTargetClass) {
                 return isValidTargetClassLifecycleInterceptorMethod(interceptionTypemethod);
             } else {
                 return isValidInterceptorClassLifecycleInterceptorMethod(interceptionTypemethod);
             }
         } else {
             return isValidBusinessMethodInterceptorMethod(interceptionTypemethod);
         }
     }
 
     private static boolean isValidTargetClassLifecycleInterceptorMethod(InterceptionType interceptionTypeMethod method) {
         /*
          * This check is relaxed (WELD-1399) because we are not able to distinguish a CDI managed bean from
          * an interceptor class bound using @Interceptors.
          *
          * This will be revisited as part of https://issues.jboss.org/browse/WELD-1401
          *
         if (interceptionType == InterceptionType.AROUND_CONSTRUCT) {
             throw new DefinitionException(ValidatorMessage.AROUND_CONSTRUCT_INTERCEPTOR_METHOD_NOT_ALLOWED_ON_TARGET_CLASS,
                     javaMethod.getName(), javaMethod.getDeclaringClass().getName(),
                     interceptionType.annotationClassName());
         }
         */
         /*
          * Again, we relax the check and allow both void and Object return types as we cannot distinguish between
          * a managed bean and an interceptor class.
          */
         if (!..equals(method.getReturnType()) && !Object.class.equals(method.getReturnType())) {
                     method.getName(), method.getDeclaringClass().getName(),
                     interceptionType.annotationClassName(), ..getName());
         }
         Class<?>[] parameterTypes = method.getParameterTypes();
         if (parameterTypes.length > 1) {
                     method.getName(), method.getDeclaringClass().getName(),
                     interceptionType.annotationClassName());
         }
         Class<?>[] exceptionTypes = method.getExceptionTypes();
         if (exceptionTypes.length != 0) {
             for (Class<?> exceptionType : exceptionTypes) {
                 if (!RuntimeException.class.isAssignableFrom(exceptionType)) {
                             method.getName(), method.getDeclaringClass().getName(),
                             exceptionType.getName());
                 }
             }
         }
 
         return parameterTypes.length == 0;
     }
 
     private static boolean isValidInterceptorClassLifecycleInterceptorMethod(InterceptionType interceptionTypeMethod method) {
         if (!Object.class.equals(method.getReturnType()) && !..equals(method.getReturnType())) {
                     method.getName(), method.getDeclaringClass().getName(),
                     interceptionType.annotationClassName(), ..getName(), );
         }
 
         Class<?>[] parameterTypes = method.getParameterTypes();
         if (parameterTypes.length == 0) {
             return false;
         } else if (parameterTypes.length == 1) {
             if (InvocationContext.class.isAssignableFrom(parameterTypes[0])) {
                 return true;
             }
                     method.getName(), method.getDeclaringClass().getName(),
                     interceptionType.annotationClassName(), InvocationContext.class.getName());
        } else {
                    method.getName(), method.getDeclaringClass().getName(),
                    interceptionType.annotationClassName());
        }
    }
    private static boolean isValidBusinessMethodInterceptorMethod(InterceptionType interceptionTypeMethod method) {
        if (!Object.class.equals(method.getReturnType())) {
                    method.getName(), method.getDeclaringClass().getName(),
                    interceptionType.annotationClassName(), );
        }
        Class<?>[] parameterTypes = method.getParameterTypes();
        if (parameterTypes.length != 1) {
                    method.getName(), method.getDeclaringClass().getName(),
                    interceptionType.annotationClassName());
        }
        if (!InvocationContext.class.isAssignableFrom(parameterTypes[0])) {
                    method.getName(), method.getDeclaringClass().getName(),
                    interceptionType.annotationClassName(), InvocationContext.class.getName());
        }
        return true;
    }
    public static Map<InterceptionTypeList<Method>> buildMethodMap(EnhancedAnnotatedType<?> typeboolean forTargetClassBeanManagerImpl manager) {
        ImmutableMap.Builder<InterceptionTypeList<Method>> builder = null;
        for (InterceptionType interceptionType : InterceptionTypeRegistry.getSupportedInterceptionTypes()) {
            List<Methodvalue = BeanMethods.getInterceptorMethods(typeinterceptionTypeforTargetClass);
            if (!value.isEmpty()) {
                if (builder == null) {
                    builder = ImmutableMap.builder();
                }
                builder.put(interceptionTypevalue);
            }
        }
        if (builder == null) {
            return Collections.emptyMap();
        }
        return builder.build();
    }
New to GrepCode? Check out our FAQ X