Commit 7bba9cf73eba0430f0c7adb124eba39cc123314c
1 parent
ce421cf2
Exists in
master
Lançando exceções intuitivas e internacionalizadas para o usuário do
framework.
Showing
2 changed files
with
38 additions
and
11 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/TransactionBootstrap.java
| @@ -40,24 +40,51 @@ import javax.enterprise.event.Observes; | @@ -40,24 +40,51 @@ import javax.enterprise.event.Observes; | ||
| 40 | import javax.enterprise.inject.spi.ProcessAnnotatedType; | 40 | import javax.enterprise.inject.spi.ProcessAnnotatedType; |
| 41 | 41 | ||
| 42 | import org.apache.commons.configuration.Configuration; | 42 | import org.apache.commons.configuration.Configuration; |
| 43 | -import org.apache.commons.configuration.ConfigurationException; | ||
| 44 | import org.apache.commons.configuration.PropertiesConfiguration; | 43 | import org.apache.commons.configuration.PropertiesConfiguration; |
| 45 | 44 | ||
| 45 | +import br.gov.frameworkdemoiselle.configuration.ConfigurationException; | ||
| 46 | import br.gov.frameworkdemoiselle.internal.implementation.DefaultTransaction; | 46 | import br.gov.frameworkdemoiselle.internal.implementation.DefaultTransaction; |
| 47 | import br.gov.frameworkdemoiselle.transaction.Transaction; | 47 | import br.gov.frameworkdemoiselle.transaction.Transaction; |
| 48 | 48 | ||
| 49 | public class TransactionBootstrap extends AbstractBootstrap { | 49 | public class TransactionBootstrap extends AbstractBootstrap { |
| 50 | 50 | ||
| 51 | - public <T> void processAnnotatedType(@Observes final ProcessAnnotatedType<T> event) throws ConfigurationException { | 51 | + private static Class<Transaction> selected; |
| 52 | 52 | ||
| 53 | - Configuration config = new PropertiesConfiguration("demoiselle.properties"); | ||
| 54 | - String selected = config.getString("frameworkdemoiselle.transaction.class", | ||
| 55 | - DefaultTransaction.class.getCanonicalName()); | 53 | + public <T> void processAnnotatedType(@Observes final ProcessAnnotatedType<T> event) { |
| 54 | + Class<?> annotated = event.getAnnotatedType().getJavaClass(); | ||
| 56 | 55 | ||
| 57 | - Class<?> type = event.getAnnotatedType().getJavaClass(); | ||
| 58 | - if (Transaction.class.isAssignableFrom(type) && type != Transaction.class | ||
| 59 | - && !type.getCanonicalName().equals(selected)) { | 56 | + if (Transaction.class.isAssignableFrom(annotated) && annotated != Transaction.class |
| 57 | + && !annotated.equals(getSelected())) { | ||
| 60 | event.veto(); | 58 | event.veto(); |
| 61 | } | 59 | } |
| 62 | } | 60 | } |
| 61 | + | ||
| 62 | + @SuppressWarnings("unchecked") | ||
| 63 | + private synchronized static Class<Transaction> getSelected() { | ||
| 64 | + if (selected == null) { | ||
| 65 | + String canonicalName = null; | ||
| 66 | + | ||
| 67 | + try { | ||
| 68 | + Configuration config = new PropertiesConfiguration("demoiselle.properties"); | ||
| 69 | + canonicalName = config.getString("frameworkdemoiselle.transaction.class", | ||
| 70 | + DefaultTransaction.class.getCanonicalName()); | ||
| 71 | + | ||
| 72 | + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | ||
| 73 | + selected = (Class<Transaction>) Class.forName(canonicalName, false, classLoader); | ||
| 74 | + selected.asSubclass(Transaction.class); | ||
| 75 | + | ||
| 76 | + } catch (org.apache.commons.configuration.ConfigurationException cause) { | ||
| 77 | + throw new ConfigurationException(getBundle().getString("file-not-found", "demoiselle.properties")); | ||
| 78 | + | ||
| 79 | + } catch (ClassNotFoundException cause) { | ||
| 80 | + throw new ConfigurationException(getBundle().getString("transaction-class-not-found", canonicalName)); | ||
| 81 | + | ||
| 82 | + } catch (ClassCastException cause) { | ||
| 83 | + throw new ConfigurationException(getBundle().getString("transaction-class-must-be-of-type", | ||
| 84 | + canonicalName, Transaction.class.getCanonicalName())); | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + return selected; | ||
| 89 | + } | ||
| 63 | } | 90 | } |
impl/core/src/main/resources/demoiselle-core-bundle.properties
| @@ -58,7 +58,7 @@ configuration-attribute-is-mandatory=A configura\u00E7\u00E3o {0} \u00E9 obrigat | @@ -58,7 +58,7 @@ configuration-attribute-is-mandatory=A configura\u00E7\u00E3o {0} \u00E9 obrigat | ||
| 58 | configuration-name-attribute-cant-be-empty=A nota\u00E7\u00E3o Name n\u00E3o pode estar em branco | 58 | configuration-name-attribute-cant-be-empty=A nota\u00E7\u00E3o Name n\u00E3o pode estar em branco |
| 59 | configuration-key-not-found=Chave de configura\u00E7\u00E3o "{0}" n\u00E3o encontrada. Conven\u00E7\u00F5es verificadas\: "{1}" | 59 | configuration-key-not-found=Chave de configura\u00E7\u00E3o "{0}" n\u00E3o encontrada. Conven\u00E7\u00F5es verificadas\: "{1}" |
| 60 | 60 | ||
| 61 | -transaction-not-defined=Nenhuma transa\u00E7\u00E3o foi definida. Para utilizar @{0} \u00E9 preciso definir a estrat\u00E9gia de transa\u00E7\u00E3o desejada no arquivo beans.xml | 61 | +transaction-not-defined=Nenhuma transa\u00E7\u00E3o foi definida. Para utilizar @{0} \u00E9 preciso definir a propriedade "frameworkdemoiselle.transaction.class" com a estrat\u00E9gia de transa\u00E7\u00E3o desejada no arquivo demoiselle.properties |
| 62 | executing-all=Executando todos os \: {0} | 62 | executing-all=Executando todos os \: {0} |
| 63 | custom-context-was-registered=O contexto {0} foi registrado | 63 | custom-context-was-registered=O contexto {0} foi registrado |
| 64 | custom-context-was-unregistered=O contexto {0} foi removido | 64 | custom-context-was-unregistered=O contexto {0} foi removido |
| @@ -70,8 +70,8 @@ error-creating-new-instance-for=Error creating a new instance for "{0}" | @@ -70,8 +70,8 @@ error-creating-new-instance-for=Error creating a new instance for "{0}" | ||
| 70 | executed-successfully=\ {0} execultado com sucesso | 70 | executed-successfully=\ {0} execultado com sucesso |
| 71 | must-declare-one-single-parameter=Voc\u00EA deve declarar um par\u00E2metro \u00FAnico em {0} | 71 | must-declare-one-single-parameter=Voc\u00EA deve declarar um par\u00E2metro \u00FAnico em {0} |
| 72 | loading-default-transaction-manager=Carregando o gerenciador de transa\u00E7\u00E3o padr\u00E3o {0} | 72 | loading-default-transaction-manager=Carregando o gerenciador de transa\u00E7\u00E3o padr\u00E3o {0} |
| 73 | -transaction-class-not-found=A classe de transa\u00E7\u00E3o "{0}" informada n\u00E3o foi encontrada. | ||
| 74 | -transaction-class-must-be-of-type=A classe de transa\u00E7\u00E3o "{0}" informada deve ser do tipo {1} | 73 | +transaction-class-not-found=A classe de transa\u00E7\u00E3o "{0}" informada no demoiselle.properties n\u00E3o foi encontrada no classpath. |
| 74 | +transaction-class-must-be-of-type=A classe de transa\u00E7\u00E3o "{0}" informada no demoiselle.properties deve ser do tipo "{1}" | ||
| 75 | 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} |
| 76 | page-result=Resultado paginado [p\u00E1gina\={0}, total de resultados\={1}] | 76 | page-result=Resultado paginado [p\u00E1gina\={0}, total de resultados\={1}] |
| 77 | page=P\u00E1gina [n\u00FAmero\={0}, tamanho\={1}] | 77 | page=P\u00E1gina [n\u00FAmero\={0}, tamanho\={1}] |