Commit 70c96c51a51b68755d938f9be3c30aeee2be2ce6

Authored by Wilson Guimarães
1 parent 66ace1f1
Exists in master

Alteração do bootstrap de transação para extender a abstração de

bootstraps.
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/TransactionBootstrap.java
@@ -36,59 +36,13 @@ @@ -36,59 +36,13 @@
36 */ 36 */
37 package br.gov.frameworkdemoiselle.internal.bootstrap; 37 package br.gov.frameworkdemoiselle.internal.bootstrap;
38 38
39 -import javax.enterprise.event.Observes;  
40 -import javax.enterprise.inject.spi.BeforeBeanDiscovery;  
41 -import javax.enterprise.inject.spi.ProcessAnnotatedType;  
42 -  
43 -import org.apache.commons.configuration.Configuration;  
44 -import org.apache.commons.configuration.PropertiesConfiguration;  
45 -  
46 -import br.gov.frameworkdemoiselle.configuration.ConfigurationException;  
47 import br.gov.frameworkdemoiselle.internal.implementation.DefaultTransaction; 39 import br.gov.frameworkdemoiselle.internal.implementation.DefaultTransaction;
48 import br.gov.frameworkdemoiselle.transaction.Transaction; 40 import br.gov.frameworkdemoiselle.transaction.Transaction;
49 -import br.gov.frameworkdemoiselle.util.Reflections;  
50 -  
51 -public class TransactionBootstrap extends AbstractBootstrap {  
52 -  
53 - private static Class<? extends Transaction> selected = loadSelected();  
54 -  
55 - public void beforeBeanDiscovery(@Observes final BeforeBeanDiscovery event) {  
56 - selected = loadSelected();  
57 - }  
58 41
59 - public <T> void processAnnotatedType(@Observes final ProcessAnnotatedType<T> event) {  
60 - Class<T> annotated = event.getAnnotatedType().getJavaClass(); 42 +public class TransactionBootstrap extends AbstractStrategyBootstrap<Transaction, DefaultTransaction> {
61 43
62 - if (Reflections.isOfType(annotated, Transaction.class) && annotated != selected) {  
63 - event.veto();  
64 - } 44 + public String getConfigurationKey() {
  45 + return "frameworkdemoiselle.transaction.class";
65 } 46 }
66 47
67 - @SuppressWarnings("unchecked")  
68 - private static Class<Transaction> loadSelected() {  
69 - Class<Transaction> result = null;  
70 - String canonicalName = null;  
71 -  
72 - try {  
73 - Configuration config = new PropertiesConfiguration("demoiselle.properties");  
74 - canonicalName = config.getString("frameworkdemoiselle.transaction.class",  
75 - DefaultTransaction.class.getCanonicalName());  
76 -  
77 - ClassLoader classLoader = Thread.currentThread().getContextClassLoader();  
78 - result = (Class<Transaction>) Class.forName(canonicalName, false, classLoader);  
79 - result.asSubclass(Transaction.class);  
80 -  
81 - } catch (org.apache.commons.configuration.ConfigurationException cause) {  
82 - throw new ConfigurationException(getBundle().getString("file-not-found", "demoiselle.properties"));  
83 -  
84 - } catch (ClassNotFoundException cause) {  
85 - throw new ConfigurationException(getBundle().getString("transaction-class-not-found", canonicalName));  
86 -  
87 - } catch (ClassCastException cause) {  
88 - throw new ConfigurationException(getBundle().getString("transaction-class-must-be-of-type", canonicalName,  
89 - Transaction.class.getCanonicalName()));  
90 - }  
91 -  
92 - return result;  
93 - }  
94 } 48 }