Commit dfac7827c5a47caf1ee5c61409677995dde8b45e
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
Showing
3 changed files
with
27 additions
and
13 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java
| @@ -69,7 +69,9 @@ public class SecurityContextImpl implements SecurityContext { | @@ -69,7 +69,9 @@ public class SecurityContextImpl implements SecurityContext { | ||
| 69 | private Authenticator getAuthenticator() { | 69 | private Authenticator getAuthenticator() { |
| 70 | if (authenticator == null) { | 70 | if (authenticator == null) { |
| 71 | AuthenticatorBootstrap bootstrap = Beans.getReference(AuthenticatorBootstrap.class); | 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 | return authenticator; | 77 | return authenticator; |
| @@ -78,7 +80,9 @@ public class SecurityContextImpl implements SecurityContext { | @@ -78,7 +80,9 @@ public class SecurityContextImpl implements SecurityContext { | ||
| 78 | private Authorizer getAuthorizer() { | 80 | private Authorizer getAuthorizer() { |
| 79 | if (authorizer == null) { | 81 | if (authorizer == null) { |
| 80 | AuthorizerBootstrap bootstrap = Beans.getReference(AuthorizerBootstrap.class); | 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 | return authorizer; | 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,7 +62,7 @@ public final class StrategySelector implements Serializable { | ||
| 62 | public static final int EXTENSIONS_L1_PRIORITY = CORE_PRIORITY - 100; | 62 | public static final int EXTENSIONS_L1_PRIORITY = CORE_PRIORITY - 100; |
| 63 | 63 | ||
| 64 | public static final int EXTENSIONS_L2_PRIORITY = EXTENSIONS_L1_PRIORITY - 100; | 64 | public static final int EXTENSIONS_L2_PRIORITY = EXTENSIONS_L1_PRIORITY - 100; |
| 65 | - | 65 | + |
| 66 | public static final int COMPONENTS_PRIORITY = EXTENSIONS_L2_PRIORITY - 100; | 66 | public static final int COMPONENTS_PRIORITY = EXTENSIONS_L2_PRIORITY - 100; |
| 67 | 67 | ||
| 68 | private static final long serialVersionUID = 1L; | 68 | private static final long serialVersionUID = 1L; |
| @@ -70,6 +70,17 @@ public final class StrategySelector implements Serializable { | @@ -70,6 +70,17 @@ public final class StrategySelector implements Serializable { | ||
| 70 | private StrategySelector() { | 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 | public static <T> T getPriorityReference(List<Class<T>> options) { | 84 | public static <T> T getPriorityReference(List<Class<T>> options) { |
| 74 | Class<T> selected = null; | 85 | Class<T> selected = null; |
| 75 | 86 | ||
| @@ -77,9 +88,6 @@ public final class StrategySelector implements Serializable { | @@ -77,9 +88,6 @@ public final class StrategySelector implements Serializable { | ||
| 77 | if (selected == null || getPriority(option) < getPriority(selected)) { | 88 | if (selected == null || getPriority(option) < getPriority(selected)) { |
| 78 | selected = option; | 89 | selected = option; |
| 79 | } | 90 | } |
| 80 | - | ||
| 81 | - System.out.println(option.getCanonicalName()); | ||
| 82 | - System.out.println(selected.getCanonicalName()); | ||
| 83 | } | 91 | } |
| 84 | 92 | ||
| 85 | return Beans.getReference(selected); | 93 | return Beans.getReference(selected); |
| @@ -96,19 +104,19 @@ public final class StrategySelector implements Serializable { | @@ -96,19 +104,19 @@ public final class StrategySelector implements Serializable { | ||
| 96 | return result; | 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 | return Beans.getReference(selectedType); | 109 | return Beans.getReference(selectedType); |
| 102 | } | 110 | } |
| 103 | 111 | ||
| 104 | @SuppressWarnings("unchecked") | 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 | ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-core-bundle", | 114 | ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-core-bundle", |
| 107 | Beans.getReference(Locale.class)); | 115 | Beans.getReference(Locale.class)); |
| 108 | 116 | ||
| 109 | Class<T> result = null; | 117 | Class<T> result = null; |
| 110 | String canonicalName = null; | 118 | String canonicalName = null; |
| 111 | - String typeName = type.getSimpleName().toLowerCase(); | 119 | + String typeName = strategyType.getSimpleName().toLowerCase(); |
| 112 | String key = null; | 120 | String key = null; |
| 113 | 121 | ||
| 114 | try { | 122 | try { |
| @@ -122,7 +130,7 @@ public final class StrategySelector implements Serializable { | @@ -122,7 +130,7 @@ public final class StrategySelector implements Serializable { | ||
| 122 | } | 130 | } |
| 123 | 131 | ||
| 124 | result = (Class<T>) Class.forName(canonicalName, false, classLoader); | 132 | result = (Class<T>) Class.forName(canonicalName, false, classLoader); |
| 125 | - result.asSubclass(type); | 133 | + result.asSubclass(strategyType); |
| 126 | 134 | ||
| 127 | } catch (org.apache.commons.configuration.ConfigurationException cause) { | 135 | } catch (org.apache.commons.configuration.ConfigurationException cause) { |
| 128 | throw new ConfigurationException(bundle.getString("file-not-found", "demoiselle.properties")); | 136 | throw new ConfigurationException(bundle.getString("file-not-found", "demoiselle.properties")); |
| @@ -136,7 +144,7 @@ public final class StrategySelector implements Serializable { | @@ -136,7 +144,7 @@ public final class StrategySelector implements Serializable { | ||
| 136 | 144 | ||
| 137 | } catch (ClassCastException cause) { | 145 | } catch (ClassCastException cause) { |
| 138 | key = Strings.getString("{0}-class-must-be-of-type", typeName); | 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 | return result; | 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,7 +58,9 @@ public class TransactionContextImpl implements TransactionContext { | ||
| 58 | private Transaction getTransaction() { | 58 | private Transaction getTransaction() { |
| 59 | if (this.transaction == null) { | 59 | if (this.transaction == null) { |
| 60 | TransactionBootstrap bootstrap = Beans.getReference(TransactionBootstrap.class); | 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 | return this.transaction; | 66 | return this.transaction; |