Commit 1b9db5469a08cff42a536cba25b91eb5c27e6940
1 parent
882867ad
Exists in
master
FWK-214: Correção do erro java.lang.NoSuchMethodError:
br.gov.frameworkdemoiselle.util.Beans.getReference Task-Url: https://demoiselle.atlassian.net/browse/FWK-214
Showing
1 changed file
with
24 additions
and
5 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Beans.java
... | ... | @@ -77,6 +77,10 @@ public final class Beans { |
77 | 77 | return beanManager; |
78 | 78 | } |
79 | 79 | |
80 | + public static <T> T getReference(final Class<T> beanClass) { | |
81 | + return getReference(beanClass, (Annotation[]) null); | |
82 | + } | |
83 | + | |
80 | 84 | /** |
81 | 85 | * Obtains a injectble instance of a bean, which have the given required type and qualifiers, and are available for |
82 | 86 | * injection in the point where this method was call. |
... | ... | @@ -93,15 +97,24 @@ public final class Beans { |
93 | 97 | T instance; |
94 | 98 | |
95 | 99 | try { |
96 | - instance = (T) getReference(getBeanManager().getBeans(beanClass, qualifiers), beanClass, qualifiers); | |
100 | + Set<Bean<?>> beans; | |
101 | + if (qualifiers == null) { | |
102 | + beans = getBeanManager().getBeans(beanClass); | |
103 | + } else { | |
104 | + beans = getBeanManager().getBeans(beanClass, qualifiers); | |
105 | + } | |
106 | + | |
107 | + instance = (T) getReference(beans, beanClass, qualifiers); | |
97 | 108 | |
98 | 109 | } catch (NoSuchElementException cause) { |
99 | 110 | StringBuffer buffer = new StringBuffer(); |
100 | 111 | buffer.append(beanClass.getCanonicalName()); |
101 | 112 | |
102 | - for (Annotation qualifier : qualifiers) { | |
103 | - buffer.append(", "); | |
104 | - buffer.append(qualifier.getClass().getCanonicalName()); | |
113 | + if (qualifiers != null) { | |
114 | + for (Annotation qualifier : qualifiers) { | |
115 | + buffer.append(", "); | |
116 | + buffer.append(qualifier.getClass().getCanonicalName()); | |
117 | + } | |
105 | 118 | } |
106 | 119 | |
107 | 120 | String message = getBundle().getString("bean-not-found", buffer.toString()); |
... | ... | @@ -146,7 +159,13 @@ public final class Beans { |
146 | 159 | Bean<?> bean = beans.iterator().next(); |
147 | 160 | CreationalContext<?> context = getBeanManager().createCreationalContext(bean); |
148 | 161 | Type beanType = beanClass == null ? bean.getBeanClass() : beanClass; |
149 | - InjectionPoint injectionPoint = new CustomInjectionPoint(bean, beanType, qualifiers); | |
162 | + InjectionPoint injectionPoint; | |
163 | + | |
164 | + if (qualifiers == null) { | |
165 | + injectionPoint = new CustomInjectionPoint(bean, beanType); | |
166 | + } else { | |
167 | + injectionPoint = new CustomInjectionPoint(bean, beanType, qualifiers); | |
168 | + } | |
150 | 169 | |
151 | 170 | return (T) getBeanManager().getInjectableReference(injectionPoint, context); |
152 | 171 | } | ... | ... |