Commit ee9ed7ecde93cbd47f42653afe67684825ab8109
1 parent
befcc946
Exists in
master
Correção do erro no getReference() quando o bean é do tipo Producer
Method
Showing
1 changed file
with
10 additions
and
7 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Beans.java
| @@ -74,12 +74,11 @@ public final class Beans { | @@ -74,12 +74,11 @@ public final class Beans { | ||
| 74 | return manager; | 74 | return manager; |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | - @SuppressWarnings("unchecked") | ||
| 78 | public static <T> T getReference(final Class<T> beanClass, Annotation... qualifiers) { | 77 | public static <T> T getReference(final Class<T> beanClass, Annotation... qualifiers) { |
| 79 | T instance; | 78 | T instance; |
| 80 | 79 | ||
| 81 | try { | 80 | try { |
| 82 | - instance = (T) getReference(manager.getBeans(beanClass, qualifiers)); | 81 | + instance = (T) getReference(manager.getBeans(beanClass, qualifiers), beanClass); |
| 83 | 82 | ||
| 84 | } catch (NoSuchElementException cause) { | 83 | } catch (NoSuchElementException cause) { |
| 85 | StringBuffer buffer = new StringBuffer(); | 84 | StringBuffer buffer = new StringBuffer(); |
| @@ -97,12 +96,11 @@ public final class Beans { | @@ -97,12 +96,11 @@ public final class Beans { | ||
| 97 | return instance; | 96 | return instance; |
| 98 | } | 97 | } |
| 99 | 98 | ||
| 100 | - @SuppressWarnings("unchecked") | ||
| 101 | public static <T> T getReference(final Class<T> beanClass) { | 99 | public static <T> T getReference(final Class<T> beanClass) { |
| 102 | T instance; | 100 | T instance; |
| 103 | 101 | ||
| 104 | try { | 102 | try { |
| 105 | - instance = (T) getReference(manager.getBeans(beanClass)); | 103 | + instance = (T) getReference(manager.getBeans(beanClass), beanClass); |
| 106 | 104 | ||
| 107 | } catch (NoSuchElementException cause) { | 105 | } catch (NoSuchElementException cause) { |
| 108 | String message = getBundle().getString("bean-not-found", beanClass.getCanonicalName()); | 106 | String message = getBundle().getString("bean-not-found", beanClass.getCanonicalName()); |
| @@ -128,12 +126,17 @@ public final class Beans { | @@ -128,12 +126,17 @@ public final class Beans { | ||
| 128 | } | 126 | } |
| 129 | 127 | ||
| 130 | @SuppressWarnings("unchecked") | 128 | @SuppressWarnings("unchecked") |
| 131 | - private static <T> T getReference(Set<Bean<?>> beans) { | 129 | + private static <T> T getReference(Set<Bean<?>> beans, Class<T> beanClass) { |
| 132 | Bean<?> bean = beans.iterator().next(); | 130 | Bean<?> bean = beans.iterator().next(); |
| 133 | - return (T) manager.getReference(bean, bean.getBeanClass(), manager.createCreationalContext(bean)); | 131 | + return (T) manager.getReference(bean, beanClass == null ? bean.getBeanClass() : beanClass, |
| 132 | + manager.createCreationalContext(bean)); | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + private static <T> T getReference(Set<Bean<?>> beans) { | ||
| 136 | + return getReference(beans, null); | ||
| 134 | } | 137 | } |
| 135 | 138 | ||
| 136 | private static ResourceBundle getBundle() { | 139 | private static ResourceBundle getBundle() { |
| 137 | return ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault()); | 140 | return ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault()); |
| 138 | } | 141 | } |
| 139 | -} | 142 | -} |
| 143 | +} | ||
| 140 | \ No newline at end of file | 144 | \ No newline at end of file |