Commit 2b4b22505c7ed57951c6785c154c1251f3ac80fb
1 parent
9c13187e
Exists in
master
Experimentos para funcioar deploy em EAR tendo o demoiselle.properties
na aplicação ao invés do EAR.
Showing
6 changed files
with
235 additions
and
1 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultTransaction.java
... | ... | @@ -37,6 +37,7 @@ |
37 | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
38 | 38 | |
39 | 39 | import javax.enterprise.context.RequestScoped; |
40 | +import javax.enterprise.inject.Any; | |
40 | 41 | |
41 | 42 | import br.gov.frameworkdemoiselle.DemoiselleException; |
42 | 43 | import br.gov.frameworkdemoiselle.transaction.Transaction; |
... | ... | @@ -48,6 +49,7 @@ import br.gov.frameworkdemoiselle.transaction.Transactional; |
48 | 49 | * @author SERPRO |
49 | 50 | * @see Transaction |
50 | 51 | */ |
52 | +@Any | |
51 | 53 | @RequestScoped |
52 | 54 | public class DefaultTransaction implements Transaction { |
53 | 55 | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AbstractStrategyProducer.java
0 → 100644
... | ... | @@ -0,0 +1,147 @@ |
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.FileNotFoundException; | |
40 | +import java.io.Serializable; | |
41 | +import java.net.URL; | |
42 | + | |
43 | +import javax.inject.Inject; | |
44 | + | |
45 | +import org.apache.commons.configuration.Configuration; | |
46 | +import org.apache.commons.configuration.PropertiesConfiguration; | |
47 | + | |
48 | +import br.gov.frameworkdemoiselle.configuration.ConfigurationException; | |
49 | +import br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader; | |
50 | +import br.gov.frameworkdemoiselle.util.Reflections; | |
51 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
52 | +import br.gov.frameworkdemoiselle.util.Strings; | |
53 | + | |
54 | +public abstract class AbstractStrategyProducer<T, D extends T> implements Serializable { | |
55 | + | |
56 | + private static final long serialVersionUID = 1L; | |
57 | + | |
58 | + private Class<T> type; | |
59 | + | |
60 | + private Class<D> defaultClass; | |
61 | + | |
62 | + private Class<? extends T> selected; | |
63 | + | |
64 | + @Inject | |
65 | + private ResourceBundle bundle; | |
66 | + | |
67 | + protected Class<? extends T> getSelected() { | |
68 | + if (selected == null) { | |
69 | + selected = loadSelected(); | |
70 | + } | |
71 | + | |
72 | + return selected; | |
73 | + } | |
74 | + | |
75 | + private Class<T> getType() { | |
76 | + if (this.type == null) { | |
77 | + this.type = Reflections.getGenericTypeArgument(this.getClass(), 0); | |
78 | + } | |
79 | + | |
80 | + return this.type; | |
81 | + } | |
82 | + | |
83 | + private Class<D> getDefaultClass() { | |
84 | + if (this.defaultClass == null) { | |
85 | + this.defaultClass = Reflections.getGenericTypeArgument(this.getClass(), 1); | |
86 | + } | |
87 | + | |
88 | + return this.defaultClass; | |
89 | + }// public <A> void processAnnotatedType(@Observes final ProcessAnnotatedType<A> event) { | |
90 | + // Class<A> annotated = event.getAnnotatedType().getJavaClass(); | |
91 | + | |
92 | + // | |
93 | + // if (Reflections.isOfType(annotated, getType()) && annotated != selected) { | |
94 | + // event.veto(); | |
95 | + // } | |
96 | + // } | |
97 | + | |
98 | + // public void beforeBeanDiscovery(@Observes final BeforeBeanDiscovery event) { | |
99 | + // selected = loadSelected(); | |
100 | + // } | |
101 | + | |
102 | + // public <A> void processAnnotatedType(@Observes final ProcessAnnotatedType<A> event) { | |
103 | + // Class<A> annotated = event.getAnnotatedType().getJavaClass(); | |
104 | + // | |
105 | + // if (Reflections.isOfType(annotated, getType()) && annotated != selected) { | |
106 | + // event.veto(); | |
107 | + // } | |
108 | + // } | |
109 | + | |
110 | + @SuppressWarnings("unchecked") | |
111 | + private Class<T> loadSelected() { | |
112 | + Class<T> result = null; | |
113 | + String canonicalName = null; | |
114 | + String typeName = getType().getSimpleName().toLowerCase(); | |
115 | + String key = null; | |
116 | + | |
117 | + try { | |
118 | + URL url = ConfigurationLoader.getResourceAsURL("demoiselle.properties"); | |
119 | + Configuration config = new PropertiesConfiguration(url); | |
120 | + canonicalName = config.getString(getConfigKey(), getDefaultClass().getCanonicalName()); | |
121 | + | |
122 | + ClassLoader classLoader = ConfigurationLoader.getClassLoaderForResource(canonicalName | |
123 | + .replaceAll("\\.", "/") + ".class"); | |
124 | + result = (Class<T>) Class.forName(canonicalName, false, classLoader); | |
125 | + result.asSubclass(getType()); | |
126 | + | |
127 | + } catch (org.apache.commons.configuration.ConfigurationException cause) { | |
128 | + throw new ConfigurationException(bundle.getString("file-not-found", "demoiselle.properties")); | |
129 | + | |
130 | + } catch (ClassNotFoundException cause) { | |
131 | + key = Strings.getString("{0}-class-not-found", typeName); | |
132 | + throw new ConfigurationException(bundle.getString(key, canonicalName)); | |
133 | + | |
134 | + } catch (ClassCastException cause) { | |
135 | + key = Strings.getString("{0}-class-must-be-of-type", typeName); | |
136 | + throw new ConfigurationException(bundle.getString(key, canonicalName, getType())); | |
137 | + | |
138 | + } catch (FileNotFoundException e) { | |
139 | + throw new ConfigurationException(bundle.getString("file-not-found", "demoiselle.properties")); | |
140 | + } | |
141 | + | |
142 | + return result; | |
143 | + } | |
144 | + | |
145 | + public abstract String getConfigKey(); | |
146 | + | |
147 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/TransactionProducer.java
0 → 100644
... | ... | @@ -0,0 +1,82 @@ |
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 | +/* | |
38 | + * Demoiselle Framework Copyright (c) 2010 Serpro and other contributors as indicated by the @author tag. See the | |
39 | + * copyright.txt in the distribution for a full listing of contributors. Demoiselle Framework is an open source Java EE | |
40 | + * library designed to accelerate the development of transactional database Web applications. Demoiselle Framework is | |
41 | + * released under the terms of the LGPL license 3 http://www.gnu.org/licenses/lgpl.html LGPL License 3 This file is part | |
42 | + * of Demoiselle Framework. Demoiselle Framework is free software: you can redistribute it and/or modify it under the | |
43 | + * terms of the GNU Lesser General Public License 3 as published by the Free Software Foundation. Demoiselle Framework | |
44 | + * is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
45 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You | |
46 | + * should have received a copy of the GNU Lesser General Public License along with Demoiselle Framework. If not, see | |
47 | + * <http://www.gnu.org/licenses/>. | |
48 | + */ | |
49 | +package br.gov.frameworkdemoiselle.internal.producer; | |
50 | + | |
51 | +import java.lang.annotation.Annotation; | |
52 | + | |
53 | +import javax.enterprise.inject.Any; | |
54 | +import javax.enterprise.inject.Default; | |
55 | +import javax.enterprise.inject.Produces; | |
56 | + | |
57 | +import br.gov.frameworkdemoiselle.internal.implementation.DefaultTransaction; | |
58 | +import br.gov.frameworkdemoiselle.transaction.Transaction; | |
59 | +import br.gov.frameworkdemoiselle.util.Beans; | |
60 | + | |
61 | +public class TransactionProducer extends AbstractStrategyProducer<Transaction, DefaultTransaction> { | |
62 | + | |
63 | + private static final long serialVersionUID = 1L; | |
64 | + | |
65 | + @Default | |
66 | + @Produces | |
67 | + public Transaction create() { | |
68 | + return Beans.getReference(getSelected(), new Any() { | |
69 | + | |
70 | + @Override | |
71 | + public Class<? extends Annotation> annotationType() { | |
72 | + return Any.class; | |
73 | + | |
74 | + } | |
75 | + }); | |
76 | + } | |
77 | + | |
78 | + @Override | |
79 | + public String getConfigKey() { | |
80 | + return "frameworkdemoiselle.transaction.class"; | |
81 | + } | |
82 | +} | ... | ... |
impl/core/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
1 | 1 | br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap |
2 | -br.gov.frameworkdemoiselle.internal.bootstrap.TransactionBootstrap | |
3 | 2 | br.gov.frameworkdemoiselle.internal.bootstrap.AuthenticatorBootstrap |
4 | 3 | br.gov.frameworkdemoiselle.internal.bootstrap.AuthorizerBootstrap |
5 | 4 | br.gov.frameworkdemoiselle.internal.bootstrap.StartupBootstrap | ... | ... |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/transaction/JPATransaction.java
... | ... | @@ -39,6 +39,7 @@ package br.gov.frameworkdemoiselle.transaction; |
39 | 39 | import java.util.Collection; |
40 | 40 | |
41 | 41 | import javax.enterprise.context.RequestScoped; |
42 | +import javax.enterprise.inject.Any; | |
42 | 43 | import javax.inject.Inject; |
43 | 44 | import javax.persistence.EntityManager; |
44 | 45 | import javax.persistence.EntityTransaction; |
... | ... | @@ -51,6 +52,7 @@ import br.gov.frameworkdemoiselle.internal.producer.EntityManagerProducer; |
51 | 52 | * @author SERPRO |
52 | 53 | * @see Transaction |
53 | 54 | */ |
55 | +@Any | |
54 | 56 | @RequestScoped |
55 | 57 | public class JPATransaction implements Transaction { |
56 | 58 | ... | ... |
impl/extension/jta/src/main/java/br/gov/frameworkdemoiselle/transaction/JTATransaction.java
... | ... | @@ -37,12 +37,14 @@ |
37 | 37 | package br.gov.frameworkdemoiselle.transaction; |
38 | 38 | |
39 | 39 | import javax.enterprise.context.RequestScoped; |
40 | +import javax.enterprise.inject.Any; | |
40 | 41 | import javax.transaction.Status; |
41 | 42 | import javax.transaction.SystemException; |
42 | 43 | import javax.transaction.UserTransaction; |
43 | 44 | |
44 | 45 | import br.gov.frameworkdemoiselle.util.Beans; |
45 | 46 | |
47 | +@Any | |
46 | 48 | @RequestScoped |
47 | 49 | public class JTATransaction implements Transaction { |
48 | 50 | ... | ... |