diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java index d727cc6..7883d50 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java @@ -69,7 +69,9 @@ public class SecurityContextImpl implements SecurityContext { private Authenticator getAuthenticator() { if (authenticator == null) { AuthenticatorBootstrap bootstrap = Beans.getReference(AuthenticatorBootstrap.class); - authenticator = StrategySelector.getPriorityReference(bootstrap.getCache()); + + authenticator = StrategySelector.getReference("frameworkdemoiselle.security.authenticator.class", + Authenticator.class, DefaultAuthenticator.class, bootstrap.getCache()); } return authenticator; @@ -78,7 +80,9 @@ public class SecurityContextImpl implements SecurityContext { private Authorizer getAuthorizer() { if (authorizer == null) { AuthorizerBootstrap bootstrap = Beans.getReference(AuthorizerBootstrap.class); - authorizer = StrategySelector.getPriorityReference(bootstrap.getCache()); + + authorizer = StrategySelector.getReference("frameworkdemoiselle.security.authorizer.class", + Authorizer.class, DefaultAuthorizer.class, bootstrap.getCache()); } return authorizer; diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/StrategySelector.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/StrategySelector.java index c949f84..d620198 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/StrategySelector.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/StrategySelector.java @@ -62,7 +62,7 @@ public final class StrategySelector implements Serializable { public static final int EXTENSIONS_L1_PRIORITY = CORE_PRIORITY - 100; public static final int EXTENSIONS_L2_PRIORITY = EXTENSIONS_L1_PRIORITY - 100; - + public static final int COMPONENTS_PRIORITY = EXTENSIONS_L2_PRIORITY - 100; private static final long serialVersionUID = 1L; @@ -70,6 +70,17 @@ public final class StrategySelector implements Serializable { private StrategySelector() { } + public static T getReference(String configKey, Class strategyType, Class defaultType, + List> options) { + T result = getExplicitReference(configKey, strategyType, defaultType); + + if (result.getClass() == defaultType) { + result = getPriorityReference(options); + } + + return result; + } + public static T getPriorityReference(List> options) { Class selected = null; @@ -77,9 +88,6 @@ public final class StrategySelector implements Serializable { if (selected == null || getPriority(option) < getPriority(selected)) { selected = option; } - - System.out.println(option.getCanonicalName()); - System.out.println(selected.getCanonicalName()); } return Beans.getReference(selected); @@ -96,19 +104,19 @@ public final class StrategySelector implements Serializable { return result; } - public static T getReference(String configKey, Class type, Class defaultType) { - Class selectedType = loadSelected(configKey, type, defaultType); + public static T getExplicitReference(String configKey, Class strategyType, Class defaultType) { + Class selectedType = loadSelected(configKey, strategyType, defaultType); return Beans.getReference(selectedType); } @SuppressWarnings("unchecked") - private static Class loadSelected(String configKey, Class type, Class defaultType) { + private static Class loadSelected(String configKey, Class strategyType, Class defaultType) { ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Beans.getReference(Locale.class)); Class result = null; String canonicalName = null; - String typeName = type.getSimpleName().toLowerCase(); + String typeName = strategyType.getSimpleName().toLowerCase(); String key = null; try { @@ -122,7 +130,7 @@ public final class StrategySelector implements Serializable { } result = (Class) Class.forName(canonicalName, false, classLoader); - result.asSubclass(type); + result.asSubclass(strategyType); } catch (org.apache.commons.configuration.ConfigurationException cause) { throw new ConfigurationException(bundle.getString("file-not-found", "demoiselle.properties")); @@ -136,7 +144,7 @@ public final class StrategySelector implements Serializable { } catch (ClassCastException cause) { key = Strings.getString("{0}-class-must-be-of-type", typeName); - throw new ConfigurationException(bundle.getString(key, canonicalName, type)); + throw new ConfigurationException(bundle.getString(key, canonicalName, strategyType)); } return result; diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionContextImpl.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionContextImpl.java index f761598..a707baf 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionContextImpl.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionContextImpl.java @@ -58,7 +58,9 @@ public class TransactionContextImpl implements TransactionContext { private Transaction getTransaction() { if (this.transaction == null) { TransactionBootstrap bootstrap = Beans.getReference(TransactionBootstrap.class); - this.transaction = StrategySelector.getPriorityReference(bootstrap.getCache()); + + this.transaction = StrategySelector.getReference("frameworkdemoiselle.transaction.class", + Transaction.class, DefaultTransaction.class, bootstrap.getCache()); } return this.transaction; -- libgit2 0.21.2