Java 类javax.enterprise.inject.spi.Interceptor 实例源码

项目:tomee    文件:BeanContext.java   
private InterceptorData createInterceptorData(final Interceptor<?> i) {
    final InterceptorData data;
    if (CdiInterceptorBean.class.isInstance(i)) {
        final CdiInterceptorBean cdiInterceptorBean = CdiInterceptorBean.class.cast(i);

        data = new InterceptorData(i.getBeanClass());
        data.getAroundInvoke().addAll(getInterceptionMethodAsListOrEmpty(cdiInterceptorBean, InterceptionType.AROUND_INVOKE));
        data.getPostConstruct().addAll(getInterceptionMethodAsListOrEmpty(cdiInterceptorBean, InterceptionType.POST_CONSTRUCT));
        data.getPreDestroy().addAll(getInterceptionMethodAsListOrEmpty(cdiInterceptorBean, InterceptionType.PRE_DESTROY));
        data.getPostActivate().addAll(getInterceptionMethodAsListOrEmpty(cdiInterceptorBean, InterceptionType.POST_ACTIVATE));
        data.getPrePassivate().addAll(getInterceptionMethodAsListOrEmpty(cdiInterceptorBean, InterceptionType.PRE_PASSIVATE));
        data.getAroundTimeout().addAll(getInterceptionMethodAsListOrEmpty(cdiInterceptorBean, InterceptionType.AROUND_TIMEOUT));
        /*
        AfterBegin, BeforeCompletion and AfterCompletion are ignored since not handled by CDI
         */
    } else { // TODO: here we are not as good as in previous since we loose inheritance for instance
        data = InterceptorData.scan(i.getBeanClass());
    }
    return data;
}
项目:testee.fi    文件:EjbDescriptorImpl.java   
@SuppressWarnings("unchecked")
private <T> Object processInterceptorChain(
        final List<Interceptor<?>> chain,
        final Object target,
        final Method method,
        final Object[] args,
        final ContextFactory contextFactory,
        final InterceptorChain.ChainEnd<T> next,
        final InterceptionType interceptionType
) throws Throwable {
    if (chain.isEmpty()) {
        return next.invoke();
    }
    final Interceptor<Object> it = (Interceptor<Object>) chain.remove(0);
    final Releaser releaser = new Releaser();
    try {
        return intercept(
                it,
                it.create(contextFactory.create(it, releaser)),
                target,
                method,
                args,
                () -> processInterceptorChain(chain, target, method, args, contextFactory, next, interceptionType),
                interceptionType
        );
    } finally {
        releaser.release();
    }
}
项目:testee.fi    文件:EjbDescriptorImpl.java   
private <T> Object intercept(
        final Interceptor<T> it,
        final T instance,
        final Object target,
        final Method method,
        final Object[] args,
        final Proceed proceed,
        final InterceptionType interceptionType
) throws Exception {
    return it.intercept(
            interceptionType,
            instance,
            context(target, interceptionType == InterceptionType.AROUND_INVOKE ? method : null, args, proceed)
    );
}
项目:tomee    文件:WebappBeanManager.java   
@Override
public List<Interceptor<?>> resolveInterceptors(final InterceptionType type, final Annotation... interceptorBindings) {
    final List<Interceptor<?>> interceptors = super.resolveInterceptors(type, interceptorBindings);
    final List<Interceptor<?>> parentInterceptors = getParentBm().resolveInterceptors(type, interceptorBindings);
    for (final Interceptor<?> i : parentInterceptors) {
        if (!interceptors.contains(i)) {
            interceptors.add(i);
        }
    }
    return interceptors;
}
项目:deltaspike    文件:DeltaSpikeProxyInvocationHandler.java   
@Override
public Object invoke(Object proxy, Method method, Object[] parameters) throws Throwable
{
    // check if interceptors are defined, otherwise just call the original logik
    List<Interceptor<?>> interceptors = interceptorLookup.lookup(proxy, method);
    if (interceptors != null && !interceptors.isEmpty())
    {
        try
        {
            DeltaSpikeProxyInvocationContext invocationContext = new DeltaSpikeProxyInvocationContext(
                    this, beanManager, interceptors, proxy, method, parameters, null);

            Object returnValue = invocationContext.proceed();

            if (invocationContext.isProceedOriginal())
            {
                return invocationContext.getProceedOriginalReturnValue();
            }

            return returnValue;
        }
        catch (DeltaSpikeProxyInvocationWrapperException e)
        {
            throw e.getCause();
        }
    }

    return proceed(proxy, method, parameters);
}
项目:deltaspike    文件:DeltaSpikeProxyInvocationContext.java   
public DeltaSpikeProxyInvocationContext(DeltaSpikeProxyInvocationHandler invocationHandler,
        BeanManager beanManager, List<Interceptor<H>> interceptors, 
        T target, Method method, Object[] parameters, Object timer)
{
    super(target, method, parameters, timer);

    this.invocationHandler = invocationHandler;
    this.interceptors = interceptors;
    this.beanManager = beanManager;

    this.interceptorIndex = 0;
}
项目:deltaspike    文件:DeltaSpikeProxyInterceptorLookup.java   
public List<Interceptor<?>> lookup(Object instance, Method method)
{
    List<Interceptor<?>> interceptors = cache.get(method);

    if (interceptors == null)
    {
        interceptors = resolveInterceptors(instance, method);
        cache.put(method, interceptors);
    }

    return interceptors;
}
项目:deltaspike    文件:DeltaSpikeProxyInterceptorLookup.java   
private List<Interceptor<?>> resolveInterceptors(Object instance, Method method)
{
    BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager();

    Annotation[] interceptorBindings = extractInterceptorBindings(beanManager, instance, method);
    if (interceptorBindings.length > 0)
    {
        return beanManager.resolveInterceptors(InterceptionType.AROUND_INVOKE, interceptorBindings);
    }

    return new ArrayList<Interceptor<?>>();
}
项目:deltaspike    文件:ExceptionControlExtension.java   
/**
 * Listener to ProcessBean event to locate handlers.
 *
 * @param processBean current {@link AnnotatedType}
 * @param beanManager  Activated Bean Manager
 * @throws TypeNotPresentException if any of the actual type arguments refers to a non-existent type declaration
 *                                 when trying to obtain the actual type arguments from a
 *                                 {@link java.lang.reflect.ParameterizedType}
 * @throws java.lang.reflect.MalformedParameterizedTypeException
 *                                 if any of the actual type parameters refer to a parameterized type that cannot
 *                                 be instantiated for any reason when trying to obtain the actual type arguments
 *                                 from a {@link java.lang.reflect.ParameterizedType}
 */
@SuppressWarnings("UnusedDeclaration")
public <T> void findHandlers(@Observes final ProcessBean<?> processBean, final BeanManager beanManager)
{
    if (!isActivated)
    {
        return;
    }

    if (processBean.getBean() instanceof Interceptor || processBean.getBean() instanceof Decorator ||
            !(processBean.getAnnotated() instanceof AnnotatedType))
    {
        return;
    }

    AnnotatedType annotatedType = (AnnotatedType)processBean.getAnnotated();

    if (annotatedType.getJavaClass().isAnnotationPresent(ExceptionHandler.class))
    {
        final Set<AnnotatedMethod<? super T>> methods = annotatedType.getMethods();

        for (AnnotatedMethod<? super T> method : methods)
        {
            if (HandlerMethodImpl.isHandler(method))
            {
                if (method.getJavaMember().getExceptionTypes().length != 0)
                {
                    processBean.addDefinitionError(new IllegalArgumentException(
                        String.format("Handler method %s must not throw exceptions", method.getJavaMember())));
                }

                //beanManager won't be stored in the instance -> no issue with wls12c
                registerHandlerMethod(new HandlerMethodImpl(processBean.getBean(), method, beanManager));
            }
        }
    }
}
项目:weld-junit    文件:MockInterceptorTest.java   
@Test
public void testDisabledInterceptor() {
    List<Interceptor<?>> interceptors = weld.getBeanManager().resolveInterceptors(InterceptionType.AROUND_INVOKE, FooBinding.Literal.INSTANCE);
    assertEquals(1, interceptors.size());
    assertEquals(MockInterceptor.class, interceptors.get(0).getBeanClass());
}
项目:weld-junit    文件:MockInterceptorTest.java   
@Test
public void testDisabledInterceptor() {
    List<Interceptor<?>> interceptors = weld.getBeanManager().resolveInterceptors(InterceptionType.AROUND_INVOKE, FooBinding.Literal.INSTANCE);
    assertEquals(1, interceptors.size());
    assertEquals(MockInterceptor.class, interceptors.get(0).getBeanClass());
}
项目:tapestry-jpa-transactions    文件:NoopBeanManager.java   
@Override
public List<Interceptor<?>> resolveInterceptors(InterceptionType type, Annotation... interceptorBindings)
{
    // TODO Auto-generated method stub
    return null;
}
项目:jbromo    文件:BeanManagerExt.java   
@Override
public List<Interceptor<?>> resolveInterceptors(
        final InterceptionType arg0, final Annotation... arg1) {
    return this.beanManager.resolveInterceptors(arg0, arg1);
}
项目:tomee    文件:BeanContext.java   
private boolean isEjbInterceptor(final Interceptor<?> pc) {
    final Set<Annotation> interceptorBindings = pc.getInterceptorBindings();
    return interceptorBindings == null || interceptorBindings.isEmpty();
}