Commit c9c676732ad0faeec3f1f3b1c9c1281d8684d64d
1 parent
c3581713
Exists in
master
Ajuste na mensagem de ambiguidade na seleção de estratégias
Showing
5 changed files
with
91 additions
and
57 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/configuration/ConfigurationException.java
@@ -68,5 +68,4 @@ public class ConfigurationException extends DemoiselleException { | @@ -68,5 +68,4 @@ public class ConfigurationException extends DemoiselleException { | ||
68 | public ConfigurationException(String message, Throwable cause) { | 68 | public ConfigurationException(String message, Throwable cause) { |
69 | super(message, cause); | 69 | super(message, cause); |
70 | } | 70 | } |
71 | - | ||
72 | } | 71 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java
@@ -71,7 +71,10 @@ public class SecurityContextImpl implements SecurityContext { | @@ -71,7 +71,10 @@ public class SecurityContextImpl implements SecurityContext { | ||
71 | if (this.authenticator == null) { | 71 | if (this.authenticator == null) { |
72 | AuthenticatorBootstrap bootstrap = Beans.getReference(AuthenticatorBootstrap.class); | 72 | AuthenticatorBootstrap bootstrap = Beans.getReference(AuthenticatorBootstrap.class); |
73 | Class<? extends Authenticator> clazz = getConfig().getAuthenticatorClass(); | 73 | Class<? extends Authenticator> clazz = getConfig().getAuthenticatorClass(); |
74 | - clazz = StrategySelector.getClass(clazz, bootstrap.getCache()); | 74 | + |
75 | + if (clazz == null) { | ||
76 | + clazz = StrategySelector.getClass(Authenticator.class, bootstrap.getCache()); | ||
77 | + } | ||
75 | 78 | ||
76 | this.authenticator = Beans.getReference(clazz); | 79 | this.authenticator = Beans.getReference(clazz); |
77 | } | 80 | } |
@@ -83,7 +86,10 @@ public class SecurityContextImpl implements SecurityContext { | @@ -83,7 +86,10 @@ public class SecurityContextImpl implements SecurityContext { | ||
83 | if (this.authorizer == null) { | 86 | if (this.authorizer == null) { |
84 | AuthorizerBootstrap bootstrap = Beans.getReference(AuthorizerBootstrap.class); | 87 | AuthorizerBootstrap bootstrap = Beans.getReference(AuthorizerBootstrap.class); |
85 | Class<? extends Authorizer> clazz = getConfig().getAuthorizerClass(); | 88 | Class<? extends Authorizer> clazz = getConfig().getAuthorizerClass(); |
86 | - clazz = StrategySelector.getClass(clazz, bootstrap.getCache()); | 89 | + |
90 | + if (clazz == null) { | ||
91 | + clazz = StrategySelector.getClass(Authorizer.class, bootstrap.getCache()); | ||
92 | + } | ||
87 | 93 | ||
88 | this.authorizer = Beans.getReference(clazz); | 94 | this.authorizer = Beans.getReference(clazz); |
89 | } | 95 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/StrategySelector.java
@@ -44,6 +44,8 @@ import java.util.List; | @@ -44,6 +44,8 @@ import java.util.List; | ||
44 | 44 | ||
45 | import br.gov.frameworkdemoiselle.annotation.Priority; | 45 | import br.gov.frameworkdemoiselle.annotation.Priority; |
46 | import br.gov.frameworkdemoiselle.configuration.ConfigurationException; | 46 | import br.gov.frameworkdemoiselle.configuration.ConfigurationException; |
47 | +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | ||
48 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
47 | 49 | ||
48 | public final class StrategySelector implements Serializable { | 50 | public final class StrategySelector implements Serializable { |
49 | 51 | ||
@@ -57,21 +59,20 @@ public final class StrategySelector implements Serializable { | @@ -57,21 +59,20 @@ public final class StrategySelector implements Serializable { | ||
57 | 59 | ||
58 | private static final long serialVersionUID = 1L; | 60 | private static final long serialVersionUID = 1L; |
59 | 61 | ||
62 | + private static ResourceBundle bundle; | ||
63 | + | ||
60 | private StrategySelector() { | 64 | private StrategySelector() { |
61 | } | 65 | } |
62 | 66 | ||
63 | - public static <T> Class<? extends T> getClass(Class<? extends T> configClass, | ||
64 | - List<Class<? extends T>> optionalClasses) { | ||
65 | - Class<? extends T> result = configClass; | ||
66 | - | ||
67 | - if (configClass == null) { | ||
68 | - result = getPriorityReference(optionalClasses); | 67 | + private static ResourceBundle getBundle() { |
68 | + if (bundle == null) { | ||
69 | + bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | ||
69 | } | 70 | } |
70 | 71 | ||
71 | - return result; | 72 | + return bundle; |
72 | } | 73 | } |
73 | 74 | ||
74 | - private static <T> Class<? extends T> getPriorityReference(List<Class<? extends T>> options) | 75 | + public static <T> Class<? extends T> getClass(Class<T> type, List<Class<? extends T>> options) |
75 | throws ConfigurationException { | 76 | throws ConfigurationException { |
76 | Class<? extends T> selected = null; | 77 | Class<? extends T> selected = null; |
77 | 78 | ||
@@ -81,24 +82,13 @@ public final class StrategySelector implements Serializable { | @@ -81,24 +82,13 @@ public final class StrategySelector implements Serializable { | ||
81 | } | 82 | } |
82 | } | 83 | } |
83 | 84 | ||
84 | - checkForAmbiguity(selected, options); | 85 | + checkForAmbiguity(type, selected, options); |
85 | 86 | ||
86 | return selected; | 87 | return selected; |
87 | } | 88 | } |
88 | 89 | ||
89 | - private static <T> int getPriority(Class<T> type) { | ||
90 | - int result = Priority.MAX_PRIORITY; | ||
91 | - Priority priority = type.getAnnotation(Priority.class); | ||
92 | - | ||
93 | - if (priority != null) { | ||
94 | - result = priority.value(); | ||
95 | - } | ||
96 | - | ||
97 | - return result; | ||
98 | - } | ||
99 | - | ||
100 | - private static <T> void checkForAmbiguity(Class<? extends T> selected, List<Class<? extends T>> options) | ||
101 | - throws ConfigurationException { | 90 | + private static <T> void checkForAmbiguity(Class<T> type, Class<? extends T> selected, |
91 | + List<Class<? extends T>> options) throws ConfigurationException { | ||
102 | int selectedPriority = getPriority(selected); | 92 | int selectedPriority = getPriority(selected); |
103 | 93 | ||
104 | List<Class<? extends T>> ambiguous = new ArrayList<Class<? extends T>>(); | 94 | List<Class<? extends T>> ambiguous = new ArrayList<Class<? extends T>>(); |
@@ -110,32 +100,73 @@ public final class StrategySelector implements Serializable { | @@ -110,32 +100,73 @@ public final class StrategySelector implements Serializable { | ||
110 | } | 100 | } |
111 | 101 | ||
112 | if (!ambiguous.isEmpty()) { | 102 | if (!ambiguous.isEmpty()) { |
113 | - throw new ConfigurationException("AMBIGUO"); | 103 | + ambiguous.add(selected); |
104 | + | ||
105 | + String message = getExceptionMessage(type, ambiguous); | ||
106 | + throw new ConfigurationException(message); | ||
107 | + } | ||
108 | + } | ||
109 | + | ||
110 | + private static <T> String getExceptionMessage(Class<T> type, List<Class<? extends T>> ambiguous) { | ||
111 | + StringBuffer classes = new StringBuffer(); | ||
112 | + | ||
113 | + int i = 0; | ||
114 | + for (Class<? extends T> clazz : ambiguous) { | ||
115 | + if (i++ != 0) { | ||
116 | + classes.append(", "); | ||
117 | + } | ||
118 | + | ||
119 | + classes.append(clazz.getCanonicalName()); | ||
114 | } | 120 | } |
121 | + | ||
122 | + return getBundle().getString("ambiguous-strategy-resolution", type.getCanonicalName(), classes.toString()); | ||
123 | + } | ||
124 | + | ||
125 | + private static <T> int getPriority(Class<T> type) { | ||
126 | + int result = Priority.MAX_PRIORITY; | ||
127 | + Priority priority = type.getAnnotation(Priority.class); | ||
128 | + | ||
129 | + if (priority != null) { | ||
130 | + result = priority.value(); | ||
131 | + } | ||
132 | + | ||
133 | + return result; | ||
115 | } | 134 | } |
116 | 135 | ||
117 | - /* | ||
118 | - * public static <T> T getExplicitReference(String configKey, Class<T> strategyType, Class<T> defaultType) { | ||
119 | - * Class<T> selectedType = loadSelected(configKey, strategyType, defaultType); return | ||
120 | - * Beans.getReference(selectedType); } | ||
121 | - */ | ||
122 | - | ||
123 | - /* | ||
124 | - * @SuppressWarnings("unchecked") private static <T> Class<T> loadSelected(String configKey, Class<T> strategyType, | ||
125 | - * Class<T> defaultType) { ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-core-bundle", | ||
126 | - * Beans.getReference(Locale.class)); Class<T> result = null; String canonicalName = null; String typeName = | ||
127 | - * strategyType.getSimpleName().toLowerCase(); String key = null; try { URL url = | ||
128 | - * ConfigurationLoader.getResourceAsURL("demoiselle.properties"); Configuration config = new | ||
129 | - * PropertiesConfiguration(url); canonicalName = config.getString(configKey, defaultType.getCanonicalName()); | ||
130 | - * ClassLoader classLoader = ConfigurationLoader.getClassLoaderForClass(canonicalName); if (classLoader == null) { | ||
131 | - * classLoader = Thread.currentThread().getContextClassLoader(); } result = (Class<T>) Class.forName(canonicalName, | ||
132 | - * false, classLoader); result.asSubclass(strategyType); } catch | ||
133 | - * (org.apache.commons.configuration.ConfigurationException cause) { throw new | ||
134 | - * ConfigurationException(bundle.getString("file-not-found", "demoiselle.properties")); } catch | ||
135 | - * (ClassNotFoundException cause) { key = Strings.getString("{0}-class-not-found", typeName); throw new | ||
136 | - * ConfigurationException(bundle.getString(key, canonicalName)); } catch (FileNotFoundException e) { throw new | ||
137 | - * ConfigurationException(bundle.getString("file-not-found", "demoiselle.properties")); } catch (ClassCastException | ||
138 | - * cause) { key = Strings.getString("{0}-class-must-be-of-type", typeName); throw new | ||
139 | - * ConfigurationException(bundle.getString(key, canonicalName, strategyType)); } return result; } | ||
140 | - */ | 136 | + // public static <T> T getExplicitReference(String configKey, Class<T> strategyType, Class<T> defaultType) { |
137 | + // Class<T> selectedType = loadSelected(configKey, strategyType, defaultType); | ||
138 | + // return Beans.getReference(selectedType); | ||
139 | + // } | ||
140 | + // | ||
141 | + // @SuppressWarnings("unchecked") | ||
142 | + // private static <T> Class<T> loadSelected(String configKey, Class<T> strategyType, Class<T> defaultType) { | ||
143 | + // ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-core-bundle", | ||
144 | + // Beans.getReference(Locale.class)); | ||
145 | + // Class<T> result = null; | ||
146 | + // String canonicalName = null; | ||
147 | + // String typeName = strategyType.getSimpleName().toLowerCase(); | ||
148 | + // String key = null; | ||
149 | + // try { | ||
150 | + // URL url = ConfigurationLoader.getResourceAsURL("demoiselle.properties"); | ||
151 | + // Configuration config = new PropertiesConfiguration(url); | ||
152 | + // canonicalName = config.getString(configKey, defaultType.getCanonicalName()); | ||
153 | + // ClassLoader classLoader = ConfigurationLoader.getClassLoaderForClass(canonicalName); | ||
154 | + // if (classLoader == null) { | ||
155 | + // classLoader = Thread.currentThread().getContextClassLoader(); | ||
156 | + // } | ||
157 | + // result = (Class<T>) Class.forName(canonicalName, false, classLoader); | ||
158 | + // result.asSubclass(strategyType); | ||
159 | + // } catch (org.apache.commons.configuration.ConfigurationException cause) { | ||
160 | + // throw new ConfigurationException(bundle.getString("file-not-found", "demoiselle.properties")); | ||
161 | + // } catch (ClassNotFoundException cause) { | ||
162 | + // key = Strings.getString("{0}-class-not-found", typeName); | ||
163 | + // throw new ConfigurationException(bundle.getString(key, canonicalName)); | ||
164 | + // } catch (FileNotFoundException e) { | ||
165 | + // throw new ConfigurationException(bundle.getString("file-not-found", "demoiselle.properties")); | ||
166 | + // } catch (ClassCastException cause) { | ||
167 | + // key = Strings.getString("{0}-class-must-be-of-type", typeName); | ||
168 | + // throw new ConfigurationException(bundle.getString(key, canonicalName, strategyType)); | ||
169 | + // } | ||
170 | + // return result; | ||
171 | + // } | ||
141 | } | 172 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionContextImpl.java
@@ -60,7 +60,10 @@ public class TransactionContextImpl implements TransactionContext { | @@ -60,7 +60,10 @@ public class TransactionContextImpl implements TransactionContext { | ||
60 | if (this.transaction == null) { | 60 | if (this.transaction == null) { |
61 | TransactionBootstrap bootstrap = Beans.getReference(TransactionBootstrap.class); | 61 | TransactionBootstrap bootstrap = Beans.getReference(TransactionBootstrap.class); |
62 | Class<? extends Transaction> clazz = getConfig().getTransactionClass(); | 62 | Class<? extends Transaction> clazz = getConfig().getTransactionClass(); |
63 | - clazz = StrategySelector.getClass(clazz, bootstrap.getCache()); | 63 | + |
64 | + if (clazz == null) { | ||
65 | + clazz = StrategySelector.getClass(Transaction.class, bootstrap.getCache()); | ||
66 | + } | ||
64 | 67 | ||
65 | this.transaction = Beans.getReference(clazz); | 68 | this.transaction = Beans.getReference(clazz); |
66 | } | 69 | } |
impl/core/src/main/resources/demoiselle-core-bundle.properties
@@ -34,6 +34,7 @@ | @@ -34,6 +34,7 @@ | ||
34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | 34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
35 | 35 | ||
36 | engine-on=Ligando os motores do Demoiselle ${project.version} | 36 | engine-on=Ligando os motores do Demoiselle ${project.version} |
37 | +ambiguous-strategy-resolution=Foi detectada ambiguidade da interface "{0}" com as seguintes implementa\u00E7\u00F5es\: "{1}". Para resolver o conflito, defina explicitamente a implementa\u00E7\u00E3o no demoiselle.properties. | ||
37 | bean-not-found=Voc\u00EA est\u00E1 tentando obter um objeto n\u00E3o reconhecido pelo CDI via Beans.getReference({0}) | 38 | bean-not-found=Voc\u00EA est\u00E1 tentando obter um objeto n\u00E3o reconhecido pelo CDI via Beans.getReference({0}) |
38 | more-than-one-exceptionhandler-defined-for-same-class=Foi definido mais de um m\u00E9todo na classe {0} para tratar a exce\u00E7\u00E3o {1} | 39 | more-than-one-exceptionhandler-defined-for-same-class=Foi definido mais de um m\u00E9todo na classe {0} para tratar a exce\u00E7\u00E3o {1} |
39 | handling-exception=Tratando a exce\u00E7\u00E3o {0} | 40 | handling-exception=Tratando a exce\u00E7\u00E3o {0} |
@@ -71,8 +72,6 @@ error-creating-new-instance-for=Error creating a new instance for "{0}" | @@ -71,8 +72,6 @@ error-creating-new-instance-for=Error creating a new instance for "{0}" | ||
71 | executed-successfully=\ {0} execultado com sucesso | 72 | executed-successfully=\ {0} execultado com sucesso |
72 | must-declare-one-single-parameter=Voc\u00EA deve declarar um par\u00E2metro \u00FAnico em {0} | 73 | must-declare-one-single-parameter=Voc\u00EA deve declarar um par\u00E2metro \u00FAnico em {0} |
73 | loading-default-transaction-manager=Carregando o gerenciador de transa\u00E7\u00E3o padr\u00E3o {0} | 74 | loading-default-transaction-manager=Carregando o gerenciador de transa\u00E7\u00E3o padr\u00E3o {0} |
74 | -transaction-class-not-found=A classe de transa\u00E7\u00E3o "{0}" informada no demoiselle.properties n\u00E3o foi encontrada no classpath. | ||
75 | -transaction-class-must-be-of-type=A classe de transa\u00E7\u00E3o "{0}" informada no demoiselle.properties deve ser do tipo "{1}" | ||
76 | results-count-greater-page-size=Quantidade de resultados {0} \u00E9 maior que o tamanho da p\u00E1gina {1} | 75 | results-count-greater-page-size=Quantidade de resultados {0} \u00E9 maior que o tamanho da p\u00E1gina {1} |
77 | page-result=Resultado paginado [p\u00E1gina\={0}, total de resultados\={1}] | 76 | page-result=Resultado paginado [p\u00E1gina\={0}, total de resultados\={1}] |
78 | page=P\u00E1gina [n\u00FAmero\={0}, tamanho\={1}] | 77 | page=P\u00E1gina [n\u00FAmero\={0}, tamanho\={1}] |
@@ -88,8 +87,6 @@ access-allowed=O usu\u00E1rio "{0}" acessou o recurso "{2}" com a a\u00E7\u00E3o | @@ -88,8 +87,6 @@ access-allowed=O usu\u00E1rio "{0}" acessou o recurso "{2}" com a a\u00E7\u00E3o | ||
88 | access-denied=O usu\u00E1rio "{0}" n\u00E3o possui permiss\u00E3o para executar a a\u00E7\u00E3o "{1}" no recurso "{2}" | 87 | access-denied=O usu\u00E1rio "{0}" n\u00E3o possui permiss\u00E3o para executar a a\u00E7\u00E3o "{1}" no recurso "{2}" |
89 | access-denied-ui=Voc\u00EA n\u00E3o est\u00E1 autorizado a executar a a\u00E7\u00E3o {1} no recurso {0} | 88 | access-denied-ui=Voc\u00EA n\u00E3o est\u00E1 autorizado a executar a a\u00E7\u00E3o {1} no recurso {0} |
90 | authorizer-not-defined=Nenhuma regra de resolu\u00E7\u00E3o de permiss\u00F5es foi definida. Para utilizar @{0} \u00E9 preciso definir a propriedade frameworkdemoiselle.security.authorizer.class como regra de resolu\u00E7\u00E3o de permiss\u00F5es desejada no arquivo demoiselle.properties. | 89 | authorizer-not-defined=Nenhuma regra de resolu\u00E7\u00E3o de permiss\u00F5es foi definida. Para utilizar @{0} \u00E9 preciso definir a propriedade frameworkdemoiselle.security.authorizer.class como regra de resolu\u00E7\u00E3o de permiss\u00F5es desejada no arquivo demoiselle.properties. |
91 | -authorizer-class-not-found=A classe de resolu\u00E7\u00E3o de permiss\u00F5es "{0}" informada no demoiselle.properties n\u00E3o foi encontrada no classpath. | ||
92 | -authorizer-class-must-be-of-type=A classe de resolu\u00E7\u00E3o de permiss\u00F5es "{0}" informada no demoiselle.properties deve ser do tipo "{1}" | ||
93 | user-not-authenticated=Usu\u00E1rio n\u00E3o autenticado | 90 | user-not-authenticated=Usu\u00E1rio n\u00E3o autenticado |
94 | has-role-verification=Verificando se o usu\u00E1rio {0} possui a(s) role(s)\: {1} | 91 | has-role-verification=Verificando se o usu\u00E1rio {0} possui a(s) role(s)\: {1} |
95 | does-not-have-role=Usu\u00E1rio {0} n\u00E3o possui a(s) role(s)\: {1} | 92 | does-not-have-role=Usu\u00E1rio {0} n\u00E3o possui a(s) role(s)\: {1} |
@@ -97,5 +94,3 @@ does-not-have-role-ui=Para acessar este recurso \u00E9 necess\u00E1rio ser {0} | @@ -97,5 +94,3 @@ does-not-have-role-ui=Para acessar este recurso \u00E9 necess\u00E1rio ser {0} | ||
97 | user-has-role=Usu\u00E1rio {0} possui a(s) role(s)\: {1} | 94 | user-has-role=Usu\u00E1rio {0} possui a(s) role(s)\: {1} |
98 | 95 | ||
99 | authenticator-not-defined=Nenhum mecanismo de autentica\u00E7\u00E3o foi definido. Para utilizar {0} \u00E9 preciso definir a propriedade frameworkdemoiselle.security.authenticator.class como mecanismo de autentica\u00E7\u00E3o desejado no arquivo demoiselle.properties. | 96 | authenticator-not-defined=Nenhum mecanismo de autentica\u00E7\u00E3o foi definido. Para utilizar {0} \u00E9 preciso definir a propriedade frameworkdemoiselle.security.authenticator.class como mecanismo de autentica\u00E7\u00E3o desejado no arquivo demoiselle.properties. |
100 | -authenticator-class-not-found=A classe de autentica\u00E7\u00E3o "{0}" informada no demoiselle.properties n\u00E3o foi encontrada no classpath. | ||
101 | -authenticator-class-must-be-of-type=A classe de autentica\u00E7\u00E3o "{0}" informada no demoiselle.properties deve ser do tipo "{1}" | ||
102 | \ No newline at end of file | 97 | \ No newline at end of file |