Search in sources :

Example 1 with BeanManagerImpl

use of org.jboss.weld.manager.BeanManagerImpl in project aries by apache.

the class HttpExtension method afterDeploymentValidation.

void afterDeploymentValidation(@Observes AfterDeploymentValidation adv, BeanManager beanManager) {
    processWebClasses();
    BeanManagerImpl beanManagerImpl = ((BeanManagerProxy) beanManager).delegate();
    Dictionary<String, Object> properties = new Hashtable<>();
    properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT, getSelectedContext());
    properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER, Boolean.TRUE.toString());
    properties.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE - 100);
    _registrations.add(_bundle.getBundleContext().registerService(LISTENER_CLASSES, new WeldInitialListener(beanManagerImpl), properties));
}
Also used : BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) Hashtable(java.util.Hashtable) BeanManagerProxy(org.jboss.weld.bean.builtin.BeanManagerProxy) WeldInitialListener(org.jboss.weld.servlet.WeldInitialListener)

Example 2 with BeanManagerImpl

use of org.jboss.weld.manager.BeanManagerImpl in project aries by apache.

the class ReferenceExtension method processInjectionTarget.

void processInjectionTarget(@Observes @SuppressWarnings("rawtypes") ProcessInjectionPoint pip, BeanManager manager) {
    InjectionPoint injectionPoint = pip.getInjectionPoint();
    Annotated annotated = injectionPoint.getAnnotated();
    Reference reference = annotated.getAnnotation(Reference.class);
    if (reference == null) {
        return;
    }
    try {
        BeanManagerImpl beanManagerImpl = ((BeanManagerProxy) manager).delegate();
        ReferenceDependency referenceDependency = new ReferenceDependency(beanManagerImpl, reference, injectionPoint);
        _referenceDependencies.add(referenceDependency);
        if (_log.isDebugEnabled()) {
            _log.debug("CDIe - Found OSGi service reference {}", referenceDependency);
        }
    } catch (Exception e) {
        if (_log.isErrorEnabled()) {
            _log.error("CDIe - Error on reference {}", reference, e);
        }
    }
}
Also used : Annotated(javax.enterprise.inject.spi.Annotated) ProcessInjectionPoint(javax.enterprise.inject.spi.ProcessInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) Reference(org.osgi.service.cdi.annotations.Reference) BeanManagerProxy(org.jboss.weld.bean.builtin.BeanManagerProxy)

Example 3 with BeanManagerImpl

use of org.jboss.weld.manager.BeanManagerImpl in project wildfly by wildfly.

the class Jsr299BindingsCreateInterceptor method processInvocation.

@Override
public Object processInvocation(InterceptorContext interceptorContext) throws Exception {
    BeanManagerImpl beanManager = this.beanManager;
    if (beanManager == null) {
        //cache the BM lookup, as it is quite slow
        beanManager = this.beanManager = this.weldContainer.getValue().getBeanManager(beanArchiveId);
    }
    //this is not always called with the deployments TCCL set
    //which causes weld to blow up
    SessionBean<Object> bean = null;
    if (ejbName != null) {
        EjbDescriptor<Object> descriptor = beanManager.getEjbDescriptor(this.ejbName);
        if (descriptor != null) {
            bean = beanManager.getBean(descriptor);
        }
    }
    InterceptorBindings interceptorBindings = this.interceptorBindings.getValue();
    final ComponentInstance componentInstance = interceptorContext.getPrivateData(ComponentInstance.class);
    InterceptorInstances existing = interceptorSupport.getInterceptorInstances(componentInstance);
    if (existing == null) {
        CreationalContext<Object> creationalContext = beanManager.createCreationalContext(bean);
        HashMap<String, SerializableContextualInstance<Interceptor<Object>, Object>> interceptorInstances = new HashMap<String, SerializableContextualInstance<Interceptor<Object>, Object>>();
        if (interceptorBindings != null) {
            for (Interceptor<?> interceptor : interceptorBindings.getAllInterceptors()) {
                addInterceptorInstance((Interceptor<Object>) interceptor, beanManager, interceptorInstances, creationalContext);
            }
        }
        interceptorSupport.setInterceptorInstances(componentInstance, new WeldInterceptorInstances(creationalContext, interceptorInstances));
    }
    return interceptorContext.proceed();
}
Also used : HashMap(java.util.HashMap) InterceptorInstances(org.jboss.as.weld.spi.InterceptorInstances) SerializableContextualInstance(org.jboss.weld.serialization.spi.helpers.SerializableContextualInstance) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) InterceptorBindings(org.jboss.weld.ejb.spi.InterceptorBindings) ComponentInstance(org.jboss.as.ee.component.ComponentInstance) Interceptor(javax.enterprise.inject.spi.Interceptor)

Example 4 with BeanManagerImpl

use of org.jboss.weld.manager.BeanManagerImpl in project wildfly by wildfly.

the class WeldClassIntrospector method getInjectionTarget.

private InjectionTarget getInjectionTarget(Class<?> clazz) {
    InjectionTarget<?> target = injectionTargets.get(clazz);
    if (target != null) {
        return target;
    }
    final BeanManagerImpl beanManager = BeanManagerProxy.unwrap(this.beanManager.getValue());
    Bean<?> bean = null;
    Set<Bean<?>> beans = new HashSet<>(beanManager.getBeans(clazz, AnyLiteral.INSTANCE));
    Iterator<Bean<?>> it = beans.iterator();
    //go through and remove them from the bean set
    while (it.hasNext()) {
        Bean<?> b = it.next();
        if (b.getBeanClass() != clazz) {
            it.remove();
        }
    }
    if (beans.size() == 1) {
        bean = beans.iterator().next();
    }
    InjectionTarget<?> newTarget = InjectionTargets.createInjectionTarget(clazz, bean, beanManager, true);
    target = injectionTargets.putIfAbsent(clazz, newTarget);
    if (target == null) {
        return newTarget;
    } else {
        return target;
    }
}
Also used : BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) HashSet(java.util.HashSet) Bean(javax.enterprise.inject.spi.Bean)

Example 5 with BeanManagerImpl

use of org.jboss.weld.manager.BeanManagerImpl in project wildfly by wildfly.

the class WeldInterceptorBindingsService method start.

@Override
public void start(StartContext startContext) throws StartException {
    BeanManagerImpl beanManager = this.weldContainer.getValue().getBeanManager(beanArchiveId);
    //this is not always called with the deployments TCCL set
    //which causes weld to blow up
    interceptorBindings = getInterceptorBindings(this.ejbName, beanManager);
}
Also used : BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl)

Aggregations

BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)6 BeanManagerProxy (org.jboss.weld.bean.builtin.BeanManagerProxy)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Hashtable (java.util.Hashtable)1 Annotated (javax.enterprise.inject.spi.Annotated)1 Bean (javax.enterprise.inject.spi.Bean)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 Interceptor (javax.enterprise.inject.spi.Interceptor)1 ProcessInjectionPoint (javax.enterprise.inject.spi.ProcessInjectionPoint)1 ComponentInstance (org.jboss.as.ee.component.ComponentInstance)1 InterceptorInstances (org.jboss.as.weld.spi.InterceptorInstances)1 WeldBootstrap (org.jboss.weld.bootstrap.WeldBootstrap)1 InterceptorBindings (org.jboss.weld.ejb.spi.InterceptorBindings)1 SerializableContextualInstance (org.jboss.weld.serialization.spi.helpers.SerializableContextualInstance)1 WeldInitialListener (org.jboss.weld.servlet.WeldInitialListener)1 Reference (org.osgi.service.cdi.annotations.Reference)1