Commit dfac7827c5a47caf1ee5c61409677995dde8b45e

Authored by Cleverson Sacramento
1 parent 7c0c79d6
Exists in master

Lendo o arquivo demoiselle.properties antes de tentar resolver

automaticamente as estratégias de transação e segurança
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java
... ... @@ -69,7 +69,9 @@ public class SecurityContextImpl implements SecurityContext {
69 69 private Authenticator getAuthenticator() {
70 70 if (authenticator == null) {
71 71 AuthenticatorBootstrap bootstrap = Beans.getReference(AuthenticatorBootstrap.class);
72   - authenticator = StrategySelector.getPriorityReference(bootstrap.getCache());
  72 +
  73 + authenticator = StrategySelector.getReference("frameworkdemoiselle.security.authenticator.class",
  74 + Authenticator.class, DefaultAuthenticator.class, bootstrap.getCache());
73 75 }
74 76  
75 77 return authenticator;
... ... @@ -78,7 +80,9 @@ public class SecurityContextImpl implements SecurityContext {
78 80 private Authorizer getAuthorizer() {
79 81 if (authorizer == null) {
80 82 AuthorizerBootstrap bootstrap = Beans.getReference(AuthorizerBootstrap.class);
81   - authorizer = StrategySelector.getPriorityReference(bootstrap.getCache());
  83 +
  84 + authorizer = StrategySelector.getReference("frameworkdemoiselle.security.authorizer.class",
  85 + Authorizer.class, DefaultAuthorizer.class, bootstrap.getCache());
82 86 }
83 87  
84 88 return authorizer;
... ...
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/StrategySelector.java
... ... @@ -62,7 +62,7 @@ public final class StrategySelector implements Serializable {
62 62 public static final int EXTENSIONS_L1_PRIORITY = CORE_PRIORITY - 100;
63 63  
64 64 public static final int EXTENSIONS_L2_PRIORITY = EXTENSIONS_L1_PRIORITY - 100;
65   -
  65 +
66 66 public static final int COMPONENTS_PRIORITY = EXTENSIONS_L2_PRIORITY - 100;
67 67  
68 68 private static final long serialVersionUID = 1L;
... ... @@ -70,6 +70,17 @@ public final class StrategySelector implements Serializable {
70 70 private StrategySelector() {
71 71 }
72 72  
  73 + public static <T> T getReference(String configKey, Class<T> strategyType, Class<? extends T> defaultType,
  74 + List<Class<T>> options) {
  75 + T result = getExplicitReference(configKey, strategyType, defaultType);
  76 +
  77 + if (result.getClass() == defaultType) {
  78 + result = getPriorityReference(options);
  79 + }
  80 +
  81 + return result;
  82 + }
  83 +
73 84 public static <T> T getPriorityReference(List<Class<T>> options) {
74 85 Class<T> selected = null;
75 86  
... ... @@ -77,9 +88,6 @@ public final class StrategySelector implements Serializable {
77 88 if (selected == null || getPriority(option) < getPriority(selected)) {
78 89 selected = option;
79 90 }
80   -
81   - System.out.println(option.getCanonicalName());
82   - System.out.println(selected.getCanonicalName());
83 91 }
84 92  
85 93 return Beans.getReference(selected);
... ... @@ -96,19 +104,19 @@ public final class StrategySelector implements Serializable {
96 104 return result;
97 105 }
98 106  
99   - public static <T> T getReference(String configKey, Class<T> type, Class<? extends T> defaultType) {
100   - Class<T> selectedType = loadSelected(configKey, type, defaultType);
  107 + public static <T> T getExplicitReference(String configKey, Class<T> strategyType, Class<? extends T> defaultType) {
  108 + Class<T> selectedType = loadSelected(configKey, strategyType, defaultType);
101 109 return Beans.getReference(selectedType);
102 110 }
103 111  
104 112 @SuppressWarnings("unchecked")
105   - private static <T> Class<T> loadSelected(String configKey, Class<T> type, Class<? extends T> defaultType) {
  113 + private static <T> Class<T> loadSelected(String configKey, Class<T> strategyType, Class<? extends T> defaultType) {
106 114 ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-core-bundle",
107 115 Beans.getReference(Locale.class));
108 116  
109 117 Class<T> result = null;
110 118 String canonicalName = null;
111   - String typeName = type.getSimpleName().toLowerCase();
  119 + String typeName = strategyType.getSimpleName().toLowerCase();
112 120 String key = null;
113 121  
114 122 try {
... ... @@ -122,7 +130,7 @@ public final class StrategySelector implements Serializable {
122 130 }
123 131  
124 132 result = (Class<T>) Class.forName(canonicalName, false, classLoader);
125   - result.asSubclass(type);
  133 + result.asSubclass(strategyType);
126 134  
127 135 } catch (org.apache.commons.configuration.ConfigurationException cause) {
128 136 throw new ConfigurationException(bundle.getString("file-not-found", "demoiselle.properties"));
... ... @@ -136,7 +144,7 @@ public final class StrategySelector implements Serializable {
136 144  
137 145 } catch (ClassCastException cause) {
138 146 key = Strings.getString("{0}-class-must-be-of-type", typeName);
139   - throw new ConfigurationException(bundle.getString(key, canonicalName, type));
  147 + throw new ConfigurationException(bundle.getString(key, canonicalName, strategyType));
140 148 }
141 149  
142 150 return result;
... ...
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionContextImpl.java
... ... @@ -58,7 +58,9 @@ public class TransactionContextImpl implements TransactionContext {
58 58 private Transaction getTransaction() {
59 59 if (this.transaction == null) {
60 60 TransactionBootstrap bootstrap = Beans.getReference(TransactionBootstrap.class);
61   - this.transaction = StrategySelector.getPriorityReference(bootstrap.getCache());
  61 +
  62 + this.transaction = StrategySelector.getReference("frameworkdemoiselle.transaction.class",
  63 + Transaction.class, DefaultTransaction.class, bootstrap.getCache());
62 64 }
63 65  
64 66 return this.transaction;
... ...