Search in sources :

Example 1 with PlainInterceptorFactory

use of org.jboss.weld.interceptor.reader.PlainInterceptorFactory in project core by weld.

the class Validator method validateInterceptors.

private void validateInterceptors(BeanManagerImpl beanManager, AbstractClassBean<?> classBean) {
    InterceptionModel interceptionModel = beanManager.getInterceptorModelRegistry().get(classBean.getAnnotated());
    if (interceptionModel != null) {
        Set<? extends InterceptorClassMetadata<?>> interceptors = interceptionModel.getAllInterceptors();
        if (interceptors.size() > 0) {
            boolean passivationCapabilityCheckRequired = beanManager.isPassivatingScope(classBean.getScope());
            for (InterceptorClassMetadata<?> interceptorMetadata : interceptors) {
                // in the case of CDI interceptors we only need to additionally validate passivation capability (if required)
                if (interceptorMetadata.getInterceptorFactory() instanceof CdiInterceptorFactory<?> && passivationCapabilityCheckRequired) {
                    CdiInterceptorFactory<?> cdiInterceptorFactory = (CdiInterceptorFactory<?>) interceptorMetadata.getInterceptorFactory();
                    Interceptor<?> interceptor = cdiInterceptorFactory.getInterceptor();
                    boolean isSerializable = (interceptor instanceof InterceptorImpl) ? ((InterceptorImpl<?>) interceptor).isSerializable() : Beans.isPassivationCapableDependency(interceptor);
                    if (!isSerializable) {
                        throw ValidatorLogger.LOG.passivatingBeanWithNonserializableInterceptor(classBean, interceptor);
                    }
                    if (interceptor instanceof InterceptorImpl) {
                        beanManager = ((InterceptorImpl<?>) interceptor).getBeanManager();
                    }
                    for (InjectionPoint injectionPoint : interceptor.getInjectionPoints()) {
                        Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(injectionPoint));
                        validateInterceptorDecoratorInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager, classBean);
                    }
                }
                if (interceptorMetadata.getInterceptorFactory() instanceof PlainInterceptorFactory<?>) {
                    PlainInterceptorFactory<?> factory = (PlainInterceptorFactory<?>) interceptorMetadata.getInterceptorFactory();
                    Class<?> interceptorClass = interceptorMetadata.getJavaClass();
                    if (passivationCapabilityCheckRequired && !Reflections.isSerializable(interceptorClass)) {
                        throw ValidatorLogger.LOG.passivatingBeanWithNonserializableInterceptor(this, interceptorClass.getName());
                    }
                    // if we can't get to the interceptor's BeanManager, we will use the bean's BM instead
                    InjectionTarget<?> injectionTarget = factory.getInjectionTarget();
                    if (injectionTarget instanceof BasicInjectionTarget<?>) {
                        beanManager = ((BasicInjectionTarget<?>) injectionTarget).getBeanManager();
                    }
                    for (InjectionPoint injectionPoint : factory.getInjectionTarget().getInjectionPoints()) {
                        validateInjectionPoint(injectionPoint, beanManager);
                        if (passivationCapabilityCheckRequired) {
                            Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(injectionPoint));
                            validateInterceptorDecoratorInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager, classBean);
                        }
                    }
                }
            }
        }
    }
}
Also used : InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) PlainInterceptorFactory(org.jboss.weld.interceptor.reader.PlainInterceptorFactory) InterceptionModel(org.jboss.weld.interceptor.spi.model.InterceptionModel) BasicInjectionTarget(org.jboss.weld.injection.producer.BasicInjectionTarget) CdiInterceptorFactory(org.jboss.weld.bean.interceptor.CdiInterceptorFactory) InterceptorImpl(org.jboss.weld.bean.InterceptorImpl)

Aggregations

InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 InterceptorImpl (org.jboss.weld.bean.InterceptorImpl)1 CdiInterceptorFactory (org.jboss.weld.bean.interceptor.CdiInterceptorFactory)1 BasicInjectionTarget (org.jboss.weld.injection.producer.BasicInjectionTarget)1 PlainInterceptorFactory (org.jboss.weld.interceptor.reader.PlainInterceptorFactory)1 InterceptionModel (org.jboss.weld.interceptor.spi.model.InterceptionModel)1