diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Strategy.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Strategy.java
new file mode 100644
index 0000000..8c97d9a
--- /dev/null
+++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Strategy.java
@@ -0,0 +1,89 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package br.gov.frameworkdemoiselle.annotation;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+/**
+ * This annotation is used to make passible:
+ *
+ * - map an attribute that belongs to a configuration class in a key with a different name of this attribute
+ * - map a Resource Bundle object to a file with different name of this object
+ *
+ *
+ * The examples below shows how these annotation could be used:
+ *
+ *
+ *
+ *
+ * public class NameConfig {
+ *
+ * @AmbiguousQualifier("other.name.attrib")
+ * private int nameOfAttribute;
+ * ...
+ * }
+ *
+ * public class NameResourceBundle {
+ *
+ * @AmbiguousQualifier("other.name.bundle")
+ * @Inject
+ * private ResourceBundle bundle;
+ * ...
+ * }
+ *
+ *
+ *
+ *
+ * @author SERPRO
+ */
+@Qualifier
+@Inherited
+@Retention(RUNTIME)
+@Target({ TYPE, FIELD, METHOD, PARAMETER })
+public @interface Strategy {
+
+}
diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContextProducer.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContextProducer.java
index 1c7adbe..6ea2e05 100644
--- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContextProducer.java
+++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContextProducer.java
@@ -67,8 +67,8 @@ import br.gov.frameworkdemoiselle.context.SessionContext;
import br.gov.frameworkdemoiselle.context.StaticContext;
import br.gov.frameworkdemoiselle.context.ViewContext;
import br.gov.frameworkdemoiselle.internal.bootstrap.CustomContextBootstrap;
-import br.gov.frameworkdemoiselle.internal.implementation.StrategySelector;
import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
+import br.gov.frameworkdemoiselle.internal.producer.StrategySelector;
import br.gov.frameworkdemoiselle.util.Beans;
import br.gov.frameworkdemoiselle.util.ResourceBundle;
@@ -235,7 +235,7 @@ public class CustomContextProducer {
}
if (producedContext == null && !selectableContexts.isEmpty()) {
- producedContext = StrategySelector.selectInstance(CustomContext.class, selectableContexts);
+ producedContext = StrategySelector.selectReference(CustomContext.class, selectableContexts);
}
return (T) producedContext;
diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationLoader.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationLoader.java
index 154b156..42c711b 100644
--- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationLoader.java
+++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationLoader.java
@@ -67,6 +67,7 @@ import br.gov.frameworkdemoiselle.configuration.Configuration;
import br.gov.frameworkdemoiselle.configuration.ConfigurationException;
import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor;
import br.gov.frameworkdemoiselle.internal.bootstrap.ConfigurationBootstrap;
+import br.gov.frameworkdemoiselle.internal.producer.StrategySelector;
import br.gov.frameworkdemoiselle.util.Beans;
import br.gov.frameworkdemoiselle.util.NameQualifier;
import br.gov.frameworkdemoiselle.util.Reflections;
@@ -267,7 +268,7 @@ public class ConfigurationLoader implements Serializable {
}
}
- ConfigurationValueExtractor elected = StrategySelector.selectInstance(ConfigurationValueExtractor.class,
+ ConfigurationValueExtractor elected = StrategySelector.selectReference(ConfigurationValueExtractor.class,
candidates);
if (elected == null) {
diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MessageContextImpl.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MessageContextImpl.java
index 1ee44ca..2d0fff0 100644
--- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MessageContextImpl.java
+++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MessageContextImpl.java
@@ -43,6 +43,7 @@ import br.gov.frameworkdemoiselle.message.MessageAppender;
import br.gov.frameworkdemoiselle.message.MessageContext;
import br.gov.frameworkdemoiselle.message.SeverityType;
import br.gov.frameworkdemoiselle.util.Beans;
+import br.gov.frameworkdemoiselle.util.StrategyQualifier;
/**
* The message store is designed to provide access to messages. It is shared by every application layer.
@@ -54,9 +55,7 @@ public class MessageContextImpl implements Serializable, MessageContext {
private static final long serialVersionUID = 1L;
private MessageAppender getAppender() {
- Class extends MessageAppender> appenderClass = StrategySelector.selectClass(MessageAppender.class);
-
- return Beans.getReference(appenderClass);
+ return Beans.getReference(MessageAppender.class, new StrategyQualifier());
}
@Override
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 77211ca..18b1703 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
@@ -54,6 +54,7 @@ import br.gov.frameworkdemoiselle.security.SecurityContext;
import br.gov.frameworkdemoiselle.util.Beans;
import br.gov.frameworkdemoiselle.util.NameQualifier;
import br.gov.frameworkdemoiselle.util.ResourceBundle;
+import br.gov.frameworkdemoiselle.util.StrategyQualifier;
/**
* This is the default implementation of {@link SecurityContext} interface.
@@ -73,13 +74,13 @@ public class SecurityContextImpl implements SecurityContext {
private Authenticator getAuthenticator() {
if (this.authenticator == null) {
- Class extends Authenticator> clazz = getConfig().getAuthenticatorClass();
+ Class extends Authenticator> type = getConfig().getAuthenticatorClass();
- if (clazz == null) {
- clazz = StrategySelector.selectClass(Authenticator.class);
+ if (type != null) {
+ this.authenticator = Beans.getReference(type);
+ } else {
+ this.authenticator = Beans.getReference(Authenticator.class, new StrategyQualifier());
}
-
- this.authenticator = Beans.getReference(clazz);
}
return this.authenticator;
@@ -87,13 +88,13 @@ public class SecurityContextImpl implements SecurityContext {
private Authorizer getAuthorizer() {
if (this.authorizer == null) {
- Class extends Authorizer> clazz = getConfig().getAuthorizerClass();
+ Class extends Authorizer> type = getConfig().getAuthorizerClass();
- if (clazz == null) {
- clazz = StrategySelector.selectClass(Authorizer.class);
+ if (type != null) {
+ this.authorizer = Beans.getReference(type);
+ } else {
+ this.authorizer = Beans.getReference(Authorizer.class, new StrategyQualifier());
}
-
- this.authorizer = Beans.getReference(clazz);
}
return this.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
deleted file mode 100644
index 279f168..0000000
--- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/StrategySelector.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Demoiselle Framework
- * Copyright (C) 2010 SERPRO
- * ----------------------------------------------------------------------------
- * This file is part of Demoiselle Framework.
- *
- * Demoiselle Framework is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License version 3
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License version 3
- * along with this program; if not, see
- * or write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- * ----------------------------------------------------------------------------
- * Este arquivo é parte do Framework Demoiselle.
- *
- * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
- * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
- * do Software Livre (FSF).
- *
- * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
- * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
- * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
- * para maiores detalhes.
- *
- * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
- * "LICENCA.txt", junto com esse programa. Se não, acesse
- * ou escreva para a Fundação do Software Livre (FSF) Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
- */
-package br.gov.frameworkdemoiselle.internal.implementation;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.enterprise.inject.AmbiguousResolutionException;
-import javax.enterprise.inject.spi.Bean;
-
-import br.gov.frameworkdemoiselle.DemoiselleException;
-import br.gov.frameworkdemoiselle.annotation.Priority;
-import br.gov.frameworkdemoiselle.util.Beans;
-import br.gov.frameworkdemoiselle.util.NameQualifier;
-import br.gov.frameworkdemoiselle.util.ResourceBundle;
-
-public final class StrategySelector implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private StrategySelector() {
- }
-
- @SuppressWarnings("unchecked")
- public static T selectInstance(Class type, Collection extends T> options) {
-
- Map, T> map = new HashMap, T>();
-
- for (T instance : options) {
- if (instance != null) {
- map.put((Class) instance.getClass(), instance);
- }
- }
-
- Class extends T> elected = selectClass(type, map.keySet());
- return map.get(elected);
- }
-
- private static Class extends T> selectClass(Class type, Collection> options) {
- Class extends T> selected = null;
-
- for (Class extends T> option : options) {
- if (selected == null || getPriority(option) < getPriority(selected)) {
- selected = option;
- }
- }
-
- if (selected != null) {
- performAmbiguityCheck(type, selected, options);
- }
-
- return selected;
- }
-
- public static Class extends T> selectClass(Class type) {
- return selectClass(type, getOptions(type));
- }
-
- @SuppressWarnings("unchecked")
- private static Collection> getOptions(Class type) {
- Set> result = new HashSet>();
-
- for (Bean> bean : Beans.getBeanManager().getBeans(type)) {
- result.add((Class extends T>) bean.getBeanClass());
- }
-
- return result;
- }
-
- private static void performAmbiguityCheck(Class type, Class extends T> selected,
- Collection> options) {
- int selectedPriority = getPriority(selected);
-
- List> ambiguous = new ArrayList>();
-
- for (Class extends T> option : options) {
- if (selected != option && selectedPriority == getPriority(option)) {
- ambiguous.add(option);
- }
- }
-
- if (!ambiguous.isEmpty()) {
- ambiguous.add(selected);
-
- String message = getExceptionMessage(type, ambiguous);
- throw new DemoiselleException(message, new AmbiguousResolutionException());
- }
- }
-
- private static String getExceptionMessage(Class type, List> ambiguous) {
- StringBuffer classes = new StringBuffer();
-
- int i = 0;
- for (Class extends T> clazz : ambiguous) {
- if (i++ != 0) {
- classes.append(", ");
- }
-
- classes.append(clazz.getCanonicalName());
- }
-
- return getBundle().getString("ambiguous-strategy-resolution", type.getCanonicalName(), classes.toString());
- }
-
- private static int getPriority(Class type) {
- int result = Priority.MAX_PRIORITY;
- Priority priority = type.getAnnotation(Priority.class);
-
- if (priority != null) {
- result = priority.value();
- }
-
- return result;
- }
-
- private static ResourceBundle getBundle() {
- return Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle"));
- }
-}
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 55be8bc..29d367f 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
@@ -42,6 +42,7 @@ import br.gov.frameworkdemoiselle.internal.configuration.TransactionConfig;
import br.gov.frameworkdemoiselle.transaction.Transaction;
import br.gov.frameworkdemoiselle.transaction.TransactionContext;
import br.gov.frameworkdemoiselle.util.Beans;
+import br.gov.frameworkdemoiselle.util.StrategyQualifier;
/**
* This is the default implementation of {@link TransactionContext} interface.
@@ -58,13 +59,13 @@ public class TransactionContextImpl implements TransactionContext {
@Override
public Transaction getCurrentTransaction() {
if (this.transaction == null) {
- Class extends Transaction> clazz = getConfig().getTransactionClass();
+ Class extends Transaction> type = getConfig().getTransactionClass();
- if (clazz == null) {
- clazz = StrategySelector.selectClass(Transaction.class);
+ if (type != null) {
+ this.transaction = Beans.getReference(type);
+ } else {
+ this.transaction = Beans.getReference(Transaction.class, new StrategyQualifier());
}
-
- this.transaction = Beans.getReference(clazz);
}
return this.transaction;
diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AuthenticatorProducer.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AuthenticatorProducer.java
new file mode 100644
index 0000000..f365938
--- /dev/null
+++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AuthenticatorProducer.java
@@ -0,0 +1,51 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package br.gov.frameworkdemoiselle.internal.producer;
+
+import javax.enterprise.inject.Produces;
+
+import br.gov.frameworkdemoiselle.annotation.Strategy;
+import br.gov.frameworkdemoiselle.security.Authenticator;
+
+public class AuthenticatorProducer {
+
+ @Produces
+ @Strategy
+ public Authenticator create() {
+ return StrategySelector.selectReference(Authenticator.class);
+ }
+}
diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AuthorizerProducer.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AuthorizerProducer.java
new file mode 100644
index 0000000..8e84c61
--- /dev/null
+++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AuthorizerProducer.java
@@ -0,0 +1,51 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package br.gov.frameworkdemoiselle.internal.producer;
+
+import javax.enterprise.inject.Produces;
+
+import br.gov.frameworkdemoiselle.annotation.Strategy;
+import br.gov.frameworkdemoiselle.security.Authorizer;
+
+public class AuthorizerProducer {
+
+ @Produces
+ @Strategy
+ public Authorizer create() {
+ return StrategySelector.selectReference(Authorizer.class);
+ }
+}
diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ConfigurationValueExtractorProducer.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ConfigurationValueExtractorProducer.java
new file mode 100644
index 0000000..f0175de
--- /dev/null
+++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ConfigurationValueExtractorProducer.java
@@ -0,0 +1,51 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package br.gov.frameworkdemoiselle.internal.producer;
+
+import javax.enterprise.inject.Produces;
+
+import br.gov.frameworkdemoiselle.annotation.Strategy;
+import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor;
+
+public class ConfigurationValueExtractorProducer {
+
+ @Produces
+ @Strategy
+ public ConfigurationValueExtractor create() {
+ return StrategySelector.selectReference(ConfigurationValueExtractor.class);
+ }
+}
diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/MessageAppenderProducer.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/MessageAppenderProducer.java
new file mode 100644
index 0000000..2852c75
--- /dev/null
+++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/MessageAppenderProducer.java
@@ -0,0 +1,51 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package br.gov.frameworkdemoiselle.internal.producer;
+
+import javax.enterprise.inject.Produces;
+
+import br.gov.frameworkdemoiselle.annotation.Strategy;
+import br.gov.frameworkdemoiselle.message.MessageAppender;
+
+public class MessageAppenderProducer {
+
+ @Produces
+ @Strategy
+ public MessageAppender create() {
+ return StrategySelector.selectReference(MessageAppender.class);
+ }
+}
diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/StrategySelector.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/StrategySelector.java
new file mode 100644
index 0000000..0a60272
--- /dev/null
+++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/StrategySelector.java
@@ -0,0 +1,165 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package br.gov.frameworkdemoiselle.internal.producer;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.enterprise.inject.AmbiguousResolutionException;
+import javax.enterprise.inject.spi.Bean;
+
+import br.gov.frameworkdemoiselle.DemoiselleException;
+import br.gov.frameworkdemoiselle.annotation.Priority;
+import br.gov.frameworkdemoiselle.util.Beans;
+import br.gov.frameworkdemoiselle.util.NameQualifier;
+import br.gov.frameworkdemoiselle.util.ResourceBundle;
+
+public final class StrategySelector implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private StrategySelector() {
+ }
+
+ @SuppressWarnings("unchecked")
+ public static T selectReference(Class type, Collection extends T> options) {
+
+ Map, T> map = new HashMap, T>();
+
+ for (T instance : options) {
+ if (instance != null) {
+ map.put((Class) instance.getClass(), instance);
+ }
+ }
+
+ Class extends T> elected = selectClass(type, map.keySet());
+ return map.get(elected);
+ }
+
+ protected static T selectReference(Class type) {
+ Class extends T> selected = selectClass(type, getOptions(type));
+ return Beans.getReference(selected);
+ }
+
+ protected static Class extends T> selectClass(Class type) {
+ return selectClass(type, getOptions(type));
+ }
+
+ private static Class extends T> selectClass(Class type, Collection> options) {
+ Class extends T> selected = null;
+
+ for (Class extends T> option : options) {
+ if (selected == null || getPriority(option) < getPriority(selected)) {
+ selected = option;
+ }
+ }
+
+ if (selected != null) {
+ performAmbiguityCheck(type, selected, options);
+ }
+
+ return selected;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static Collection> getOptions(Class type, Annotation... qualifiers) {
+ Set> result = new HashSet>();
+
+ for (Bean> bean : Beans.getBeanManager().getBeans(type, qualifiers)) {
+ result.add((Class extends T>) bean.getBeanClass());
+ }
+
+ return result;
+ }
+
+ private static void performAmbiguityCheck(Class type, Class extends T> selected,
+ Collection> options) {
+ int selectedPriority = getPriority(selected);
+
+ List> ambiguous = new ArrayList>();
+
+ for (Class extends T> option : options) {
+ if (selected != option && selectedPriority == getPriority(option)) {
+ ambiguous.add(option);
+ }
+ }
+
+ if (!ambiguous.isEmpty()) {
+ ambiguous.add(selected);
+
+ String message = getExceptionMessage(type, ambiguous);
+ throw new DemoiselleException(message, new AmbiguousResolutionException());
+ }
+ }
+
+ private static String getExceptionMessage(Class type, List> ambiguous) {
+ StringBuffer classes = new StringBuffer();
+
+ int i = 0;
+ for (Class extends T> clazz : ambiguous) {
+ if (i++ != 0) {
+ classes.append(", ");
+ }
+
+ classes.append(clazz.getCanonicalName());
+ }
+
+ return getBundle().getString("ambiguous-strategy-resolution", type.getCanonicalName(), classes.toString());
+ }
+
+ private static int getPriority(Class type) {
+ int result = Priority.MAX_PRIORITY;
+ Priority priority = type.getAnnotation(Priority.class);
+
+ if (priority != null) {
+ result = priority.value();
+ }
+
+ return result;
+ }
+
+ private static ResourceBundle getBundle() {
+ return Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle"));
+ }
+}
diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/TransactionProducer.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/TransactionProducer.java
new file mode 100644
index 0000000..c1a2ce3
--- /dev/null
+++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/TransactionProducer.java
@@ -0,0 +1,51 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package br.gov.frameworkdemoiselle.internal.producer;
+
+import javax.enterprise.inject.Produces;
+
+import br.gov.frameworkdemoiselle.annotation.Strategy;
+import br.gov.frameworkdemoiselle.transaction.Transaction;
+
+public class TransactionProducer {
+
+ @Produces
+ @Strategy
+ public Transaction create() {
+ return StrategySelector.selectReference(Transaction.class);
+ }
+}
diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Beans.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Beans.java
index da5bdd6..8b4030f 100644
--- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Beans.java
+++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Beans.java
@@ -112,30 +112,6 @@ public final class Beans {
}
/**
- * Obtains a injectble instance of a bean, which have the given required type and are available for injection in the
- * point where this method was call.
- *
- * @param beanClass
- * the beanClass which instace is requested to be obtained.
- * @return Type a instace of the injected beanClass.
- * @throws DemoiselleException
- * if no bean are avaliable to be injected for the given Class.
- */
- public static T getReference(final Class beanClass) {
- T instance;
-
- try {
- instance = (T) getReference(getBeanManager().getBeans(beanClass), beanClass);
-
- } catch (NoSuchElementException cause) {
- String message = getBundle().getString("bean-not-found", beanClass.getCanonicalName());
- throw new DemoiselleException(message, cause);
- }
-
- return instance;
- }
-
- /**
* Obtains a injectble instance of a bean, which have the given EL name and are available for injection in the point
* where this method was call.
*
diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/util/StrategyQualifier.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/util/StrategyQualifier.java
new file mode 100644
index 0000000..d65c527
--- /dev/null
+++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/util/StrategyQualifier.java
@@ -0,0 +1,58 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package br.gov.frameworkdemoiselle.util;
+
+import java.lang.annotation.Annotation;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+import util.beans.ambiguous.AmbiguousQualifier;
+import br.gov.frameworkdemoiselle.annotation.Name;
+import br.gov.frameworkdemoiselle.annotation.Strategy;
+
+/**
+ * Annotation litteral that allows to create instances of the {@link Name} qualifier. The created instance can then be
+ * used to call {@link Beans#getReference(Class type, Annotation... qualifiers)}.
+ *
+ * @see Beans
+ * @see AmbiguousQualifier
+ * @author SERPRO
+ */
+@SuppressWarnings("all")
+public class StrategyQualifier extends AnnotationLiteral implements Strategy {
+
+}
diff --git a/impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerFactoryProducer.java b/impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerFactoryProducer.java
index ed205cf..76d499a 100644
--- a/impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerFactoryProducer.java
+++ b/impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerFactoryProducer.java
@@ -65,22 +65,20 @@ import org.w3c.dom.NodeList;
import br.gov.frameworkdemoiselle.DemoiselleException;
import br.gov.frameworkdemoiselle.annotation.Name;
import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig;
+import br.gov.frameworkdemoiselle.util.Beans;
+import br.gov.frameworkdemoiselle.util.NameQualifier;
import br.gov.frameworkdemoiselle.util.ResourceBundle;
@ApplicationScoped
-// @StaticScoped
public class EntityManagerFactoryProducer implements Serializable {
private static final long serialVersionUID = 1L;
private static final String ENTITY_MANAGER_RESOURCE = "META-INF/persistence.xml";
- @Inject
- protected Logger logger;
+ private transient Logger logger;
- @Inject
- @Name("demoiselle-jpa-bundle")
- protected ResourceBundle bundle;
+ private transient ResourceBundle bundle;
@Inject
private Persistences persistenceUnitReader;
@@ -143,7 +141,8 @@ public class EntityManagerFactoryProducer implements Serializable {
persistenceUnit = ((Element) node).getAttribute("name");
if ("".equals(persistenceUnit)) {
- throw new DemoiselleException(bundle.getString("can-not-get-persistence-unit-from-persistence"));
+ throw new DemoiselleException(getBundle()
+ .getString("can-not-get-persistence-unit-from-persistence"));
} else {
persistenceUnits.add(persistenceUnit);
}
@@ -152,8 +151,8 @@ public class EntityManagerFactoryProducer implements Serializable {
return persistenceUnits.toArray(new String[0]);
} catch (Exception cause) {
- String message = bundle.getString("can-not-get-persistence-unit-from-persistence");
- logger.log(SEVERE, message, cause);
+ String message = getBundle().getString("can-not-get-persistence-unit-from-persistence");
+ getLogger().log(SEVERE, message, cause);
throw new DemoiselleException(message, cause);
}
@@ -171,7 +170,7 @@ public class EntityManagerFactoryProducer implements Serializable {
throw new DemoiselleException(cause);
}
- logger.fine(bundle.getString("persistence-unit-name-found", persistenceUnit));
+ getLogger().fine(getBundle().getString("persistence-unit-name-found", persistenceUnit));
}
}
@@ -190,7 +189,7 @@ public class EntityManagerFactoryProducer implements Serializable {
Map result = factoryCache.get(classLoader);
if (result == null || result.isEmpty()) {
- logger.fine(bundle.getString("entity-manager-factory-not-found-in-cache"));
+ getLogger().fine(getBundle().getString("entity-manager-factory-not-found-in-cache"));
for (String persistenceUnit : loadPersistenceUnitFromClassloader(classLoader)) {
create(persistenceUnit);
result = factoryCache.get(classLoader);
@@ -199,4 +198,21 @@ public class EntityManagerFactoryProducer implements Serializable {
return result;
}
+
+ private ResourceBundle getBundle() {
+ if (bundle == null) {
+ bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-jpa-bundle"));
+ }
+
+ return bundle;
+ }
+
+ private Logger getLogger() {
+ if (logger == null) {
+ logger = Beans.getReference(Logger.class, new NameQualifier("br.gov.frameworkdemoiselle.util"));
+
+ }
+
+ return logger;
+ }
}
diff --git a/impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerProducer.java b/impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerProducer.java
index 03f2b2a..86268bc 100644
--- a/impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerProducer.java
+++ b/impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerProducer.java
@@ -66,7 +66,7 @@ public class EntityManagerProducer implements Serializable {
private Instance storeInstance;
@Inject
- private EntityManagerConfig configuration;
+ private EntityManagerConfig config;
@Inject
private Persistences persistenceUnitReader;
@@ -85,7 +85,7 @@ public class EntityManagerProducer implements Serializable {
*/
@Default
@Produces
- protected EntityManager createDefault(EntityManagerConfig config) {
+ protected EntityManager createDefault() {
String persistenceUnit = persistenceUnitReader.getFromProperties(config);
if (persistenceUnit == null) {
@@ -121,7 +121,7 @@ public class EntityManagerProducer implements Serializable {
}
private EntityManagerStore getStore() {
- switch (configuration.getEntityManagerScope()) {
+ switch (config.getEntityManagerScope()) {
case REQUEST:
return storeInstance.select(RequestEntityManagerStore.class).get();
case APPLICATION:
diff --git a/impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/Persistences.java b/impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/Persistences.java
index b28b065..bce508c 100644
--- a/impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/Persistences.java
+++ b/impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/Persistences.java
@@ -41,26 +41,18 @@ import static br.gov.frameworkdemoiselle.configuration.Configuration.DEFAULT_RES
import java.util.Set;
import java.util.logging.Logger;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
import br.gov.frameworkdemoiselle.DemoiselleException;
import br.gov.frameworkdemoiselle.annotation.Name;
import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig;
+import br.gov.frameworkdemoiselle.util.Beans;
+import br.gov.frameworkdemoiselle.util.NameQualifier;
import br.gov.frameworkdemoiselle.util.ResourceBundle;
-@Singleton
public class Persistences {
- @Inject
- protected Logger logger;
-
- @Inject
- @Name("demoiselle-jpa-bundle")
- protected ResourceBundle bundle;
+ private transient ResourceBundle bundle;
- @Inject
- private EntityManagerFactoryProducer factory;
+ private transient Logger logger;
/**
* Tries to get persistence unit name from demoiselle.properties.
@@ -73,7 +65,7 @@ public class Persistences {
String persistenceUnit = config.getDefaultPersistenceUnitName();
if (persistenceUnit != null) {
- this.logger.fine(bundle.getString("getting-persistence-unit-from-properties", DEFAULT_RESOURCE));
+ getLogger().fine(getBundle().getString("getting-persistence-unit-from-properties", DEFAULT_RESOURCE));
}
return persistenceUnit;
@@ -86,13 +78,31 @@ public class Persistences {
* @return Persistence Unit AmbiguousQualifier
*/
protected String getFromXML() {
+ EntityManagerFactoryProducer factory = Beans.getReference(EntityManagerFactoryProducer.class);
Set persistenceUnits = factory.getCache().keySet();
if (persistenceUnits.size() > 1) {
- throw new DemoiselleException(bundle.getString("more-than-one-persistence-unit-defined",
+ throw new DemoiselleException(getBundle().getString("more-than-one-persistence-unit-defined",
Name.class.getSimpleName()));
} else {
return persistenceUnits.iterator().next();
}
}
+
+ private ResourceBundle getBundle() {
+ if (bundle == null) {
+ bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-jpa-bundle"));
+ }
+
+ return bundle;
+ }
+
+ private Logger getLogger() {
+ if (logger == null) {
+ logger = Beans.getReference(Logger.class, new NameQualifier("br.gov.frameworkdemoiselle.util"));
+
+ }
+
+ return logger;
+ }
}
diff --git a/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/HttpViolationException.java b/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/HttpViolationException.java
index 43822b4..f4a1efe 100644
--- a/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/HttpViolationException.java
+++ b/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/HttpViolationException.java
@@ -47,10 +47,24 @@ public class HttpViolationException extends Exception {
private int statusCode;
+ private String mediaType = "application/json";
+
public HttpViolationException(int statusCode) {
this.statusCode = statusCode;
}
+ public HttpViolationException(int statusCode, String mediaType) {
+ this.mediaType = mediaType;
+ }
+
+ public int getStatusCode() {
+ return statusCode;
+ }
+
+ public String getMediaType() {
+ return mediaType;
+ }
+
public HttpViolationException addViolation(String message) {
return addViolation(null, message);
}
@@ -130,8 +144,4 @@ public class HttpViolationException extends Exception {
return this.property + " " + this.message;
}
}
-
- public int getStatusCode() {
- return statusCode;
- }
}
diff --git a/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/HttpViolationExceptionMapper.java b/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/HttpViolationExceptionMapper.java
index e465724..f56dbc3 100644
--- a/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/HttpViolationExceptionMapper.java
+++ b/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/HttpViolationExceptionMapper.java
@@ -62,6 +62,7 @@ public class HttpViolationExceptionMapper implements ExceptionMapper violations = exception.getViolations();
int status = exception.getStatusCode();
+ String mediaType = exception.getMediaType();
if (violations.isEmpty()) {
violations = null;
@@ -69,7 +70,7 @@ public class HttpViolationExceptionMapper implements ExceptionMapper
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package br.gov.frameworkdemoiselle.internal.producer;
+
+import javax.enterprise.inject.Produces;
+
+import br.gov.frameworkdemoiselle.annotation.Strategy;
+import br.gov.frameworkdemoiselle.security.TokenManager;
+
+public class TokenManagerProducer {
+
+ @Produces
+ @Strategy
+ public TokenManager create() {
+ return StrategySelector.selectReference(TokenManager.class);
+ }
+}
diff --git a/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/security/TokenAuthenticator.java b/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/security/TokenAuthenticator.java
index 2b574f9..aead6f5 100644
--- a/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/security/TokenAuthenticator.java
+++ b/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/security/TokenAuthenticator.java
@@ -44,6 +44,7 @@ import javax.enterprise.context.RequestScoped;
import br.gov.frameworkdemoiselle.annotation.Priority;
import br.gov.frameworkdemoiselle.util.Beans;
+import br.gov.frameworkdemoiselle.util.StrategyQualifier;
@RequestScoped
@Priority(L2_PRIORITY)
@@ -56,7 +57,7 @@ public class TokenAuthenticator implements Authenticator {
@Override
public void authenticate() throws Exception {
Token token = Beans.getReference(Token.class);
- TokenManager tokenManager = Beans.getReference(TokenManager.class);
+ TokenManager tokenManager = Beans.getReference(TokenManager.class, new StrategyQualifier());
if (token.isEmpty()) {
this.user = customAuthentication();
diff --git a/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/Cache.java b/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/Cache.java
index 0230b45..0c3d84e 100644
--- a/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/Cache.java
+++ b/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/Cache.java
@@ -54,5 +54,5 @@ import javax.interceptor.InterceptorBinding;
public @interface Cache {
@Nonbinding
- String value();
+ String value() default "max-age=9223372036854775807";
}
--
libgit2 0.21.2