Search in sources :

Example 21 with AnnotatedType

use of javax.enterprise.inject.spi.AnnotatedType in project deltaspike by apache.

the class DefaultMockFilter method isMockedImplementationSupported.

@Override
public boolean isMockedImplementationSupported(BeanManager beanManager, Annotated annotated) {
    if (!isMockSupportEnabled(annotated)) {
        return false;
    }
    Class origin = null;
    if (annotated instanceof AnnotatedType) {
        origin = ((AnnotatedType) annotated).getJavaClass();
        Set<Annotation> annotations = new HashSet<Annotation>();
        annotations.addAll(annotated.getAnnotations());
        for (AnnotatedMethod annotatedMethod : (Set<javax.enterprise.inject.spi.AnnotatedMethod>) ((AnnotatedType) annotated).getMethods()) {
            annotations.addAll(annotatedMethod.getAnnotations());
        }
        if (isEjbOrAnnotatedTypeWithInterceptorAnnotation(beanManager, annotations, origin.getName())) {
            return false;
        }
    } else if (annotated instanceof AnnotatedMember) {
        Member member = ((AnnotatedMember) annotated).getJavaMember();
        origin = member.getDeclaringClass();
        if (isEjbOrAnnotatedTypeWithInterceptorAnnotation(beanManager, annotated.getAnnotations(), member.toString())) {
            return false;
        }
    }
    if (origin != null && origin.getPackage() == null) {
        LOG.warning("Please don't use the default-package for " + origin.getName());
        return true;
    }
    return origin != null && !isInternalPackage(origin.getPackage().getName());
}
Also used : AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) Set(java.util.Set) HashSet(java.util.HashSet) AnnotatedMethod(javax.enterprise.inject.spi.AnnotatedMethod) AnnotatedMember(javax.enterprise.inject.spi.AnnotatedMember) AnnotatedMember(javax.enterprise.inject.spi.AnnotatedMember) Member(java.lang.reflect.Member) Annotation(java.lang.annotation.Annotation) HashSet(java.util.HashSet)

Example 22 with AnnotatedType

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

the class BeanClassRefreshAgent method createAnnotatedTypeForExistingBeanClass.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static void createAnnotatedTypeForExistingBeanClass(BeanManagerImpl beanManager, Class<?> beanClass, InjectionTargetBean bean) {
    WebBeansContext wbc = beanManager.getWebBeansContext();
    AnnotatedElementFactory annotatedElementFactory = wbc.getAnnotatedElementFactory();
    // Clear AnnotatedElementFactory caches
    annotatedElementFactory.clear();
    AnnotatedType annotatedType = annotatedElementFactory.newAnnotatedType(beanClass);
    ReflectionHelper.set(bean, InjectionTargetBean.class, "annotatedType", annotatedType);
    // Updated members that were set by bean attributes
    BeanAttributesImpl attributes = BeanAttributesBuilder.forContext(wbc).newBeanAttibutes(annotatedType).build();
    ReflectionHelper.set(bean, BeanAttributesImpl.class, "types", attributes.getTypes());
    ReflectionHelper.set(bean, BeanAttributesImpl.class, "qualifiers", attributes.getQualifiers());
    ReflectionHelper.set(bean, BeanAttributesImpl.class, "scope", attributes.getScope());
    ReflectionHelper.set(bean, BeanAttributesImpl.class, "name", attributes.getName());
    ReflectionHelper.set(bean, BeanAttributesImpl.class, "stereotypes", attributes.getStereotypes());
    ReflectionHelper.set(bean, BeanAttributesImpl.class, "alternative", attributes.isAlternative());
    InjectionTargetFactory factory = new InjectionTargetFactoryImpl(annotatedType, bean.getWebBeansContext());
    InjectionTarget injectionTarget = factory.createInjectionTarget(bean);
    ReflectionHelper.set(bean, InjectionTargetBean.class, "injectionTarget", injectionTarget);
    LOGGER.debug("New annotated type created for bean '{}'", beanClass.getName());
}
Also used : AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) WebBeansContext(org.apache.webbeans.config.WebBeansContext) BeanAttributesImpl(org.apache.webbeans.component.BeanAttributesImpl) InjectionTargetFactory(javax.enterprise.inject.spi.InjectionTargetFactory) InjectionTarget(javax.enterprise.inject.spi.InjectionTarget) AnnotatedElementFactory(org.apache.webbeans.portable.AnnotatedElementFactory) InjectionTargetFactoryImpl(org.apache.webbeans.container.InjectionTargetFactoryImpl)

Example 23 with AnnotatedType

use of javax.enterprise.inject.spi.AnnotatedType in project cucumber-jvm by cucumber.

the class Cdi2Factory method addBean.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void addBean(AfterBeanDiscovery afterBeanDiscovery, BeanManager beanManager, Class<?> clazz) {
    AnnotatedType clazzAnnotatedType = beanManager.createAnnotatedType(clazz);
    // @formatter:off
    InjectionTarget injectionTarget = beanManager.getInjectionTargetFactory(clazzAnnotatedType).createInjectionTarget(null);
    // @formatter:on
    // @formatter:off
    afterBeanDiscovery.addBean().read(clazzAnnotatedType).createWith(callback -> {
        CreationalContext c = (CreationalContext) callback;
        Object instance = injectionTarget.produce(c);
        injectionTarget.inject(instance, c);
        injectionTarget.postConstruct(instance);
        return instance;
    });
// @formatter:on
}
Also used : CreationalContext(javax.enterprise.context.spi.CreationalContext) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) InjectionTarget(javax.enterprise.inject.spi.InjectionTarget)

Example 24 with AnnotatedType

use of javax.enterprise.inject.spi.AnnotatedType in project dolphin-platform by canoo.

the class CdiManagedBeanFactory method createDependentInstance.

@Override
public <T> T createDependentInstance(Class<T> cls, PostConstructInterceptor<T> interceptor) {
    Assert.requireNonNull(cls, "cls");
    Assert.requireNonNull(interceptor, "interceptor");
    BeanManager bm = BeanManagerProvider.getInstance().getBeanManager();
    AnnotatedType annotatedType = bm.createAnnotatedType(cls);
    final InjectionTarget<T> injectionTarget = bm.createInjectionTarget(annotatedType);
    final Bean<T> bean = new BeanBuilder<T>(bm).beanClass(cls).name(UUID.randomUUID().toString()).scope(Dependent.class).beanLifecycle(new DolphinPlatformContextualLifecycle<T>(injectionTarget, interceptor)).create();
    Class<?> beanClass = bean.getBeanClass();
    CreationalContext<T> creationalContext = bm.createCreationalContext(bean);
    T instance = (T) bm.getReference(bean, beanClass, creationalContext);
    contextMap.put(instance, creationalContext);
    beanMap.put(instance, bean);
    return instance;
}
Also used : AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) BeanManager(javax.enterprise.inject.spi.BeanManager)

Aggregations

AnnotatedType (javax.enterprise.inject.spi.AnnotatedType)24 AnnotatedMethod (javax.enterprise.inject.spi.AnnotatedMethod)7 Annotation (java.lang.annotation.Annotation)5 Method (java.lang.reflect.Method)5 Type (java.lang.reflect.Type)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ProcessAnnotatedType (javax.enterprise.inject.spi.ProcessAnnotatedType)4 Test (org.junit.Test)4 InjectionTarget (javax.enterprise.inject.spi.InjectionTarget)3 EnhancedAnnotatedType (org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType)3 ForwardingAnnotatedType (org.jboss.weld.util.annotated.ForwardingAnnotatedType)3 Field (java.lang.reflect.Field)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Logger (java.util.logging.Logger)2 CreationalContext (javax.enterprise.context.spi.CreationalContext)2 Alternative (javax.enterprise.inject.Alternative)2