Search in sources :

Example 1 with BeanAttributes

use of javax.enterprise.inject.spi.BeanAttributes in project core by weld.

the class ProbeExtension method processBeanAttributes.

public <T> void processBeanAttributes(@Observes ProcessBeanAttributes<T> event, BeanManager beanManager) {
    probe.getBootstrapStats().increment(EventType.PBA);
    final BeanAttributes<T> beanAttributes = event.getBeanAttributes();
    final WeldManager weldManager = (WeldManager) beanManager;
    if (isMonitored(event.getAnnotated(), beanAttributes, weldManager)) {
        event.setBeanAttributes(new ForwardingBeanAttributes<T>() {

            @Override
            public Set<Class<? extends Annotation>> getStereotypes() {
                return ImmutableSet.<Class<? extends Annotation>>builder().addAll(attributes().getStereotypes()).add(MonitoredComponent.class).build();
            }

            @Override
            protected BeanAttributes<T> attributes() {
                return beanAttributes;
            }

            @Override
            public String toString() {
                return beanAttributes.toString();
            }
        });
        ProbeLogger.LOG.monitoringStereotypeAdded(event.getAnnotated());
    }
    if (eventMonitorContainerLifecycleEvents) {
        addContainerLifecycleEvent(event, "Types: [" + Formats.formatTypes(event.getBeanAttributes().getTypes()) + "], qualifiers: [" + Formats.formatAnnotations(event.getBeanAttributes().getQualifiers()) + "]", beanManager);
    }
}
Also used : ImmutableSet(org.jboss.weld.util.collections.ImmutableSet) Set(java.util.Set) ForwardingBeanAttributes(org.jboss.weld.util.bean.ForwardingBeanAttributes) ProcessBeanAttributes(javax.enterprise.inject.spi.ProcessBeanAttributes) BeanAttributes(javax.enterprise.inject.spi.BeanAttributes) Annotation(java.lang.annotation.Annotation) WeldManager(org.jboss.weld.manager.api.WeldManager)

Example 2 with BeanAttributes

use of javax.enterprise.inject.spi.BeanAttributes in project wildfly-swarm by wildfly-swarm.

the class MPJWTExtension method addTypeToClaimProducer.

/**
 * Replace the general producer method BeanAttributes with one bound to the collected injection site
 * types to properly reflect all of the type locations the producer method applies to.
 *
 * @param pba the ProcessBeanAttributes
 * @see ClaimProviderBeanAttributes
 */
public void addTypeToClaimProducer(@Observes ProcessBeanAttributes pba) {
    if (pba.getAnnotated().isAnnotationPresent(Claim.class)) {
        Claim claim = pba.getAnnotated().getAnnotation(Claim.class);
        if (claim.value().length() == 0 && claim.standard() == Claims.UNKNOWN) {
            log.debugf("addTypeToClaimProducer: %s\n", pba.getAnnotated());
            BeanAttributes delegate = pba.getBeanAttributes();
            String name = delegate.getName();
            if (delegate.getTypes().contains(Optional.class)) {
                if (providerOptionalTypes.size() == 0) {
                    providerOptionalTypes.add(Optional.class);
                }
                pba.setBeanAttributes(new ClaimProviderBeanAttributes(delegate, providerOptionalTypes, providerQualifiers));
            // This is
            } else if (name != null && name.startsWith("RawClaimTypeProducer#")) {
                if (rawTypes.size() == 0) {
                    rawTypes.add(Object.class);
                }
                pba.setBeanAttributes(new ClaimProviderBeanAttributes(delegate, rawTypes, rawTypeQualifiers));
                log.debugf("Setup RawClaimTypeProducer BeanAttributes");
            }
        }
    }
}
Also used : BeanAttributes(javax.enterprise.inject.spi.BeanAttributes) ProcessBeanAttributes(javax.enterprise.inject.spi.ProcessBeanAttributes) Claim(org.eclipse.microprofile.jwt.Claim)

Example 3 with BeanAttributes

use of javax.enterprise.inject.spi.BeanAttributes in project HotswapAgent by HotswapProjects.

the class BeanReloadExecutor method doDefineNewManagedBean.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static void doDefineNewManagedBean(BeanManagerImpl beanManager, String bdaId, Class<?> beanClass) {
    try {
        ClassTransformer classTransformer = getClassTransformer();
        SlimAnnotatedType<?> annotatedType = classTransformer.getBackedAnnotatedType(beanClass, bdaId);
        boolean managedBeanOrDecorator = Beans.isTypeManagedBeanOrDecoratorOrInterceptor(annotatedType);
        if (managedBeanOrDecorator) {
            EnhancedAnnotatedType eat = EnhancedAnnotatedTypeImpl.of(annotatedType, classTransformer);
            BeanAttributes attributes = BeanAttributesFactory.forBean(eat, beanManager);
            ManagedBean<?> bean = ManagedBean.of(attributes, eat, beanManager);
            ReflectionHelper.set(beanManager, beanManager.getClass(), "beanSet", Collections.synchronizedSet(new HashSet<Bean<?>>()));
            beanManager.addBean(bean);
            beanManager.getBeanResolver().clear();
            bean.initializeAfterBeanDiscovery();
            LOGGER.debug("Bean defined '{}'", beanClass.getName());
        } else {
            // TODO : define session bean
            LOGGER.warning("Bean NOT? defined '{}', session bean?", beanClass.getName());
        }
    } catch (Exception e) {
        LOGGER.debug("Bean definition failed.", e);
    }
}
Also used : EnhancedAnnotatedType(org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType) BeanAttributes(javax.enterprise.inject.spi.BeanAttributes) ClassTransformer(org.jboss.weld.resources.ClassTransformer) ContextNotActiveException(org.jboss.weld.context.ContextNotActiveException) HashSet(java.util.HashSet)

Aggregations

BeanAttributes (javax.enterprise.inject.spi.BeanAttributes)3 ProcessBeanAttributes (javax.enterprise.inject.spi.ProcessBeanAttributes)2 Annotation (java.lang.annotation.Annotation)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Claim (org.eclipse.microprofile.jwt.Claim)1 EnhancedAnnotatedType (org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType)1 ContextNotActiveException (org.jboss.weld.context.ContextNotActiveException)1 WeldManager (org.jboss.weld.manager.api.WeldManager)1 ClassTransformer (org.jboss.weld.resources.ClassTransformer)1 ForwardingBeanAttributes (org.jboss.weld.util.bean.ForwardingBeanAttributes)1 ImmutableSet (org.jboss.weld.util.collections.ImmutableSet)1