diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ProxyBean.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ProxyBean.java index 06acbb4..b89d5f3 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ProxyBean.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ProxyBean.java @@ -38,20 +38,24 @@ package br.gov.frameworkdemoiselle.internal.bootstrap; import java.lang.annotation.Annotation; import java.lang.reflect.Type; -import java.util.Collections; import java.util.HashSet; import java.util.Set; import javax.enterprise.context.Dependent; +import javax.enterprise.context.NormalScope; import javax.enterprise.context.spi.CreationalContext; +import javax.enterprise.inject.Alternative; import javax.enterprise.inject.Any; import javax.enterprise.inject.Default; +import javax.enterprise.inject.Stereotype; import javax.enterprise.inject.spi.AnnotatedType; import javax.enterprise.inject.spi.Bean; import javax.enterprise.inject.spi.BeanManager; import javax.enterprise.inject.spi.InjectionPoint; import javax.enterprise.inject.spi.InjectionTarget; import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Named; +import javax.inject.Qualifier; import javax.inject.Scope; /** @@ -59,21 +63,22 @@ import javax.inject.Scope; */ public class ProxyBean implements Bean { - private Class proxy; + private Class beanClass; private InjectionTarget injectionTarget; - public ProxyBean(Class proxy, BeanManager beanManager) { - AnnotatedType annotatedType = beanManager.createAnnotatedType(proxy); + public ProxyBean(Class beanClass, BeanManager beanManager) { + AnnotatedType annotatedType = beanManager.createAnnotatedType(beanClass); this.injectionTarget = beanManager.createInjectionTarget(annotatedType); - this.proxy = proxy; + this.beanClass = beanClass; } public Object create(CreationalContext creationalContext) { Object instance = injectionTarget.produce(creationalContext); injectionTarget.inject(instance, creationalContext); injectionTarget.postConstruct(instance); + return instance; } @@ -85,40 +90,75 @@ public class ProxyBean implements Bean { public Set getTypes() { Set types = new HashSet(); - types.add(proxy.getSuperclass()); + types.add(beanClass.getSuperclass()); types.add(Object.class); + return types; } @SuppressWarnings("serial") public Set getQualifiers() { - Set qualifiers = new HashSet(); - qualifiers.add(new AnnotationLiteral() { + Set result = new HashSet(); + + result.add(new AnnotationLiteral() { }); - qualifiers.add(new AnnotationLiteral() { + result.add(new AnnotationLiteral() { }); - return qualifiers; + for (Annotation annotation : beanClass.getAnnotations()) { + if (annotation.getClass().isAnnotationPresent(Qualifier.class)) { + result.add(annotation); + } + } + + return result; } public Class getScope() { - return Dependent.class; + Class result = Dependent.class; + + Class annotationClass; + for (Annotation annotation : beanClass.getAnnotations()) { + annotationClass = annotation.getClass(); + + if (annotationClass.isAnnotationPresent(Scope.class) + || annotationClass.isAnnotationPresent(NormalScope.class)) { + result = annotationClass; + break; + } + } + + return result; } public String getName() { - return null; + String result = null; + + if (beanClass.isAnnotationPresent(Named.class)) { + result = beanClass.getAnnotation(Named.class).value(); + } + + return result; } public Set> getStereotypes() { - return Collections.emptySet(); + Set> result = new HashSet>(); + + for (Annotation annotation : beanClass.getAnnotations()) { + if (annotation.getClass().isAnnotationPresent(Stereotype.class)) { + result.add(annotation.getClass()); + } + } + + return result; } public Class getBeanClass() { - return proxy; + return beanClass; } public boolean isAlternative() { - return false; + return beanClass.isAnnotationPresent(Alternative.class); } public boolean isNullable() { -- libgit2 0.21.2