Search in sources :

Example 6 with InterceptionModel

use of org.jboss.weld.interceptor.spi.model.InterceptionModel in project core by weld.

the class ManagedBean method initHasPostConstructCallback.

private boolean initHasPostConstructCallback(InjectionTarget<T> producer) {
    if (producer instanceof BasicInjectionTarget<?>) {
        BasicInjectionTarget<?> weldProducer = (BasicInjectionTarget<?>) producer;
        final InterceptionModel interceptors = getInterceptors();
        if (interceptors == null || interceptors.getInterceptors(InterceptionType.POST_CONSTRUCT, null).isEmpty()) {
            if (!weldProducer.getLifecycleCallbackInvoker().hasPostConstructCallback()) {
                return false;
            }
        }
    }
    // otherwise we assume there is a post construct callback, just to be safe
    return true;
}
Also used : InterceptionModel(org.jboss.weld.interceptor.spi.model.InterceptionModel) BasicInjectionTarget(org.jboss.weld.injection.producer.BasicInjectionTarget)

Example 7 with InterceptionModel

use of org.jboss.weld.interceptor.spi.model.InterceptionModel in project core by weld.

the class EjbSupportImpl method registerCdiInterceptorsForMessageDrivenBeans.

public void registerCdiInterceptorsForMessageDrivenBeans(BeanDeployerEnvironment environment, BeanManagerImpl manager) {
    for (InternalEjbDescriptor<?> descriptor : getEjbDescriptors()) {
        if (descriptor.isMessageDriven()) {
            EnhancedAnnotatedType<?> type = manager.getServices().getRequired(ClassTransformer.class).getEnhancedAnnotatedType(descriptor.getBeanClass(), manager.getId());
            if (!manager.getInterceptorModelRegistry().containsKey(type.slim())) {
                InterceptionModelInitializer.of(manager, type, null).init();
            }
            InterceptionModel model = manager.getInterceptorModelRegistry().get(type.slim());
            if (model != null) {
                ejbServices.registerInterceptors(descriptor.delegate(), new InterceptorBindingsAdapter(model));
            }
        }
    }
}
Also used : InterceptorBindingsAdapter(org.jboss.weld.bean.interceptor.InterceptorBindingsAdapter) ClassTransformer(org.jboss.weld.resources.ClassTransformer) InterceptionModel(org.jboss.weld.interceptor.spi.model.InterceptionModel)

Example 8 with InterceptionModel

use of org.jboss.weld.interceptor.spi.model.InterceptionModel in project core by weld.

the class EjbSupportImpl method createMessageDrivenInjectionTarget.

@Override
public <T> BasicInjectionTarget<T> createMessageDrivenInjectionTarget(EnhancedAnnotatedType<T> type, EjbDescriptor<T> d, BeanManagerImpl manager) {
    InternalEjbDescriptor<T> descriptor = InternalEjbDescriptor.of(d);
    EnhancedAnnotatedType<T> implementationClass = SessionBeans.getEjbImplementationClass(descriptor, manager, type);
    Instantiator<T> instantiator = null;
    if (type.equals(implementationClass)) {
        instantiator = new DefaultInstantiator<T>(type, null, manager);
    } else {
        // Session bean subclassed by the EJB container
        instantiator = SubclassedComponentInstantiator.forSubclassedEjb(type, implementationClass, null, manager);
    }
    InterceptionModel interceptionModel = manager.getInterceptorModelRegistry().get(type.slim());
    if (interceptionModel != null) {
        if (interceptionModel.hasExternalNonConstructorInterceptors()) {
            instantiator = SubclassedComponentInstantiator.forInterceptedDecoratedBean(implementationClass, null, (AbstractInstantiator<T>) instantiator, manager);
            instantiator = new InterceptorApplyingInstantiator<>(instantiator, interceptionModel, type.slim());
        }
        if (interceptionModel.hasExternalConstructorInterceptors()) {
            instantiator = new ConstructorInterceptionInstantiator<>(instantiator, interceptionModel, type.slim());
        }
    }
    return BasicInjectionTarget.createDefault(type, null, manager, instantiator);
}
Also used : AbstractInstantiator(org.jboss.weld.injection.producer.AbstractInstantiator) InterceptionModel(org.jboss.weld.interceptor.spi.model.InterceptionModel)

Example 9 with InterceptionModel

use of org.jboss.weld.interceptor.spi.model.InterceptionModel in project core by weld.

the class SubclassedComponentDescriptorTest method testInterceptionModelForConstructor.

@Test
public void testInterceptionModelForConstructor() {
    BasicInjectionTarget<?> it = (BasicInjectionTarget<?>) manager.createInjectionTarget(manager.getEjbDescriptor(Foo.class.getSimpleName()));
    InterceptionModel model = manager.getInterceptorModelRegistry().get(it.getAnnotated());
    assertNotNull(model);
    assertTrue(model.hasExternalConstructorInterceptors());
}
Also used : InterceptionModel(org.jboss.weld.interceptor.spi.model.InterceptionModel) BasicInjectionTarget(org.jboss.weld.injection.producer.BasicInjectionTarget) Test(org.testng.annotations.Test)

Example 10 with InterceptionModel

use of org.jboss.weld.interceptor.spi.model.InterceptionModel 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

InterceptionModel (org.jboss.weld.interceptor.spi.model.InterceptionModel)12 BasicInjectionTarget (org.jboss.weld.injection.producer.BasicInjectionTarget)3 Type (java.lang.reflect.Type)2 HashSet (java.util.HashSet)2 Decorator (javax.enterprise.inject.spi.Decorator)2 SlimAnnotatedType (org.jboss.weld.annotated.slim.SlimAnnotatedType)2 InterceptorBindingsAdapter (org.jboss.weld.bean.interceptor.InterceptorBindingsAdapter)2 InterceptionType (org.jboss.weld.interceptor.spi.model.InterceptionType)2 ClassTransformer (org.jboss.weld.resources.ClassTransformer)2 TemplatesImpl (com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl)1 Annotation (java.lang.annotation.Annotation)1 Constructor (java.lang.reflect.Constructor)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Bean (javax.enterprise.inject.spi.Bean)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 Interceptor (javax.enterprise.inject.spi.Interceptor)1 ProcessAnnotatedType (javax.enterprise.inject.spi.ProcessAnnotatedType)1 ProcessSyntheticAnnotatedType (javax.enterprise.inject.spi.ProcessSyntheticAnnotatedType)1 EnhancedAnnotatedType (org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType)1 MethodSignature (org.jboss.weld.annotated.enhanced.MethodSignature)1