Commit 1758ac0053944927782438157d1067c749d2274e
1 parent
d444f2bc
Exists in
master
Tornando o bootstrap de veto mais reutilizável
Showing
5 changed files
with
89 additions
and
79 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractTransactionBootstrap.java
... | ... | @@ -1,76 +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.bootstrap; | |
38 | - | |
39 | -import javax.enterprise.event.Observes; | |
40 | -import javax.enterprise.inject.spi.ProcessAnnotatedType; | |
41 | - | |
42 | -import br.gov.frameworkdemoiselle.annotation.Priority; | |
43 | -import br.gov.frameworkdemoiselle.transaction.Transaction; | |
44 | -import br.gov.frameworkdemoiselle.util.Reflections; | |
45 | - | |
46 | -public abstract class AbstractTransactionBootstrap<T extends Transaction> extends AbstractBootstrap { | |
47 | - | |
48 | - private Class<T> transactionClass; | |
49 | - | |
50 | - protected <A> void processAnnotatedType(@Observes final ProcessAnnotatedType<A> event) { | |
51 | - Class<?> annotated = event.getAnnotatedType().getJavaClass(); | |
52 | - | |
53 | - if (Reflections.isOfType(annotated, Transaction.class) && annotated != getTransactionClass() | |
54 | - && getPriority(getTransactionClass()) < getPriority(annotated)) { | |
55 | - event.veto(); | |
56 | - } | |
57 | - } | |
58 | - | |
59 | - private int getPriority(Class<?> type) { | |
60 | - int priority = Priority.MAX_PRIORITY; | |
61 | - | |
62 | - if (type.isAnnotationPresent(Priority.class)) { | |
63 | - Priority annotation = type.getAnnotation(Priority.class); | |
64 | - priority = annotation.value(); | |
65 | - } | |
66 | - | |
67 | - return priority; | |
68 | - } | |
69 | - | |
70 | - protected Class<T> getTransactionClass() { | |
71 | - if (this.transactionClass == null) { | |
72 | - this.transactionClass = Reflections.getGenericTypeArgument(this.getClass(), 0); | |
73 | - } | |
74 | - return this.transactionClass; | |
75 | - } | |
76 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractVetoBootstrap.java
0 → 100644
... | ... | @@ -0,0 +1,84 @@ |
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.bootstrap; | |
38 | + | |
39 | +import javax.enterprise.event.Observes; | |
40 | +import javax.enterprise.inject.spi.ProcessAnnotatedType; | |
41 | + | |
42 | +import br.gov.frameworkdemoiselle.annotation.Priority; | |
43 | +import br.gov.frameworkdemoiselle.util.Reflections; | |
44 | + | |
45 | +public abstract class AbstractVetoBootstrap<T, S> extends AbstractBootstrap { | |
46 | + | |
47 | + private Class<T> type; | |
48 | + | |
49 | + private Class<S> subclass; | |
50 | + | |
51 | + protected <A> void processAnnotatedType(@Observes final ProcessAnnotatedType<A> event) { | |
52 | + Class<?> annotated = event.getAnnotatedType().getJavaClass(); | |
53 | + | |
54 | + if (Reflections.isOfType(annotated, getType()) && annotated != getSubclass() | |
55 | + && getPriority(getSubclass()) < getPriority(annotated)) { | |
56 | + event.veto(); | |
57 | + } | |
58 | + } | |
59 | + | |
60 | + private int getPriority(Class<?> type) { | |
61 | + int priority = Priority.MAX_PRIORITY; | |
62 | + | |
63 | + if (type.isAnnotationPresent(Priority.class)) { | |
64 | + Priority annotation = type.getAnnotation(Priority.class); | |
65 | + priority = annotation.value(); | |
66 | + } | |
67 | + | |
68 | + return priority; | |
69 | + } | |
70 | + | |
71 | + protected Class<T> getType() { | |
72 | + if (this.type == null) { | |
73 | + this.type = Reflections.getGenericTypeArgument(this.getClass(), 0); | |
74 | + } | |
75 | + return this.type; | |
76 | + } | |
77 | + | |
78 | + protected Class<S> getSubclass() { | |
79 | + if (this.subclass == null) { | |
80 | + this.subclass = Reflections.getGenericTypeArgument(this.getClass(), 1); | |
81 | + } | |
82 | + return this.subclass; | |
83 | + } | |
84 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultTransaction.java
... | ... | @@ -89,6 +89,6 @@ public class DefaultTransaction implements Transaction { |
89 | 89 | |
90 | 90 | private DemoiselleException getException() { |
91 | 91 | return new DemoiselleException(CoreBundle.get().getString("transaction-not-defined", |
92 | - Transactional.class.getSimpleName())); | |
92 | + Transactional.class.getSimpleName(), Transaction.class.getSimpleName())); | |
93 | 93 | } |
94 | 94 | } | ... | ... |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/JPATransactionBootstrap.java
... | ... | @@ -37,7 +37,8 @@ |
37 | 37 | package br.gov.frameworkdemoiselle.internal.bootstrap; |
38 | 38 | |
39 | 39 | import br.gov.frameworkdemoiselle.transaction.JPATransaction; |
40 | +import br.gov.frameworkdemoiselle.transaction.Transaction; | |
40 | 41 | |
41 | -public class JPATransactionBootstrap extends AbstractTransactionBootstrap<JPATransaction> { | |
42 | +public class JPATransactionBootstrap extends AbstractVetoBootstrap<Transaction, JPATransaction> { | |
42 | 43 | |
43 | 44 | } | ... | ... |
impl/extension/jta/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/JTATransactionBootstrap.java
... | ... | @@ -37,7 +37,8 @@ |
37 | 37 | package br.gov.frameworkdemoiselle.internal.bootstrap; |
38 | 38 | |
39 | 39 | import br.gov.frameworkdemoiselle.transaction.JTATransaction; |
40 | +import br.gov.frameworkdemoiselle.transaction.Transaction; | |
40 | 41 | |
41 | -public class JTATransactionBootstrap extends AbstractTransactionBootstrap<JTATransaction> { | |
42 | +public class JTATransactionBootstrap extends AbstractVetoBootstrap<Transaction, JTATransaction> { | |
42 | 43 | |
43 | 44 | } | ... | ... |