Commit 3068daa447e4bdf37b1a89f62297af697548cc84
1 parent
0d972391
Exists in
master
REOPENED - issue FWK-97: Seleção do producer em Beans.getReference() é
aleatória https://demoiselle.atlassian.net/browse/FWK-97
Showing
25 changed files
with
596 additions
and
38 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Name.java
... | ... | @@ -66,14 +66,14 @@ import javax.inject.Qualifier; |
66 | 66 | * <pre> |
67 | 67 | * public class NameConfig { |
68 | 68 | * |
69 | - * @Name("other.name.attrib") | |
69 | + * @AmbiguousQualifier("other.name.attrib") | |
70 | 70 | * private int nameOfAttribute; |
71 | 71 | * ... |
72 | 72 | * } |
73 | 73 | * |
74 | 74 | * public class NameResourceBundle { |
75 | 75 | * |
76 | - * @Name("other.name.bundle") | |
76 | + * @AmbiguousQualifier("other.name.bundle") | |
77 | 77 | * @Inject |
78 | 78 | * private ResourceBundle bundle; |
79 | 79 | * ... | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/OperationParameter.java
... | ... | @@ -60,7 +60,7 @@ import javax.enterprise.util.Nonbinding; |
60 | 60 | public @interface OperationParameter { |
61 | 61 | |
62 | 62 | /** |
63 | - * Name that will be used to publish this operation's parameter to clients. | |
63 | + * AmbiguousQualifier that will be used to publish this operation's parameter to clients. | |
64 | 64 | */ |
65 | 65 | @Nonbinding |
66 | 66 | String name(); | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/Management.java
... | ... | @@ -121,7 +121,7 @@ public class Management implements Serializable { |
121 | 121 | * A type annotated with {@link ManagementController}. This method will create an (or obtain an already |
122 | 122 | * created) instance of this type and invoke the operation over it. |
123 | 123 | * @param actionName |
124 | - * Name of method to be invoked, the type must have this operation on it's list | |
124 | + * AmbiguousQualifier of method to be invoked, the type must have this operation on it's list | |
125 | 125 | * @param params |
126 | 126 | * List of values for the operation parameters. Can be <code>null</code> if the operation require no |
127 | 127 | * parameters. | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/LoggerProducer.java
... | ... | @@ -89,7 +89,7 @@ public class LoggerProducer implements Serializable { |
89 | 89 | type = Reflections.forName(canonicalName); |
90 | 90 | |
91 | 91 | } catch (ClassCastException cause) { |
92 | - // TODO Colocar a mensgaem apropriada mostrando como utilizar a anotação @Name corretamente com a injeção de | |
92 | + // TODO Colocar a mensgaem apropriada mostrando como utilizar a anotação @AmbiguousQualifier corretamente com a injeção de | |
93 | 93 | // Logger. |
94 | 94 | throw new DemoiselleException(null, cause); |
95 | 95 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/security/RequiredPermissionInterceptor.java
... | ... | @@ -99,12 +99,12 @@ public class RequiredPermissionInterceptor implements Serializable { |
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
102 | - * Returns the resource defined in {@code @RequiredPermission} annotation, the name defined in {@code @Name} | |
102 | + * Returns the resource defined in {@code @RequiredPermission} annotation, the name defined in {@code @AmbiguousQualifier} | |
103 | 103 | * annotation or the class name itself |
104 | 104 | * |
105 | 105 | * @param ic |
106 | 106 | * the {@code InvocationContext} in which the method is being called |
107 | - * @return the resource defined in {@code @RequiredPermission} annotation, the name defined in {@code @Name} | |
107 | + * @return the resource defined in {@code @RequiredPermission} annotation, the name defined in {@code @AmbiguousQualifier} | |
108 | 108 | * annotation or the class name itself |
109 | 109 | */ |
110 | 110 | private String getResource(InvocationContext ic) { |
... | ... | @@ -127,12 +127,12 @@ public class RequiredPermissionInterceptor implements Serializable { |
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
130 | - * Returns the operation defined in {@code @RequiredPermission} annotation, the name defined in {@code @Name} | |
130 | + * Returns the operation defined in {@code @RequiredPermission} annotation, the name defined in {@code @AmbiguousQualifier} | |
131 | 131 | * annotation or the method's name itself |
132 | 132 | * |
133 | 133 | * @param ic |
134 | 134 | * the {@code InvocationContext} in which the method is being called |
135 | - * @return the operation defined in {@code @RequiredPermission} annotation, the name defined in {@code @Name} | |
135 | + * @return the operation defined in {@code @RequiredPermission} annotation, the name defined in {@code @AmbiguousQualifier} | |
136 | 136 | * annotation or the method's name itself |
137 | 137 | */ |
138 | 138 | private String getOperation(InvocationContext ic) { | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Beans.java
... | ... | @@ -45,6 +45,7 @@ import java.util.NoSuchElementException; |
45 | 45 | import java.util.Set; |
46 | 46 | |
47 | 47 | import javax.enterprise.context.spi.CreationalContext; |
48 | +import javax.enterprise.inject.AmbiguousResolutionException; | |
48 | 49 | import javax.enterprise.inject.spi.Annotated; |
49 | 50 | import javax.enterprise.inject.spi.Bean; |
50 | 51 | import javax.enterprise.inject.spi.BeanManager; |
... | ... | @@ -64,7 +65,7 @@ import br.gov.frameworkdemoiselle.DemoiselleException; |
64 | 65 | public final class Beans { |
65 | 66 | |
66 | 67 | private static BeanManager beanManager = null; |
67 | - | |
68 | + | |
68 | 69 | private Beans() { |
69 | 70 | } |
70 | 71 | |
... | ... | @@ -75,7 +76,7 @@ public final class Beans { |
75 | 76 | public static BeanManager getBeanManager() { |
76 | 77 | return beanManager; |
77 | 78 | } |
78 | - | |
79 | + | |
79 | 80 | /** |
80 | 81 | * Obtains a injectble instance of a bean, which have the given required type and qualifiers, and are available for |
81 | 82 | * injection in the point where this method was call. |
... | ... | @@ -161,11 +162,12 @@ public final class Beans { |
161 | 162 | |
162 | 163 | @SuppressWarnings("unchecked") |
163 | 164 | private static <T> T getReference(Set<Bean<?>> beans, Class<T> beanClass, Annotation... qualifiers) { |
164 | - Bean<?> bean = beans.iterator().next(); | |
165 | - | |
166 | - // TODO Esta mudança só deve ser submetida com os testes passando. Esta mudança quebra os testes. | |
167 | - // Bean<?> bean = getBeanManager().resolve( beans ); | |
165 | + if (beans.size() > 1) { | |
166 | + String message = getBundle().getString("ambiguous-bean-resolution", beanClass.getName(), beans.toString()); | |
167 | + throw new DemoiselleException(message, new AmbiguousResolutionException()); | |
168 | + } | |
168 | 169 | |
170 | + Bean<?> bean = beans.iterator().next(); | |
169 | 171 | CreationalContext<?> context = getBeanManager().createCreationalContext(bean); |
170 | 172 | Type beanType = beanClass == null ? bean.getBeanClass() : beanClass; |
171 | 173 | InjectionPoint injectionPoint = new CustomInjectionPoint(bean, beanType, qualifiers); | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/NameQualifier.java
... | ... | @@ -41,11 +41,11 @@ import javax.enterprise.util.AnnotationLiteral; |
41 | 41 | import br.gov.frameworkdemoiselle.annotation.Name; |
42 | 42 | |
43 | 43 | /** |
44 | - * Creates a instance of an java annotation, specifically for qualification @Name. | |
44 | + * Creates a instance of an java annotation, specifically for qualification @AmbiguousQualifier. | |
45 | 45 | * This is required to get some classes by calling Beans.getReference method. |
46 | 46 | * |
47 | 47 | * @see Beans |
48 | - * @see Name | |
48 | + * @see AmbiguousQualifier | |
49 | 49 | * |
50 | 50 | * @author SERPRO |
51 | 51 | */ | ... | ... |
impl/core/src/main/resources/demoiselle-core-bundle.properties
... | ... | @@ -37,6 +37,7 @@ engine-on=Ligando os motores do Demoiselle ${project.version} |
37 | 37 | resource-not-found=Arquivo {0} n\u00E3o foi encontrado |
38 | 38 | key-not-found=A chave {0} n\u00E3o foi encontrada |
39 | 39 | ambiguous-strategy-resolution=Foi detectada ambiguidade da interface {0} com as seguintes implementa\u00E7\u00F5es\: {1}. Para resolver o conflito, defina explicitamente a implementa\u00E7\u00E3o no demoiselle.properties. |
40 | +ambiguous-bean-resolution=Falha ao obter {0} pois foi detectada ambiguidade nas seguintes implementa\u00E7\u00F5es\: {1} | |
40 | 41 | bean-not-found=Voc\u00EA est\u00E1 tentando obter um objeto n\u00E3o reconhecido pelo CDI via Beans.getReference({0}) |
41 | 42 | more-than-one-exceptionhandler-defined-for-same-class=Foi definido mais de um m\u00E9todo na classe {0} para tratar a exce\u00E7\u00E3o {1} |
42 | 43 | handling-exception=Tratando a exce\u00E7\u00E3o {0} | ... | ... |
impl/core/src/test/java/management/basic/ManagementTest.java
... | ... | @@ -72,13 +72,13 @@ public class ManagementTest { |
72 | 72 | @Test |
73 | 73 | public void readProperty() { |
74 | 74 | DummyManagedClass managedClass = Beans.getReference(DummyManagedClass.class); |
75 | - managedClass.setName("Test Name"); | |
75 | + managedClass.setName("Test AmbiguousQualifier"); | |
76 | 76 | |
77 | 77 | // store é nossa extensão de gerenciamento falsa, então estamos testando um "cliente" acessando |
78 | 78 | // nosso tipo gerenciado DummyManagedClass remotamente. |
79 | 79 | ManagedClassStore store = Beans.getReference(ManagedClassStore.class); |
80 | 80 | Object name = store.getProperty(DummyManagedClass.class, "name"); |
81 | - Assert.assertEquals("Test Name", name); | |
81 | + Assert.assertEquals("Test AmbiguousQualifier", name); | |
82 | 82 | } |
83 | 83 | |
84 | 84 | @Test |
... | ... | @@ -86,10 +86,10 @@ public class ManagementTest { |
86 | 86 | // store é nossa extensão de gerenciamento falsa, então estamos testando um "cliente" definindo |
87 | 87 | // um novo valor em uma propriedade de nosso tipo gerenciado DummyManagedClass remotamente. |
88 | 88 | ManagedClassStore store = Beans.getReference(ManagedClassStore.class); |
89 | - store.setProperty(DummyManagedClass.class, "name", "Test Name"); | |
89 | + store.setProperty(DummyManagedClass.class, "name", "Test AmbiguousQualifier"); | |
90 | 90 | |
91 | 91 | DummyManagedClass managedClass = Beans.getReference(DummyManagedClass.class); |
92 | - Assert.assertEquals("Test Name", managedClass.getName()); | |
92 | + Assert.assertEquals("Test AmbiguousQualifier", managedClass.getName()); | |
93 | 93 | } |
94 | 94 | |
95 | 95 | @Test | ... | ... |
impl/core/src/test/java/util/beans/ambiguous/AmbiguousBeansTest.java
0 → 100644
... | ... | @@ -0,0 +1,100 @@ |
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 util.beans.ambiguous; | |
38 | + | |
39 | +import static junit.framework.Assert.assertEquals; | |
40 | + | |
41 | +import javax.enterprise.inject.AmbiguousResolutionException; | |
42 | +import javax.enterprise.util.AnnotationLiteral; | |
43 | + | |
44 | +import org.jboss.arquillian.container.test.api.Deployment; | |
45 | +import org.jboss.arquillian.junit.Arquillian; | |
46 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
47 | +import org.junit.Test; | |
48 | +import org.junit.runner.RunWith; | |
49 | + | |
50 | +import test.Tests; | |
51 | +import br.gov.frameworkdemoiselle.DemoiselleException; | |
52 | +import br.gov.frameworkdemoiselle.util.Beans; | |
53 | + | |
54 | +@RunWith(Arquillian.class) | |
55 | +public class AmbiguousBeansTest { | |
56 | + | |
57 | + @Deployment | |
58 | + public static JavaArchive createDeployment() { | |
59 | + JavaArchive deployment = Tests.createDeployment(AmbiguousBeansTest.class); | |
60 | + return deployment; | |
61 | + } | |
62 | + | |
63 | + @Test | |
64 | + public void failOnAmbiguousBeansImplementationsTest() { | |
65 | + try { | |
66 | + Beans.getReference(Bean.class); | |
67 | + } catch (DemoiselleException cause) { | |
68 | + assertEquals(AmbiguousResolutionException.class, cause.getCause().getClass()); | |
69 | + } | |
70 | + } | |
71 | + | |
72 | + @Test | |
73 | + public void failOnAmbiguousQualifiedBeansImplementationsTest() { | |
74 | + try { | |
75 | + Beans.getReference(Bean.class, new AnnotationLiteral<AmbiguousQualifier>() { | |
76 | + | |
77 | + private static final long serialVersionUID = 1L; | |
78 | + }); | |
79 | + } catch (DemoiselleException cause) { | |
80 | + assertEquals(AmbiguousResolutionException.class, cause.getCause().getClass()); | |
81 | + } | |
82 | + } | |
83 | + | |
84 | + @Test | |
85 | + public void ambiguityResolvedByQualifiersTest() { | |
86 | + Bean bean; | |
87 | + | |
88 | + bean = Beans.getReference(Bean.class, new AnnotationLiteral<FirstValidQualifier>() { | |
89 | + | |
90 | + private static final long serialVersionUID = 1L; | |
91 | + }); | |
92 | + assertEquals(FirstValidQualifiedBean.class, bean.getClass()); | |
93 | + | |
94 | + bean = Beans.getReference(Bean.class, new AnnotationLiteral<SecondValidQualifier>() { | |
95 | + | |
96 | + private static final long serialVersionUID = 1L; | |
97 | + }); | |
98 | + assertEquals(SecondValidQualifiedBean.class, bean.getClass()); | |
99 | + } | |
100 | +} | ... | ... |
impl/core/src/test/java/util/beans/ambiguous/AmbiguousQualifier.java
0 → 100644
... | ... | @@ -0,0 +1,57 @@ |
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 util.beans.ambiguous; | |
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 | +@Qualifier | |
52 | +@Inherited | |
53 | +@Retention(RUNTIME) | |
54 | +@Target({ TYPE, FIELD, METHOD, PARAMETER }) | |
55 | +public @interface AmbiguousQualifier { | |
56 | + | |
57 | +} | ... | ... |
... | ... | @@ -0,0 +1,41 @@ |
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 util.beans.ambiguous; | |
38 | + | |
39 | +public interface Bean { | |
40 | + | |
41 | +} | ... | ... |
impl/core/src/test/java/util/beans/ambiguous/FirstAmbiguousBean.java
0 → 100644
... | ... | @@ -0,0 +1,41 @@ |
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 util.beans.ambiguous; | |
38 | + | |
39 | +public class FirstAmbiguousBean implements Bean { | |
40 | + | |
41 | +} | ... | ... |
impl/core/src/test/java/util/beans/ambiguous/FirstAmbiguousQualifiedBean.java
0 → 100644
... | ... | @@ -0,0 +1,42 @@ |
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 util.beans.ambiguous; | |
38 | + | |
39 | +@AmbiguousQualifier | |
40 | +public class FirstAmbiguousQualifiedBean implements Bean { | |
41 | + | |
42 | +} | ... | ... |
impl/core/src/test/java/util/beans/ambiguous/FirstValidQualifiedBean.java
0 → 100644
... | ... | @@ -0,0 +1,42 @@ |
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 util.beans.ambiguous; | |
38 | + | |
39 | +@FirstValidQualifier | |
40 | +public class FirstValidQualifiedBean implements Bean { | |
41 | + | |
42 | +} | ... | ... |
impl/core/src/test/java/util/beans/ambiguous/FirstValidQualifier.java
0 → 100644
... | ... | @@ -0,0 +1,57 @@ |
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 util.beans.ambiguous; | |
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 | +@Qualifier | |
52 | +@Inherited | |
53 | +@Retention(RUNTIME) | |
54 | +@Target({ TYPE, FIELD, METHOD, PARAMETER }) | |
55 | +public @interface FirstValidQualifier { | |
56 | + | |
57 | +} | ... | ... |
impl/core/src/test/java/util/beans/ambiguous/SecondAmbiguousBean.java
0 → 100644
... | ... | @@ -0,0 +1,41 @@ |
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 util.beans.ambiguous; | |
38 | + | |
39 | +public class SecondAmbiguousBean implements Bean { | |
40 | + | |
41 | +} | ... | ... |
impl/core/src/test/java/util/beans/ambiguous/SecondAmbiguousQualifiedBean.java
0 → 100644
... | ... | @@ -0,0 +1,42 @@ |
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 util.beans.ambiguous; | |
38 | + | |
39 | +@AmbiguousQualifier | |
40 | +public class SecondAmbiguousQualifiedBean implements Bean { | |
41 | + | |
42 | +} | ... | ... |
impl/core/src/test/java/util/beans/ambiguous/SecondValidQualifiedBean.java
0 → 100644
... | ... | @@ -0,0 +1,42 @@ |
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 util.beans.ambiguous; | |
38 | + | |
39 | +@SecondValidQualifier | |
40 | +public class SecondValidQualifiedBean implements Bean { | |
41 | + | |
42 | +} | ... | ... |
impl/core/src/test/java/util/beans/ambiguous/SecondValidQualifier.java
0 → 100644
... | ... | @@ -0,0 +1,57 @@ |
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 util.beans.ambiguous; | |
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 | +@Qualifier | |
52 | +@Inherited | |
53 | +@Retention(RUNTIME) | |
54 | +@Target({ TYPE, FIELD, METHOD, PARAMETER }) | |
55 | +public @interface SecondValidQualifier { | |
56 | + | |
57 | +} | ... | ... |
impl/core/src/test/java/util/beans/simple/Bean.java
impl/core/src/test/java/util/beans/simple/BeanImpl.java
impl/core/src/test/java/util/beans/simple/NamedBean.java
impl/core/src/test/java/util/beans/simple/SimpleBeansTest.java
... | ... | @@ -61,12 +61,12 @@ public class SimpleBeansTest { |
61 | 61 | } |
62 | 62 | |
63 | 63 | @Test |
64 | - public void beanClassTest() { | |
64 | + public void defaultBeanImplementationTest() { | |
65 | 65 | assertEquals(BeanImpl.class, Beans.getReference(Bean.class).getClass()); |
66 | 66 | } |
67 | 67 | |
68 | 68 | @Test |
69 | - public void beanClassExceptionTest() { | |
69 | + public void failOnGetBeanInterfaceWithoutImplementationTest() { | |
70 | 70 | try { |
71 | 71 | Beans.getReference(AloneBean.class); |
72 | 72 | fail(); |
... | ... | @@ -76,14 +76,14 @@ public class SimpleBeansTest { |
76 | 76 | } |
77 | 77 | |
78 | 78 | @Test |
79 | - public void beanNameTest() { | |
80 | - assertEquals(NamedBean.class, Beans.getReference("DummyClass").getClass()); | |
79 | + public void validBeanNameTest() { | |
80 | + assertEquals(NamedBean.class, Beans.getReference("namedBean").getClass()); | |
81 | 81 | } |
82 | 82 | |
83 | 83 | @Test |
84 | - public void beanNameExceptionTest() { | |
84 | + public void invalidBeanNameTest() { | |
85 | 85 | try { |
86 | - Beans.getReference("NamedBean"); | |
86 | + Beans.getReference("wrongNamedBean"); | |
87 | 87 | fail(); |
88 | 88 | } catch (DemoiselleException cause) { |
89 | 89 | assertEquals(NoSuchElementException.class, cause.getCause().getClass()); | ... | ... |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerProducer.java
... | ... | @@ -111,7 +111,7 @@ public class EntityManagerProducer implements Serializable{ |
111 | 111 | /** |
112 | 112 | * |
113 | 113 | * <p> |
114 | - * Factory that reads the {@link Name} qualifier and creates an entity manager with | |
114 | + * Factory that reads the {@link AmbiguousQualifier} qualifier and creates an entity manager with | |
115 | 115 | * a matching persistence unit name. |
116 | 116 | * </p> |
117 | 117 | * |
... | ... | @@ -149,7 +149,7 @@ public class EntityManagerProducer implements Serializable{ |
149 | 149 | * Uses persistence.xml to get informations about which persistence unit to use. Throws DemoiselleException if more |
150 | 150 | * than one Persistence Unit is defined. |
151 | 151 | * |
152 | - * @return Persistence Unit Name | |
152 | + * @return Persistence Unit AmbiguousQualifier | |
153 | 153 | */ |
154 | 154 | private String getFromXML() { |
155 | 155 | Set<String> persistenceUnits = factory.getCache().keySet(); | ... | ... |