Commit ef753e73cf6250c42dee4c9ff8df0195a24702b5
1 parent
179020f4
Exists in
master
Refatoração dos métodos getClass e getInstance para selectClass e
selectInstance. Modificação da exceção lançada pela classe StrategySelector, DemoiselleException no lugar de ConfigurationException.
Showing
3 changed files
with
11 additions
and
10 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java
... | ... | @@ -78,7 +78,7 @@ public class SecurityContextImpl implements SecurityContext { |
78 | 78 | Class<? extends Authenticator> clazz = getConfig().getAuthenticatorClass(); |
79 | 79 | |
80 | 80 | if (clazz == null) { |
81 | - clazz = StrategySelector.getClass(Authenticator.class, bootstrap.getCache()); | |
81 | + clazz = StrategySelector.selectClass(Authenticator.class, bootstrap.getCache()); | |
82 | 82 | } |
83 | 83 | |
84 | 84 | this.authenticator = Beans.getReference(clazz); |
... | ... | @@ -93,7 +93,7 @@ public class SecurityContextImpl implements SecurityContext { |
93 | 93 | Class<? extends Authorizer> clazz = getConfig().getAuthorizerClass(); |
94 | 94 | |
95 | 95 | if (clazz == null) { |
96 | - clazz = StrategySelector.getClass(Authorizer.class, bootstrap.getCache()); | |
96 | + clazz = StrategySelector.selectClass(Authorizer.class, bootstrap.getCache()); | |
97 | 97 | } |
98 | 98 | |
99 | 99 | this.authorizer = Beans.getReference(clazz); | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/StrategySelector.java
... | ... | @@ -45,8 +45,10 @@ import java.util.HashMap; |
45 | 45 | import java.util.List; |
46 | 46 | import java.util.Map; |
47 | 47 | |
48 | +import javax.enterprise.inject.AmbiguousResolutionException; | |
49 | + | |
50 | +import br.gov.frameworkdemoiselle.DemoiselleException; | |
48 | 51 | import br.gov.frameworkdemoiselle.annotation.Priority; |
49 | -import br.gov.frameworkdemoiselle.configuration.ConfigurationException; | |
50 | 52 | import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; |
51 | 53 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
52 | 54 | |
... | ... | @@ -76,7 +78,7 @@ public final class StrategySelector implements Serializable { |
76 | 78 | } |
77 | 79 | |
78 | 80 | @SuppressWarnings("unchecked") |
79 | - public static <T> T getInstance(Class<T> type, Collection<? extends T> options) throws ConfigurationException { | |
81 | + public static <T> T selectInstance(Class<T> type, Collection<? extends T> options) { | |
80 | 82 | |
81 | 83 | Map<Class<? extends T>, T> map = new HashMap<Class<? extends T>, T>(); |
82 | 84 | |
... | ... | @@ -86,12 +88,11 @@ public final class StrategySelector implements Serializable { |
86 | 88 | } |
87 | 89 | } |
88 | 90 | |
89 | - Class<? extends T> elected = getClass(type, map.keySet()); | |
91 | + Class<? extends T> elected = selectClass(type, map.keySet()); | |
90 | 92 | return map.get(elected); |
91 | 93 | } |
92 | 94 | |
93 | - public static <T> Class<? extends T> getClass(Class<T> type, Collection<Class<? extends T>> options) | |
94 | - throws ConfigurationException { | |
95 | + public static <T> Class<? extends T> selectClass(Class<T> type, Collection<Class<? extends T>> options) { | |
95 | 96 | Class<? extends T> selected = null; |
96 | 97 | |
97 | 98 | for (Class<? extends T> option : options) { |
... | ... | @@ -108,7 +109,7 @@ public final class StrategySelector implements Serializable { |
108 | 109 | } |
109 | 110 | |
110 | 111 | private static <T> void checkForAmbiguity(Class<T> type, Class<? extends T> selected, |
111 | - Collection<Class<? extends T>> options) throws ConfigurationException { | |
112 | + Collection<Class<? extends T>> options) { | |
112 | 113 | int selectedPriority = getPriority(selected); |
113 | 114 | |
114 | 115 | List<Class<? extends T>> ambiguous = new ArrayList<Class<? extends T>>(); |
... | ... | @@ -123,7 +124,7 @@ public final class StrategySelector implements Serializable { |
123 | 124 | ambiguous.add(selected); |
124 | 125 | |
125 | 126 | String message = getExceptionMessage(type, ambiguous); |
126 | - throw new ConfigurationException(message); | |
127 | + throw new DemoiselleException(message, new AmbiguousResolutionException()); | |
127 | 128 | } |
128 | 129 | } |
129 | 130 | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionContextImpl.java
... | ... | @@ -62,7 +62,7 @@ public class TransactionContextImpl implements TransactionContext { |
62 | 62 | Class<? extends Transaction> clazz = getConfig().getTransactionClass(); |
63 | 63 | |
64 | 64 | if (clazz == null) { |
65 | - clazz = StrategySelector.getClass(Transaction.class, bootstrap.getCache()); | |
65 | + clazz = StrategySelector.selectClass(Transaction.class, bootstrap.getCache()); | |
66 | 66 | } |
67 | 67 | |
68 | 68 | this.transaction = Beans.getReference(clazz); | ... | ... |