private static List<InterceptorMethodInvocation> buildInterceptorMethodInvocations(
     Object instance,
     Method method,
     Object[] args,
     InterceptionType interceptionType,
     InterceptionContext ctx) {
   List<? extends InterceptorClassMetadata<?>> interceptorList =
       ctx.getInterceptionModel().getInterceptors(interceptionType, method);
   List<InterceptorMethodInvocation> interceptorInvocations =
       new ArrayList<InterceptorMethodInvocation>(interceptorList.size());
   for (InterceptorClassMetadata<?> interceptorMetadata : interceptorList) {
     interceptorInvocations.addAll(
         interceptorMetadata
             .getInterceptorInvocation(
                 ctx.getInterceptorInstance(interceptorMetadata), interceptionType)
             .getInterceptorMethodInvocations());
   }
   TargetClassInterceptorMetadata targetClassInterceptorMetadata =
       ctx.getInterceptionModel().getTargetClassInterceptorMetadata();
   if (targetClassInterceptorMetadata != null
       && targetClassInterceptorMetadata.isEligible(interceptionType)) {
     interceptorInvocations.addAll(
         targetClassInterceptorMetadata
             .getInterceptorInvocation(instance, interceptionType)
             .getInterceptorMethodInvocations());
   }
   return interceptorInvocations;
 }
 private static List<InterceptorMethodInvocation> buildInterceptorMethodInvocations(
     List<InterceptorClassMetadata<?>> interceptorMetadata,
     InterceptionContext ctx,
     InterceptionType interceptionType) {
   List<InterceptorMethodInvocation> interceptorInvocations =
       new ArrayList<InterceptorMethodInvocation>(interceptorMetadata.size());
   for (InterceptorClassMetadata<?> metadata : interceptorMetadata) {
     Object interceptorInstance = ctx.getInterceptorInstance(metadata);
     InterceptorInvocation invocation =
         metadata.getInterceptorInvocation(interceptorInstance, interceptionType);
     interceptorInvocations.addAll(invocation.getInterceptorMethodInvocations());
   }
   return interceptorInvocations;
 }
Exemple #3
0
  @Override
  public Object intercept(InterceptionType type, T instance, final InvocationContext ctx) {
    final org.jboss.weld.interceptor.spi.model.InterceptionType interceptionType =
        org.jboss.weld.interceptor.spi.model.InterceptionType.valueOf(type.name());
    final List<InterceptorMethodInvocation> methodInvocations =
        interceptorMetadata
            .getInterceptorInvocation(instance, interceptionType)
            .getInterceptorMethodInvocations();

    Set<Annotation> interceptorBindings = null;
    if (ctx instanceof ExperimentalInvocationContext) {
      interceptorBindings =
          Reflections.<ExperimentalInvocationContext>cast(ctx).getInterceptorBindings();
    }

    try {
      /*
       * Calling Interceptor.intercept() may result in multiple interceptor method invocations (provided the interceptor class
       * interceptor methods on superclasses). This requires cooperation with InvocationContext.
       *
       * We use a wrapper InvocationContext for the purpose of executing the chain of
       * interceptor methods of this interceptor.
       */
      return new WeldInvocationContext(ctx, methodInvocations, interceptorBindings, null).proceed();
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw new WeldException(e);
    }
  }
Exemple #4
0
 private void checkInterceptorBindings() {
   if (interceptorMetadata.isEligible(
           org.jboss.weld.interceptor.spi.model.InterceptionType.POST_CONSTRUCT)
       || interceptorMetadata.isEligible(
           org.jboss.weld.interceptor.spi.model.InterceptionType.PRE_DESTROY)
       || interceptorMetadata.isEligible(
           org.jboss.weld.interceptor.spi.model.InterceptionType.POST_ACTIVATE)
       || interceptorMetadata.isEligible(
           org.jboss.weld.interceptor.spi.model.InterceptionType.PRE_PASSIVATE)) {
     for (Annotation interceptorBindingType : interceptorBindingTypes) {
       Target target = interceptorBindingType.annotationType().getAnnotation(Target.class);
       if (target != null
           && Arrays2.unorderedEquals(target.value(), ElementType.TYPE, ElementType.METHOD)) {
         throw ReflectionLogger.LOG.methodElementTypeNotAllowed(
             this, interceptorBindingType.annotationType());
       }
     }
   }
 }
Exemple #5
0
 @Override
 public boolean intercepts(InterceptionType type) {
   return interceptorMetadata.isEligible(
       org.jboss.weld.interceptor.spi.model.InterceptionType.valueOf(type.name()));
 }