Commit 14e748c0130ab02115b8a0c31c8c452ef276ed2f
1 parent
8fbfdea5
Exists in
master
Mudança no Strategy Selector
Showing
23 changed files
with
714 additions
and
239 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Strategy.java
0 → 100644
@@ -0,0 +1,89 @@ | @@ -0,0 +1,89 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.annotation; | ||
38 | + | ||
39 | +import static java.lang.annotation.ElementType.FIELD; | ||
40 | +import static java.lang.annotation.ElementType.METHOD; | ||
41 | +import static java.lang.annotation.ElementType.PARAMETER; | ||
42 | +import static java.lang.annotation.ElementType.TYPE; | ||
43 | +import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
44 | + | ||
45 | +import java.lang.annotation.Inherited; | ||
46 | +import java.lang.annotation.Retention; | ||
47 | +import java.lang.annotation.Target; | ||
48 | + | ||
49 | +import javax.inject.Qualifier; | ||
50 | + | ||
51 | +/** | ||
52 | + * This annotation is used to make passible: | ||
53 | + * <ul> | ||
54 | + * <li>map an attribute that belongs to a configuration class in a key with a different name of this attribute</li> | ||
55 | + * <li>map a Resource Bundle object to a file with different name of this object</li> | ||
56 | + * </ul> | ||
57 | + * <p> | ||
58 | + * The examples below shows how these annotation could be used: | ||
59 | + * <p> | ||
60 | + * <blockquote> | ||
61 | + * | ||
62 | + * <pre> | ||
63 | + * public class NameConfig { | ||
64 | + * | ||
65 | + * @AmbiguousQualifier("other.name.attrib") | ||
66 | + * private int nameOfAttribute; | ||
67 | + * ... | ||
68 | + * } | ||
69 | + * | ||
70 | + * public class NameResourceBundle { | ||
71 | + * | ||
72 | + * @AmbiguousQualifier("other.name.bundle") | ||
73 | + * @Inject | ||
74 | + * private ResourceBundle bundle; | ||
75 | + * ... | ||
76 | + * } | ||
77 | + * </pre> | ||
78 | + * | ||
79 | + * </blockquote> | ||
80 | + * | ||
81 | + * @author SERPRO | ||
82 | + */ | ||
83 | +@Qualifier | ||
84 | +@Inherited | ||
85 | +@Retention(RUNTIME) | ||
86 | +@Target({ TYPE, FIELD, METHOD, PARAMETER }) | ||
87 | +public @interface Strategy { | ||
88 | + | ||
89 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContextProducer.java
@@ -67,8 +67,8 @@ import br.gov.frameworkdemoiselle.context.SessionContext; | @@ -67,8 +67,8 @@ import br.gov.frameworkdemoiselle.context.SessionContext; | ||
67 | import br.gov.frameworkdemoiselle.context.StaticContext; | 67 | import br.gov.frameworkdemoiselle.context.StaticContext; |
68 | import br.gov.frameworkdemoiselle.context.ViewContext; | 68 | import br.gov.frameworkdemoiselle.context.ViewContext; |
69 | import br.gov.frameworkdemoiselle.internal.bootstrap.CustomContextBootstrap; | 69 | import br.gov.frameworkdemoiselle.internal.bootstrap.CustomContextBootstrap; |
70 | -import br.gov.frameworkdemoiselle.internal.implementation.StrategySelector; | ||
71 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | 70 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
71 | +import br.gov.frameworkdemoiselle.internal.producer.StrategySelector; | ||
72 | import br.gov.frameworkdemoiselle.util.Beans; | 72 | import br.gov.frameworkdemoiselle.util.Beans; |
73 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 73 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
74 | 74 | ||
@@ -235,7 +235,7 @@ public class CustomContextProducer { | @@ -235,7 +235,7 @@ public class CustomContextProducer { | ||
235 | } | 235 | } |
236 | 236 | ||
237 | if (producedContext == null && !selectableContexts.isEmpty()) { | 237 | if (producedContext == null && !selectableContexts.isEmpty()) { |
238 | - producedContext = StrategySelector.selectInstance(CustomContext.class, selectableContexts); | 238 | + producedContext = StrategySelector.selectReference(CustomContext.class, selectableContexts); |
239 | } | 239 | } |
240 | 240 | ||
241 | return (T) producedContext; | 241 | return (T) producedContext; |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationLoader.java
@@ -67,6 +67,7 @@ import br.gov.frameworkdemoiselle.configuration.Configuration; | @@ -67,6 +67,7 @@ import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
67 | import br.gov.frameworkdemoiselle.configuration.ConfigurationException; | 67 | import br.gov.frameworkdemoiselle.configuration.ConfigurationException; |
68 | import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; | 68 | import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; |
69 | import br.gov.frameworkdemoiselle.internal.bootstrap.ConfigurationBootstrap; | 69 | import br.gov.frameworkdemoiselle.internal.bootstrap.ConfigurationBootstrap; |
70 | +import br.gov.frameworkdemoiselle.internal.producer.StrategySelector; | ||
70 | import br.gov.frameworkdemoiselle.util.Beans; | 71 | import br.gov.frameworkdemoiselle.util.Beans; |
71 | import br.gov.frameworkdemoiselle.util.NameQualifier; | 72 | import br.gov.frameworkdemoiselle.util.NameQualifier; |
72 | import br.gov.frameworkdemoiselle.util.Reflections; | 73 | import br.gov.frameworkdemoiselle.util.Reflections; |
@@ -267,7 +268,7 @@ public class ConfigurationLoader implements Serializable { | @@ -267,7 +268,7 @@ public class ConfigurationLoader implements Serializable { | ||
267 | } | 268 | } |
268 | } | 269 | } |
269 | 270 | ||
270 | - ConfigurationValueExtractor elected = StrategySelector.selectInstance(ConfigurationValueExtractor.class, | 271 | + ConfigurationValueExtractor elected = StrategySelector.selectReference(ConfigurationValueExtractor.class, |
271 | candidates); | 272 | candidates); |
272 | 273 | ||
273 | if (elected == null) { | 274 | if (elected == null) { |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MessageContextImpl.java
@@ -43,6 +43,7 @@ import br.gov.frameworkdemoiselle.message.MessageAppender; | @@ -43,6 +43,7 @@ import br.gov.frameworkdemoiselle.message.MessageAppender; | ||
43 | import br.gov.frameworkdemoiselle.message.MessageContext; | 43 | import br.gov.frameworkdemoiselle.message.MessageContext; |
44 | import br.gov.frameworkdemoiselle.message.SeverityType; | 44 | import br.gov.frameworkdemoiselle.message.SeverityType; |
45 | import br.gov.frameworkdemoiselle.util.Beans; | 45 | import br.gov.frameworkdemoiselle.util.Beans; |
46 | +import br.gov.frameworkdemoiselle.util.StrategyQualifier; | ||
46 | 47 | ||
47 | /** | 48 | /** |
48 | * The message store is designed to provide access to messages. It is shared by every application layer. | 49 | * 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 { | @@ -54,9 +55,7 @@ public class MessageContextImpl implements Serializable, MessageContext { | ||
54 | private static final long serialVersionUID = 1L; | 55 | private static final long serialVersionUID = 1L; |
55 | 56 | ||
56 | private MessageAppender getAppender() { | 57 | private MessageAppender getAppender() { |
57 | - Class<? extends MessageAppender> appenderClass = StrategySelector.selectClass(MessageAppender.class); | ||
58 | - | ||
59 | - return Beans.getReference(appenderClass); | 58 | + return Beans.getReference(MessageAppender.class, new StrategyQualifier()); |
60 | } | 59 | } |
61 | 60 | ||
62 | @Override | 61 | @Override |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java
@@ -54,6 +54,7 @@ import br.gov.frameworkdemoiselle.security.SecurityContext; | @@ -54,6 +54,7 @@ import br.gov.frameworkdemoiselle.security.SecurityContext; | ||
54 | import br.gov.frameworkdemoiselle.util.Beans; | 54 | import br.gov.frameworkdemoiselle.util.Beans; |
55 | import br.gov.frameworkdemoiselle.util.NameQualifier; | 55 | import br.gov.frameworkdemoiselle.util.NameQualifier; |
56 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 56 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
57 | +import br.gov.frameworkdemoiselle.util.StrategyQualifier; | ||
57 | 58 | ||
58 | /** | 59 | /** |
59 | * This is the default implementation of {@link SecurityContext} interface. | 60 | * This is the default implementation of {@link SecurityContext} interface. |
@@ -73,13 +74,13 @@ public class SecurityContextImpl implements SecurityContext { | @@ -73,13 +74,13 @@ public class SecurityContextImpl implements SecurityContext { | ||
73 | 74 | ||
74 | private Authenticator getAuthenticator() { | 75 | private Authenticator getAuthenticator() { |
75 | if (this.authenticator == null) { | 76 | if (this.authenticator == null) { |
76 | - Class<? extends Authenticator> clazz = getConfig().getAuthenticatorClass(); | 77 | + Class<? extends Authenticator> type = getConfig().getAuthenticatorClass(); |
77 | 78 | ||
78 | - if (clazz == null) { | ||
79 | - clazz = StrategySelector.selectClass(Authenticator.class); | 79 | + if (type != null) { |
80 | + this.authenticator = Beans.getReference(type); | ||
81 | + } else { | ||
82 | + this.authenticator = Beans.getReference(Authenticator.class, new StrategyQualifier()); | ||
80 | } | 83 | } |
81 | - | ||
82 | - this.authenticator = Beans.getReference(clazz); | ||
83 | } | 84 | } |
84 | 85 | ||
85 | return this.authenticator; | 86 | return this.authenticator; |
@@ -87,13 +88,13 @@ public class SecurityContextImpl implements SecurityContext { | @@ -87,13 +88,13 @@ public class SecurityContextImpl implements SecurityContext { | ||
87 | 88 | ||
88 | private Authorizer getAuthorizer() { | 89 | private Authorizer getAuthorizer() { |
89 | if (this.authorizer == null) { | 90 | if (this.authorizer == null) { |
90 | - Class<? extends Authorizer> clazz = getConfig().getAuthorizerClass(); | 91 | + Class<? extends Authorizer> type = getConfig().getAuthorizerClass(); |
91 | 92 | ||
92 | - if (clazz == null) { | ||
93 | - clazz = StrategySelector.selectClass(Authorizer.class); | 93 | + if (type != null) { |
94 | + this.authorizer = Beans.getReference(type); | ||
95 | + } else { | ||
96 | + this.authorizer = Beans.getReference(Authorizer.class, new StrategyQualifier()); | ||
94 | } | 97 | } |
95 | - | ||
96 | - this.authorizer = Beans.getReference(clazz); | ||
97 | } | 98 | } |
98 | 99 | ||
99 | return this.authorizer; | 100 | return this.authorizer; |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/StrategySelector.java
@@ -1,159 +0,0 @@ | @@ -1,159 +0,0 @@ | ||
1 | -/* | ||
2 | - * Demoiselle Framework | ||
3 | - * Copyright (C) 2010 SERPRO | ||
4 | - * ---------------------------------------------------------------------------- | ||
5 | - * This file is part of Demoiselle Framework. | ||
6 | - * | ||
7 | - * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | - * as published by the Free Software Foundation. | ||
10 | - * | ||
11 | - * This program is distributed in the hope that it will be useful, | ||
12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | - * GNU General Public License for more details. | ||
15 | - * | ||
16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | - * ---------------------------------------------------------------------------- | ||
21 | - * Este arquivo é parte do Framework Demoiselle. | ||
22 | - * | ||
23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | - * do Software Livre (FSF). | ||
26 | - * | ||
27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | - * para maiores detalhes. | ||
31 | - * | ||
32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | - */ | ||
37 | -package br.gov.frameworkdemoiselle.internal.implementation; | ||
38 | - | ||
39 | -import java.io.Serializable; | ||
40 | -import java.util.ArrayList; | ||
41 | -import java.util.Collection; | ||
42 | -import java.util.HashMap; | ||
43 | -import java.util.HashSet; | ||
44 | -import java.util.List; | ||
45 | -import java.util.Map; | ||
46 | -import java.util.Set; | ||
47 | - | ||
48 | -import javax.enterprise.inject.AmbiguousResolutionException; | ||
49 | -import javax.enterprise.inject.spi.Bean; | ||
50 | - | ||
51 | -import br.gov.frameworkdemoiselle.DemoiselleException; | ||
52 | -import br.gov.frameworkdemoiselle.annotation.Priority; | ||
53 | -import br.gov.frameworkdemoiselle.util.Beans; | ||
54 | -import br.gov.frameworkdemoiselle.util.NameQualifier; | ||
55 | -import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
56 | - | ||
57 | -public final class StrategySelector implements Serializable { | ||
58 | - | ||
59 | - private static final long serialVersionUID = 1L; | ||
60 | - | ||
61 | - private StrategySelector() { | ||
62 | - } | ||
63 | - | ||
64 | - @SuppressWarnings("unchecked") | ||
65 | - public static <T> T selectInstance(Class<T> type, Collection<? extends T> options) { | ||
66 | - | ||
67 | - Map<Class<? extends T>, T> map = new HashMap<Class<? extends T>, T>(); | ||
68 | - | ||
69 | - for (T instance : options) { | ||
70 | - if (instance != null) { | ||
71 | - map.put((Class<T>) instance.getClass(), instance); | ||
72 | - } | ||
73 | - } | ||
74 | - | ||
75 | - Class<? extends T> elected = selectClass(type, map.keySet()); | ||
76 | - return map.get(elected); | ||
77 | - } | ||
78 | - | ||
79 | - private static <T> Class<? extends T> selectClass(Class<T> type, Collection<Class<? extends T>> options) { | ||
80 | - Class<? extends T> selected = null; | ||
81 | - | ||
82 | - for (Class<? extends T> option : options) { | ||
83 | - if (selected == null || getPriority(option) < getPriority(selected)) { | ||
84 | - selected = option; | ||
85 | - } | ||
86 | - } | ||
87 | - | ||
88 | - if (selected != null) { | ||
89 | - performAmbiguityCheck(type, selected, options); | ||
90 | - } | ||
91 | - | ||
92 | - return selected; | ||
93 | - } | ||
94 | - | ||
95 | - public static <T> Class<? extends T> selectClass(Class<T> type) { | ||
96 | - return selectClass(type, getOptions(type)); | ||
97 | - } | ||
98 | - | ||
99 | - @SuppressWarnings("unchecked") | ||
100 | - private static <T> Collection<Class<? extends T>> getOptions(Class<T> type) { | ||
101 | - Set<Class<? extends T>> result = new HashSet<Class<? extends T>>(); | ||
102 | - | ||
103 | - for (Bean<?> bean : Beans.getBeanManager().getBeans(type)) { | ||
104 | - result.add((Class<? extends T>) bean.getBeanClass()); | ||
105 | - } | ||
106 | - | ||
107 | - return result; | ||
108 | - } | ||
109 | - | ||
110 | - private static <T> void performAmbiguityCheck(Class<T> type, Class<? extends T> selected, | ||
111 | - Collection<Class<? extends T>> options) { | ||
112 | - int selectedPriority = getPriority(selected); | ||
113 | - | ||
114 | - List<Class<? extends T>> ambiguous = new ArrayList<Class<? extends T>>(); | ||
115 | - | ||
116 | - for (Class<? extends T> option : options) { | ||
117 | - if (selected != option && selectedPriority == getPriority(option)) { | ||
118 | - ambiguous.add(option); | ||
119 | - } | ||
120 | - } | ||
121 | - | ||
122 | - if (!ambiguous.isEmpty()) { | ||
123 | - ambiguous.add(selected); | ||
124 | - | ||
125 | - String message = getExceptionMessage(type, ambiguous); | ||
126 | - throw new DemoiselleException(message, new AmbiguousResolutionException()); | ||
127 | - } | ||
128 | - } | ||
129 | - | ||
130 | - private static <T> String getExceptionMessage(Class<T> type, List<Class<? extends T>> ambiguous) { | ||
131 | - StringBuffer classes = new StringBuffer(); | ||
132 | - | ||
133 | - int i = 0; | ||
134 | - for (Class<? extends T> clazz : ambiguous) { | ||
135 | - if (i++ != 0) { | ||
136 | - classes.append(", "); | ||
137 | - } | ||
138 | - | ||
139 | - classes.append(clazz.getCanonicalName()); | ||
140 | - } | ||
141 | - | ||
142 | - return getBundle().getString("ambiguous-strategy-resolution", type.getCanonicalName(), classes.toString()); | ||
143 | - } | ||
144 | - | ||
145 | - private static <T> int getPriority(Class<T> type) { | ||
146 | - int result = Priority.MAX_PRIORITY; | ||
147 | - Priority priority = type.getAnnotation(Priority.class); | ||
148 | - | ||
149 | - if (priority != null) { | ||
150 | - result = priority.value(); | ||
151 | - } | ||
152 | - | ||
153 | - return result; | ||
154 | - } | ||
155 | - | ||
156 | - private static ResourceBundle getBundle() { | ||
157 | - return Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle")); | ||
158 | - } | ||
159 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionContextImpl.java
@@ -42,6 +42,7 @@ import br.gov.frameworkdemoiselle.internal.configuration.TransactionConfig; | @@ -42,6 +42,7 @@ import br.gov.frameworkdemoiselle.internal.configuration.TransactionConfig; | ||
42 | import br.gov.frameworkdemoiselle.transaction.Transaction; | 42 | import br.gov.frameworkdemoiselle.transaction.Transaction; |
43 | import br.gov.frameworkdemoiselle.transaction.TransactionContext; | 43 | import br.gov.frameworkdemoiselle.transaction.TransactionContext; |
44 | import br.gov.frameworkdemoiselle.util.Beans; | 44 | import br.gov.frameworkdemoiselle.util.Beans; |
45 | +import br.gov.frameworkdemoiselle.util.StrategyQualifier; | ||
45 | 46 | ||
46 | /** | 47 | /** |
47 | * This is the default implementation of {@link TransactionContext} interface. | 48 | * This is the default implementation of {@link TransactionContext} interface. |
@@ -58,13 +59,13 @@ public class TransactionContextImpl implements TransactionContext { | @@ -58,13 +59,13 @@ public class TransactionContextImpl implements TransactionContext { | ||
58 | @Override | 59 | @Override |
59 | public Transaction getCurrentTransaction() { | 60 | public Transaction getCurrentTransaction() { |
60 | if (this.transaction == null) { | 61 | if (this.transaction == null) { |
61 | - Class<? extends Transaction> clazz = getConfig().getTransactionClass(); | 62 | + Class<? extends Transaction> type = getConfig().getTransactionClass(); |
62 | 63 | ||
63 | - if (clazz == null) { | ||
64 | - clazz = StrategySelector.selectClass(Transaction.class); | 64 | + if (type != null) { |
65 | + this.transaction = Beans.getReference(type); | ||
66 | + } else { | ||
67 | + this.transaction = Beans.getReference(Transaction.class, new StrategyQualifier()); | ||
65 | } | 68 | } |
66 | - | ||
67 | - this.transaction = Beans.getReference(clazz); | ||
68 | } | 69 | } |
69 | 70 | ||
70 | return this.transaction; | 71 | return this.transaction; |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AuthenticatorProducer.java
0 → 100644
@@ -0,0 +1,51 @@ | @@ -0,0 +1,51 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.producer; | ||
38 | + | ||
39 | +import javax.enterprise.inject.Produces; | ||
40 | + | ||
41 | +import br.gov.frameworkdemoiselle.annotation.Strategy; | ||
42 | +import br.gov.frameworkdemoiselle.security.Authenticator; | ||
43 | + | ||
44 | +public class AuthenticatorProducer { | ||
45 | + | ||
46 | + @Produces | ||
47 | + @Strategy | ||
48 | + public Authenticator create() { | ||
49 | + return StrategySelector.selectReference(Authenticator.class); | ||
50 | + } | ||
51 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AuthorizerProducer.java
0 → 100644
@@ -0,0 +1,51 @@ | @@ -0,0 +1,51 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.producer; | ||
38 | + | ||
39 | +import javax.enterprise.inject.Produces; | ||
40 | + | ||
41 | +import br.gov.frameworkdemoiselle.annotation.Strategy; | ||
42 | +import br.gov.frameworkdemoiselle.security.Authorizer; | ||
43 | + | ||
44 | +public class AuthorizerProducer { | ||
45 | + | ||
46 | + @Produces | ||
47 | + @Strategy | ||
48 | + public Authorizer create() { | ||
49 | + return StrategySelector.selectReference(Authorizer.class); | ||
50 | + } | ||
51 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ConfigurationValueExtractorProducer.java
0 → 100644
@@ -0,0 +1,51 @@ | @@ -0,0 +1,51 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.producer; | ||
38 | + | ||
39 | +import javax.enterprise.inject.Produces; | ||
40 | + | ||
41 | +import br.gov.frameworkdemoiselle.annotation.Strategy; | ||
42 | +import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; | ||
43 | + | ||
44 | +public class ConfigurationValueExtractorProducer { | ||
45 | + | ||
46 | + @Produces | ||
47 | + @Strategy | ||
48 | + public ConfigurationValueExtractor create() { | ||
49 | + return StrategySelector.selectReference(ConfigurationValueExtractor.class); | ||
50 | + } | ||
51 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/MessageAppenderProducer.java
0 → 100644
@@ -0,0 +1,51 @@ | @@ -0,0 +1,51 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.producer; | ||
38 | + | ||
39 | +import javax.enterprise.inject.Produces; | ||
40 | + | ||
41 | +import br.gov.frameworkdemoiselle.annotation.Strategy; | ||
42 | +import br.gov.frameworkdemoiselle.message.MessageAppender; | ||
43 | + | ||
44 | +public class MessageAppenderProducer { | ||
45 | + | ||
46 | + @Produces | ||
47 | + @Strategy | ||
48 | + public MessageAppender create() { | ||
49 | + return StrategySelector.selectReference(MessageAppender.class); | ||
50 | + } | ||
51 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/StrategySelector.java
0 → 100644
@@ -0,0 +1,165 @@ | @@ -0,0 +1,165 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.producer; | ||
38 | + | ||
39 | +import java.io.Serializable; | ||
40 | +import java.lang.annotation.Annotation; | ||
41 | +import java.util.ArrayList; | ||
42 | +import java.util.Collection; | ||
43 | +import java.util.HashMap; | ||
44 | +import java.util.HashSet; | ||
45 | +import java.util.List; | ||
46 | +import java.util.Map; | ||
47 | +import java.util.Set; | ||
48 | + | ||
49 | +import javax.enterprise.inject.AmbiguousResolutionException; | ||
50 | +import javax.enterprise.inject.spi.Bean; | ||
51 | + | ||
52 | +import br.gov.frameworkdemoiselle.DemoiselleException; | ||
53 | +import br.gov.frameworkdemoiselle.annotation.Priority; | ||
54 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
55 | +import br.gov.frameworkdemoiselle.util.NameQualifier; | ||
56 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
57 | + | ||
58 | +public final class StrategySelector implements Serializable { | ||
59 | + | ||
60 | + private static final long serialVersionUID = 1L; | ||
61 | + | ||
62 | + private StrategySelector() { | ||
63 | + } | ||
64 | + | ||
65 | + @SuppressWarnings("unchecked") | ||
66 | + public static <T> T selectReference(Class<T> type, Collection<? extends T> options) { | ||
67 | + | ||
68 | + Map<Class<? extends T>, T> map = new HashMap<Class<? extends T>, T>(); | ||
69 | + | ||
70 | + for (T instance : options) { | ||
71 | + if (instance != null) { | ||
72 | + map.put((Class<T>) instance.getClass(), instance); | ||
73 | + } | ||
74 | + } | ||
75 | + | ||
76 | + Class<? extends T> elected = selectClass(type, map.keySet()); | ||
77 | + return map.get(elected); | ||
78 | + } | ||
79 | + | ||
80 | + protected static <T> T selectReference(Class<T> type) { | ||
81 | + Class<? extends T> selected = selectClass(type, getOptions(type)); | ||
82 | + return Beans.getReference(selected); | ||
83 | + } | ||
84 | + | ||
85 | + protected static <T> Class<? extends T> selectClass(Class<T> type) { | ||
86 | + return selectClass(type, getOptions(type)); | ||
87 | + } | ||
88 | + | ||
89 | + private static <T> Class<? extends T> selectClass(Class<T> type, Collection<Class<? extends T>> options) { | ||
90 | + Class<? extends T> selected = null; | ||
91 | + | ||
92 | + for (Class<? extends T> option : options) { | ||
93 | + if (selected == null || getPriority(option) < getPriority(selected)) { | ||
94 | + selected = option; | ||
95 | + } | ||
96 | + } | ||
97 | + | ||
98 | + if (selected != null) { | ||
99 | + performAmbiguityCheck(type, selected, options); | ||
100 | + } | ||
101 | + | ||
102 | + return selected; | ||
103 | + } | ||
104 | + | ||
105 | + @SuppressWarnings("unchecked") | ||
106 | + private static <T> Collection<Class<? extends T>> getOptions(Class<T> type, Annotation... qualifiers) { | ||
107 | + Set<Class<? extends T>> result = new HashSet<Class<? extends T>>(); | ||
108 | + | ||
109 | + for (Bean<?> bean : Beans.getBeanManager().getBeans(type, qualifiers)) { | ||
110 | + result.add((Class<? extends T>) bean.getBeanClass()); | ||
111 | + } | ||
112 | + | ||
113 | + return result; | ||
114 | + } | ||
115 | + | ||
116 | + private static <T> void performAmbiguityCheck(Class<T> type, Class<? extends T> selected, | ||
117 | + Collection<Class<? extends T>> options) { | ||
118 | + int selectedPriority = getPriority(selected); | ||
119 | + | ||
120 | + List<Class<? extends T>> ambiguous = new ArrayList<Class<? extends T>>(); | ||
121 | + | ||
122 | + for (Class<? extends T> option : options) { | ||
123 | + if (selected != option && selectedPriority == getPriority(option)) { | ||
124 | + ambiguous.add(option); | ||
125 | + } | ||
126 | + } | ||
127 | + | ||
128 | + if (!ambiguous.isEmpty()) { | ||
129 | + ambiguous.add(selected); | ||
130 | + | ||
131 | + String message = getExceptionMessage(type, ambiguous); | ||
132 | + throw new DemoiselleException(message, new AmbiguousResolutionException()); | ||
133 | + } | ||
134 | + } | ||
135 | + | ||
136 | + private static <T> String getExceptionMessage(Class<T> type, List<Class<? extends T>> ambiguous) { | ||
137 | + StringBuffer classes = new StringBuffer(); | ||
138 | + | ||
139 | + int i = 0; | ||
140 | + for (Class<? extends T> clazz : ambiguous) { | ||
141 | + if (i++ != 0) { | ||
142 | + classes.append(", "); | ||
143 | + } | ||
144 | + | ||
145 | + classes.append(clazz.getCanonicalName()); | ||
146 | + } | ||
147 | + | ||
148 | + return getBundle().getString("ambiguous-strategy-resolution", type.getCanonicalName(), classes.toString()); | ||
149 | + } | ||
150 | + | ||
151 | + private static <T> int getPriority(Class<T> type) { | ||
152 | + int result = Priority.MAX_PRIORITY; | ||
153 | + Priority priority = type.getAnnotation(Priority.class); | ||
154 | + | ||
155 | + if (priority != null) { | ||
156 | + result = priority.value(); | ||
157 | + } | ||
158 | + | ||
159 | + return result; | ||
160 | + } | ||
161 | + | ||
162 | + private static ResourceBundle getBundle() { | ||
163 | + return Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle")); | ||
164 | + } | ||
165 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/TransactionProducer.java
0 → 100644
@@ -0,0 +1,51 @@ | @@ -0,0 +1,51 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.producer; | ||
38 | + | ||
39 | +import javax.enterprise.inject.Produces; | ||
40 | + | ||
41 | +import br.gov.frameworkdemoiselle.annotation.Strategy; | ||
42 | +import br.gov.frameworkdemoiselle.transaction.Transaction; | ||
43 | + | ||
44 | +public class TransactionProducer { | ||
45 | + | ||
46 | + @Produces | ||
47 | + @Strategy | ||
48 | + public Transaction create() { | ||
49 | + return StrategySelector.selectReference(Transaction.class); | ||
50 | + } | ||
51 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Beans.java
@@ -112,30 +112,6 @@ public final class Beans { | @@ -112,30 +112,6 @@ public final class Beans { | ||
112 | } | 112 | } |
113 | 113 | ||
114 | /** | 114 | /** |
115 | - * Obtains a injectble instance of a bean, which have the given required type and are available for injection in the | ||
116 | - * point where this method was call. | ||
117 | - * | ||
118 | - * @param beanClass | ||
119 | - * the beanClass which instace is requested to be obtained. | ||
120 | - * @return Type a instace of the injected beanClass. | ||
121 | - * @throws DemoiselleException | ||
122 | - * if no bean are avaliable to be injected for the given Class. | ||
123 | - */ | ||
124 | - public static <T> T getReference(final Class<T> beanClass) { | ||
125 | - T instance; | ||
126 | - | ||
127 | - try { | ||
128 | - instance = (T) getReference(getBeanManager().getBeans(beanClass), beanClass); | ||
129 | - | ||
130 | - } catch (NoSuchElementException cause) { | ||
131 | - String message = getBundle().getString("bean-not-found", beanClass.getCanonicalName()); | ||
132 | - throw new DemoiselleException(message, cause); | ||
133 | - } | ||
134 | - | ||
135 | - return instance; | ||
136 | - } | ||
137 | - | ||
138 | - /** | ||
139 | * Obtains a injectble instance of a bean, which have the given EL name and are available for injection in the point | 115 | * Obtains a injectble instance of a bean, which have the given EL name and are available for injection in the point |
140 | * where this method was call. | 116 | * where this method was call. |
141 | * | 117 | * |
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/StrategyQualifier.java
0 → 100644
@@ -0,0 +1,58 @@ | @@ -0,0 +1,58 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.util; | ||
38 | + | ||
39 | +import java.lang.annotation.Annotation; | ||
40 | + | ||
41 | +import javax.enterprise.util.AnnotationLiteral; | ||
42 | + | ||
43 | +import util.beans.ambiguous.AmbiguousQualifier; | ||
44 | +import br.gov.frameworkdemoiselle.annotation.Name; | ||
45 | +import br.gov.frameworkdemoiselle.annotation.Strategy; | ||
46 | + | ||
47 | +/** | ||
48 | + * Annotation litteral that allows to create instances of the {@link Name} qualifier. The created instance can then be | ||
49 | + * used to call {@link Beans#getReference(Class type, Annotation... qualifiers)}. | ||
50 | + * | ||
51 | + * @see Beans | ||
52 | + * @see AmbiguousQualifier | ||
53 | + * @author SERPRO | ||
54 | + */ | ||
55 | +@SuppressWarnings("all") | ||
56 | +public class StrategyQualifier extends AnnotationLiteral<Strategy> implements Strategy { | ||
57 | + | ||
58 | +} |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerFactoryProducer.java
@@ -65,22 +65,20 @@ import org.w3c.dom.NodeList; | @@ -65,22 +65,20 @@ import org.w3c.dom.NodeList; | ||
65 | import br.gov.frameworkdemoiselle.DemoiselleException; | 65 | import br.gov.frameworkdemoiselle.DemoiselleException; |
66 | import br.gov.frameworkdemoiselle.annotation.Name; | 66 | import br.gov.frameworkdemoiselle.annotation.Name; |
67 | import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig; | 67 | import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig; |
68 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
69 | +import br.gov.frameworkdemoiselle.util.NameQualifier; | ||
68 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 70 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
69 | 71 | ||
70 | @ApplicationScoped | 72 | @ApplicationScoped |
71 | -// @StaticScoped | ||
72 | public class EntityManagerFactoryProducer implements Serializable { | 73 | public class EntityManagerFactoryProducer implements Serializable { |
73 | 74 | ||
74 | private static final long serialVersionUID = 1L; | 75 | private static final long serialVersionUID = 1L; |
75 | 76 | ||
76 | private static final String ENTITY_MANAGER_RESOURCE = "META-INF/persistence.xml"; | 77 | private static final String ENTITY_MANAGER_RESOURCE = "META-INF/persistence.xml"; |
77 | 78 | ||
78 | - @Inject | ||
79 | - protected Logger logger; | 79 | + private transient Logger logger; |
80 | 80 | ||
81 | - @Inject | ||
82 | - @Name("demoiselle-jpa-bundle") | ||
83 | - protected ResourceBundle bundle; | 81 | + private transient ResourceBundle bundle; |
84 | 82 | ||
85 | @Inject | 83 | @Inject |
86 | private Persistences persistenceUnitReader; | 84 | private Persistences persistenceUnitReader; |
@@ -143,7 +141,8 @@ public class EntityManagerFactoryProducer implements Serializable { | @@ -143,7 +141,8 @@ public class EntityManagerFactoryProducer implements Serializable { | ||
143 | persistenceUnit = ((Element) node).getAttribute("name"); | 141 | persistenceUnit = ((Element) node).getAttribute("name"); |
144 | 142 | ||
145 | if ("".equals(persistenceUnit)) { | 143 | if ("".equals(persistenceUnit)) { |
146 | - throw new DemoiselleException(bundle.getString("can-not-get-persistence-unit-from-persistence")); | 144 | + throw new DemoiselleException(getBundle() |
145 | + .getString("can-not-get-persistence-unit-from-persistence")); | ||
147 | } else { | 146 | } else { |
148 | persistenceUnits.add(persistenceUnit); | 147 | persistenceUnits.add(persistenceUnit); |
149 | } | 148 | } |
@@ -152,8 +151,8 @@ public class EntityManagerFactoryProducer implements Serializable { | @@ -152,8 +151,8 @@ public class EntityManagerFactoryProducer implements Serializable { | ||
152 | return persistenceUnits.toArray(new String[0]); | 151 | return persistenceUnits.toArray(new String[0]); |
153 | 152 | ||
154 | } catch (Exception cause) { | 153 | } catch (Exception cause) { |
155 | - String message = bundle.getString("can-not-get-persistence-unit-from-persistence"); | ||
156 | - logger.log(SEVERE, message, cause); | 154 | + String message = getBundle().getString("can-not-get-persistence-unit-from-persistence"); |
155 | + getLogger().log(SEVERE, message, cause); | ||
157 | 156 | ||
158 | throw new DemoiselleException(message, cause); | 157 | throw new DemoiselleException(message, cause); |
159 | } | 158 | } |
@@ -171,7 +170,7 @@ public class EntityManagerFactoryProducer implements Serializable { | @@ -171,7 +170,7 @@ public class EntityManagerFactoryProducer implements Serializable { | ||
171 | throw new DemoiselleException(cause); | 170 | throw new DemoiselleException(cause); |
172 | } | 171 | } |
173 | 172 | ||
174 | - logger.fine(bundle.getString("persistence-unit-name-found", persistenceUnit)); | 173 | + getLogger().fine(getBundle().getString("persistence-unit-name-found", persistenceUnit)); |
175 | } | 174 | } |
176 | } | 175 | } |
177 | 176 | ||
@@ -190,7 +189,7 @@ public class EntityManagerFactoryProducer implements Serializable { | @@ -190,7 +189,7 @@ public class EntityManagerFactoryProducer implements Serializable { | ||
190 | Map<String, EntityManagerFactory> result = factoryCache.get(classLoader); | 189 | Map<String, EntityManagerFactory> result = factoryCache.get(classLoader); |
191 | 190 | ||
192 | if (result == null || result.isEmpty()) { | 191 | if (result == null || result.isEmpty()) { |
193 | - logger.fine(bundle.getString("entity-manager-factory-not-found-in-cache")); | 192 | + getLogger().fine(getBundle().getString("entity-manager-factory-not-found-in-cache")); |
194 | for (String persistenceUnit : loadPersistenceUnitFromClassloader(classLoader)) { | 193 | for (String persistenceUnit : loadPersistenceUnitFromClassloader(classLoader)) { |
195 | create(persistenceUnit); | 194 | create(persistenceUnit); |
196 | result = factoryCache.get(classLoader); | 195 | result = factoryCache.get(classLoader); |
@@ -199,4 +198,21 @@ public class EntityManagerFactoryProducer implements Serializable { | @@ -199,4 +198,21 @@ public class EntityManagerFactoryProducer implements Serializable { | ||
199 | 198 | ||
200 | return result; | 199 | return result; |
201 | } | 200 | } |
201 | + | ||
202 | + private ResourceBundle getBundle() { | ||
203 | + if (bundle == null) { | ||
204 | + bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-jpa-bundle")); | ||
205 | + } | ||
206 | + | ||
207 | + return bundle; | ||
208 | + } | ||
209 | + | ||
210 | + private Logger getLogger() { | ||
211 | + if (logger == null) { | ||
212 | + logger = Beans.getReference(Logger.class, new NameQualifier("br.gov.frameworkdemoiselle.util")); | ||
213 | + | ||
214 | + } | ||
215 | + | ||
216 | + return logger; | ||
217 | + } | ||
202 | } | 218 | } |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerProducer.java
@@ -66,7 +66,7 @@ public class EntityManagerProducer implements Serializable { | @@ -66,7 +66,7 @@ public class EntityManagerProducer implements Serializable { | ||
66 | private Instance<EntityManagerStore> storeInstance; | 66 | private Instance<EntityManagerStore> storeInstance; |
67 | 67 | ||
68 | @Inject | 68 | @Inject |
69 | - private EntityManagerConfig configuration; | 69 | + private EntityManagerConfig config; |
70 | 70 | ||
71 | @Inject | 71 | @Inject |
72 | private Persistences persistenceUnitReader; | 72 | private Persistences persistenceUnitReader; |
@@ -85,7 +85,7 @@ public class EntityManagerProducer implements Serializable { | @@ -85,7 +85,7 @@ public class EntityManagerProducer implements Serializable { | ||
85 | */ | 85 | */ |
86 | @Default | 86 | @Default |
87 | @Produces | 87 | @Produces |
88 | - protected EntityManager createDefault(EntityManagerConfig config) { | 88 | + protected EntityManager createDefault() { |
89 | String persistenceUnit = persistenceUnitReader.getFromProperties(config); | 89 | String persistenceUnit = persistenceUnitReader.getFromProperties(config); |
90 | 90 | ||
91 | if (persistenceUnit == null) { | 91 | if (persistenceUnit == null) { |
@@ -121,7 +121,7 @@ public class EntityManagerProducer implements Serializable { | @@ -121,7 +121,7 @@ public class EntityManagerProducer implements Serializable { | ||
121 | } | 121 | } |
122 | 122 | ||
123 | private EntityManagerStore getStore() { | 123 | private EntityManagerStore getStore() { |
124 | - switch (configuration.getEntityManagerScope()) { | 124 | + switch (config.getEntityManagerScope()) { |
125 | case REQUEST: | 125 | case REQUEST: |
126 | return storeInstance.select(RequestEntityManagerStore.class).get(); | 126 | return storeInstance.select(RequestEntityManagerStore.class).get(); |
127 | case APPLICATION: | 127 | case APPLICATION: |
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 | @@ -41,26 +41,18 @@ import static br.gov.frameworkdemoiselle.configuration.Configuration.DEFAULT_RES | ||
41 | import java.util.Set; | 41 | import java.util.Set; |
42 | import java.util.logging.Logger; | 42 | import java.util.logging.Logger; |
43 | 43 | ||
44 | -import javax.inject.Inject; | ||
45 | -import javax.inject.Singleton; | ||
46 | - | ||
47 | import br.gov.frameworkdemoiselle.DemoiselleException; | 44 | import br.gov.frameworkdemoiselle.DemoiselleException; |
48 | import br.gov.frameworkdemoiselle.annotation.Name; | 45 | import br.gov.frameworkdemoiselle.annotation.Name; |
49 | import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig; | 46 | import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig; |
47 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
48 | +import br.gov.frameworkdemoiselle.util.NameQualifier; | ||
50 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 49 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
51 | 50 | ||
52 | -@Singleton | ||
53 | public class Persistences { | 51 | public class Persistences { |
54 | 52 | ||
55 | - @Inject | ||
56 | - protected Logger logger; | ||
57 | - | ||
58 | - @Inject | ||
59 | - @Name("demoiselle-jpa-bundle") | ||
60 | - protected ResourceBundle bundle; | 53 | + private transient ResourceBundle bundle; |
61 | 54 | ||
62 | - @Inject | ||
63 | - private EntityManagerFactoryProducer factory; | 55 | + private transient Logger logger; |
64 | 56 | ||
65 | /** | 57 | /** |
66 | * Tries to get persistence unit name from demoiselle.properties. | 58 | * Tries to get persistence unit name from demoiselle.properties. |
@@ -73,7 +65,7 @@ public class Persistences { | @@ -73,7 +65,7 @@ public class Persistences { | ||
73 | String persistenceUnit = config.getDefaultPersistenceUnitName(); | 65 | String persistenceUnit = config.getDefaultPersistenceUnitName(); |
74 | 66 | ||
75 | if (persistenceUnit != null) { | 67 | if (persistenceUnit != null) { |
76 | - this.logger.fine(bundle.getString("getting-persistence-unit-from-properties", DEFAULT_RESOURCE)); | 68 | + getLogger().fine(getBundle().getString("getting-persistence-unit-from-properties", DEFAULT_RESOURCE)); |
77 | } | 69 | } |
78 | 70 | ||
79 | return persistenceUnit; | 71 | return persistenceUnit; |
@@ -86,13 +78,31 @@ public class Persistences { | @@ -86,13 +78,31 @@ public class Persistences { | ||
86 | * @return Persistence Unit AmbiguousQualifier | 78 | * @return Persistence Unit AmbiguousQualifier |
87 | */ | 79 | */ |
88 | protected String getFromXML() { | 80 | protected String getFromXML() { |
81 | + EntityManagerFactoryProducer factory = Beans.getReference(EntityManagerFactoryProducer.class); | ||
89 | Set<String> persistenceUnits = factory.getCache().keySet(); | 82 | Set<String> persistenceUnits = factory.getCache().keySet(); |
90 | 83 | ||
91 | if (persistenceUnits.size() > 1) { | 84 | if (persistenceUnits.size() > 1) { |
92 | - throw new DemoiselleException(bundle.getString("more-than-one-persistence-unit-defined", | 85 | + throw new DemoiselleException(getBundle().getString("more-than-one-persistence-unit-defined", |
93 | Name.class.getSimpleName())); | 86 | Name.class.getSimpleName())); |
94 | } else { | 87 | } else { |
95 | return persistenceUnits.iterator().next(); | 88 | return persistenceUnits.iterator().next(); |
96 | } | 89 | } |
97 | } | 90 | } |
91 | + | ||
92 | + private ResourceBundle getBundle() { | ||
93 | + if (bundle == null) { | ||
94 | + bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-jpa-bundle")); | ||
95 | + } | ||
96 | + | ||
97 | + return bundle; | ||
98 | + } | ||
99 | + | ||
100 | + private Logger getLogger() { | ||
101 | + if (logger == null) { | ||
102 | + logger = Beans.getReference(Logger.class, new NameQualifier("br.gov.frameworkdemoiselle.util")); | ||
103 | + | ||
104 | + } | ||
105 | + | ||
106 | + return logger; | ||
107 | + } | ||
98 | } | 108 | } |
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/HttpViolationException.java
@@ -47,10 +47,24 @@ public class HttpViolationException extends Exception { | @@ -47,10 +47,24 @@ public class HttpViolationException extends Exception { | ||
47 | 47 | ||
48 | private int statusCode; | 48 | private int statusCode; |
49 | 49 | ||
50 | + private String mediaType = "application/json"; | ||
51 | + | ||
50 | public HttpViolationException(int statusCode) { | 52 | public HttpViolationException(int statusCode) { |
51 | this.statusCode = statusCode; | 53 | this.statusCode = statusCode; |
52 | } | 54 | } |
53 | 55 | ||
56 | + public HttpViolationException(int statusCode, String mediaType) { | ||
57 | + this.mediaType = mediaType; | ||
58 | + } | ||
59 | + | ||
60 | + public int getStatusCode() { | ||
61 | + return statusCode; | ||
62 | + } | ||
63 | + | ||
64 | + public String getMediaType() { | ||
65 | + return mediaType; | ||
66 | + } | ||
67 | + | ||
54 | public HttpViolationException addViolation(String message) { | 68 | public HttpViolationException addViolation(String message) { |
55 | return addViolation(null, message); | 69 | return addViolation(null, message); |
56 | } | 70 | } |
@@ -130,8 +144,4 @@ public class HttpViolationException extends Exception { | @@ -130,8 +144,4 @@ public class HttpViolationException extends Exception { | ||
130 | return this.property + " " + this.message; | 144 | return this.property + " " + this.message; |
131 | } | 145 | } |
132 | } | 146 | } |
133 | - | ||
134 | - public int getStatusCode() { | ||
135 | - return statusCode; | ||
136 | - } | ||
137 | } | 147 | } |
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/HttpViolationExceptionMapper.java
@@ -62,6 +62,7 @@ public class HttpViolationExceptionMapper implements ExceptionMapper<HttpViolati | @@ -62,6 +62,7 @@ public class HttpViolationExceptionMapper implements ExceptionMapper<HttpViolati | ||
62 | public Response toResponse(HttpViolationException exception) { | 62 | public Response toResponse(HttpViolationException exception) { |
63 | Set<Violation> violations = exception.getViolations(); | 63 | Set<Violation> violations = exception.getViolations(); |
64 | int status = exception.getStatusCode(); | 64 | int status = exception.getStatusCode(); |
65 | + String mediaType = exception.getMediaType(); | ||
65 | 66 | ||
66 | if (violations.isEmpty()) { | 67 | if (violations.isEmpty()) { |
67 | violations = null; | 68 | violations = null; |
@@ -69,7 +70,7 @@ public class HttpViolationExceptionMapper implements ExceptionMapper<HttpViolati | @@ -69,7 +70,7 @@ public class HttpViolationExceptionMapper implements ExceptionMapper<HttpViolati | ||
69 | getLogger().log(FINE, getBundle().getString("mapping-violations", status), exception); | 70 | getLogger().log(FINE, getBundle().getString("mapping-violations", status), exception); |
70 | } | 71 | } |
71 | 72 | ||
72 | - return Response.status(status).entity(violations).build(); | 73 | + return Response.status(status).entity(violations).type(mediaType).build(); |
73 | } | 74 | } |
74 | 75 | ||
75 | private ResourceBundle getBundle() { | 76 | private ResourceBundle getBundle() { |
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/internal/producer/TokenManagerProducer.java
0 → 100644
@@ -0,0 +1,51 @@ | @@ -0,0 +1,51 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.producer; | ||
38 | + | ||
39 | +import javax.enterprise.inject.Produces; | ||
40 | + | ||
41 | +import br.gov.frameworkdemoiselle.annotation.Strategy; | ||
42 | +import br.gov.frameworkdemoiselle.security.TokenManager; | ||
43 | + | ||
44 | +public class TokenManagerProducer { | ||
45 | + | ||
46 | + @Produces | ||
47 | + @Strategy | ||
48 | + public TokenManager create() { | ||
49 | + return StrategySelector.selectReference(TokenManager.class); | ||
50 | + } | ||
51 | +} |
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/security/TokenAuthenticator.java
@@ -44,6 +44,7 @@ import javax.enterprise.context.RequestScoped; | @@ -44,6 +44,7 @@ import javax.enterprise.context.RequestScoped; | ||
44 | 44 | ||
45 | import br.gov.frameworkdemoiselle.annotation.Priority; | 45 | import br.gov.frameworkdemoiselle.annotation.Priority; |
46 | import br.gov.frameworkdemoiselle.util.Beans; | 46 | import br.gov.frameworkdemoiselle.util.Beans; |
47 | +import br.gov.frameworkdemoiselle.util.StrategyQualifier; | ||
47 | 48 | ||
48 | @RequestScoped | 49 | @RequestScoped |
49 | @Priority(L2_PRIORITY) | 50 | @Priority(L2_PRIORITY) |
@@ -56,7 +57,7 @@ public class TokenAuthenticator implements Authenticator { | @@ -56,7 +57,7 @@ public class TokenAuthenticator implements Authenticator { | ||
56 | @Override | 57 | @Override |
57 | public void authenticate() throws Exception { | 58 | public void authenticate() throws Exception { |
58 | Token token = Beans.getReference(Token.class); | 59 | Token token = Beans.getReference(Token.class); |
59 | - TokenManager tokenManager = Beans.getReference(TokenManager.class); | 60 | + TokenManager tokenManager = Beans.getReference(TokenManager.class, new StrategyQualifier()); |
60 | 61 | ||
61 | if (token.isEmpty()) { | 62 | if (token.isEmpty()) { |
62 | this.user = customAuthentication(); | 63 | this.user = customAuthentication(); |
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/Cache.java
@@ -54,5 +54,5 @@ import javax.interceptor.InterceptorBinding; | @@ -54,5 +54,5 @@ import javax.interceptor.InterceptorBinding; | ||
54 | public @interface Cache { | 54 | public @interface Cache { |
55 | 55 | ||
56 | @Nonbinding | 56 | @Nonbinding |
57 | - String value(); | 57 | + String value() default "max-age=9223372036854775807"; |
58 | } | 58 | } |