Search in sources :

Example 1 with InterceptorImpl

use of org.jboss.weld.bean.InterceptorImpl in project Payara by payara.

the class JCDIServiceImpl method getAroundConstructInterceptorInstance.

private <T> T getAroundConstructInterceptorInstance(Interceptor<T> interceptor, CreationalContext<T> creationalContext) {
    T instance = null;
    if (creationalContext instanceof CreationalContextImpl<?>) {
        CreationalContextImpl<T> weldContext = Reflections.cast(creationalContext);
        @SuppressWarnings("unchecked") InterceptorImpl<T> interceptorImpl = (InterceptorImpl) interceptor;
        InterceptorClassMetadata<T> interceptorClassMetadata = interceptorImpl.getInterceptorMetadata();
        InterceptionContext interceptionContext = weldContext.getAroundConstructInterceptionContext();
        instance = interceptionContext.getInterceptorInstance(interceptorClassMetadata);
    }
    return instance;
}
Also used : InterceptionContext(org.jboss.weld.interceptor.proxy.InterceptionContext) CreationalContextImpl(org.jboss.weld.contexts.CreationalContextImpl) InterceptorImpl(org.jboss.weld.bean.InterceptorImpl)

Example 2 with InterceptorImpl

use of org.jboss.weld.bean.InterceptorImpl 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)

Example 3 with InterceptorImpl

use of org.jboss.weld.bean.InterceptorImpl in project core by weld.

the class WeldStartup method endInitialization.

public void endInitialization() {
    tracker.start(Tracker.OP_END_INIT);
    final BeanIdentifierIndex index = deploymentManager.getServices().get(BeanIdentifierIndex.class);
    if (index != null) {
        // Build a special index of bean identifiers
        index.build(getBeansForBeanIdentifierIndex());
    }
    // Register the managers so external requests can handle them
    // clear the TypeSafeResolvers, so data that is only used at startup
    // is not kept around using up memory
    flushCaches();
    deploymentManager.getServices().cleanupAfterBoot();
    deploymentManager.cleanupAfterBoot();
    for (BeanDeployment beanDeployment : getBeanDeployments()) {
        BeanManagerImpl beanManager = beanDeployment.getBeanManager();
        beanManager.getInterceptorMetadataReader().cleanAfterBoot();
        beanManager.getServices().cleanupAfterBoot();
        beanManager.cleanupAfterBoot();
        // clean up beans
        for (Bean<?> bean : beanManager.getBeans()) {
            if (bean instanceof RIBean<?>) {
                RIBean<?> riBean = (RIBean<?>) bean;
                riBean.cleanupAfterBoot();
            }
        }
        // clean up decorators
        for (Decorator<?> decorator : beanManager.getDecorators()) {
            if (decorator instanceof DecoratorImpl<?>) {
                Reflections.<DecoratorImpl<?>>cast(decorator).cleanupAfterBoot();
            }
        }
        // clean up interceptors
        for (Interceptor<?> interceptor : beanManager.getInterceptors()) {
            if (interceptor instanceof InterceptorImpl<?>) {
                Reflections.<InterceptorImpl<?>>cast(interceptor).cleanupAfterBoot();
            }
        }
    }
    for (BeanDeployment beanDeployment : getBeanDeployments()) {
        beanDeployment.getBeanDeployer().cleanup();
    }
    // feed BeanDeploymentModule registry
    final BeanDeploymentModules modules = deploymentManager.getServices().get(BeanDeploymentModules.class);
    if (modules != null) {
        modules.processBeanDeployments(getBeanDeployments());
        BootstrapLogger.LOG.debugv("EE modules: {0}", modules);
    }
    getContainer().setState(ContainerState.INITIALIZED);
    if (modules != null) {
        // web modules are handled by HttpContextLifecycle
        for (BeanDeploymentModule module : modules) {
            if (!module.isWebModule()) {
                module.fireEvent(Object.class, ContextEvent.APPLICATION_INITIALIZED, InitializedLiteral.APPLICATION);
            }
        }
    }
    tracker.close();
}
Also used : BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) DecoratorImpl(org.jboss.weld.bean.DecoratorImpl) RIBean(org.jboss.weld.bean.RIBean) BeanIdentifierIndex(org.jboss.weld.serialization.BeanIdentifierIndex) InterceptorImpl(org.jboss.weld.bean.InterceptorImpl)

Aggregations

InterceptorImpl (org.jboss.weld.bean.InterceptorImpl)3 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 DecoratorImpl (org.jboss.weld.bean.DecoratorImpl)1 RIBean (org.jboss.weld.bean.RIBean)1 CdiInterceptorFactory (org.jboss.weld.bean.interceptor.CdiInterceptorFactory)1 CreationalContextImpl (org.jboss.weld.contexts.CreationalContextImpl)1 BasicInjectionTarget (org.jboss.weld.injection.producer.BasicInjectionTarget)1 InterceptionContext (org.jboss.weld.interceptor.proxy.InterceptionContext)1 PlainInterceptorFactory (org.jboss.weld.interceptor.reader.PlainInterceptorFactory)1 InterceptionModel (org.jboss.weld.interceptor.spi.model.InterceptionModel)1 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)1 BeanIdentifierIndex (org.jboss.weld.serialization.BeanIdentifierIndex)1