Commit 5620813f5fef055ae1c3266b9785aa58d8eff9d1
1 parent
8daf2764
Exists in
master
Criação e ativação do bootstrap que lê a estratégia de configuração do
demoiselle.properties
Showing
3 changed files
with
94 additions
and
1 deletions
Show diff stats
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/resources/demoiselle.properties
| @@ -32,3 +32,6 @@ | @@ -32,3 +32,6 @@ | ||
| 32 | # "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | 32 | # "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> |
| 33 | # ou escreva para a Fundação do Software Livre (FSF) Inc., | 33 | # ou escreva para a Fundação do Software Livre (FSF) Inc., |
| 34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | 34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 35 | + | ||
| 36 | +frameworkdemoiselle.transaction.class=br.gov.frameworkdemoiselle.transaction.JPATransaction | ||
| 37 | +#frameworkdemoiselle.transaction.class=br.gov.frameworkdemoiselle.transaction.JTATransaction | ||
| 35 | \ No newline at end of file | 38 | \ No newline at end of file |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/TransactionBootstrap.java
0 → 100644
| @@ -0,0 +1,90 @@ | @@ -0,0 +1,90 @@ | ||
| 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 org.apache.commons.configuration.Configuration; | ||
| 43 | +import org.apache.commons.configuration.PropertiesConfiguration; | ||
| 44 | + | ||
| 45 | +import br.gov.frameworkdemoiselle.configuration.ConfigurationException; | ||
| 46 | +import br.gov.frameworkdemoiselle.internal.implementation.DefaultTransaction; | ||
| 47 | +import br.gov.frameworkdemoiselle.transaction.Transaction; | ||
| 48 | +import br.gov.frameworkdemoiselle.util.Reflections; | ||
| 49 | + | ||
| 50 | +public class TransactionBootstrap extends AbstractBootstrap { | ||
| 51 | + | ||
| 52 | + private static Class<Transaction> selected = loadSelected(); | ||
| 53 | + | ||
| 54 | + public <T> void processAnnotatedType(@Observes final ProcessAnnotatedType<T> event) { | ||
| 55 | + Class<?> annotated = event.getAnnotatedType().getJavaClass(); | ||
| 56 | + | ||
| 57 | + if (Reflections.isOfType(annotated, Transaction.class) && annotated != loadSelected()) { | ||
| 58 | + event.veto(); | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + @SuppressWarnings("unchecked") | ||
| 63 | + private static Class<Transaction> loadSelected() { | ||
| 64 | + synchronized (selected) { | ||
| 65 | + String canonicalName = null; | ||
| 66 | + | ||
| 67 | + try { | ||
| 68 | + Configuration config = new PropertiesConfiguration("demoiselle.properties"); | ||
| 69 | + canonicalName = config.getString("frameworkdemoiselle.transaction.class", | ||
| 70 | + DefaultTransaction.class.getCanonicalName()); | ||
| 71 | + | ||
| 72 | + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | ||
| 73 | + selected = (Class<Transaction>) Class.forName(canonicalName, false, classLoader); | ||
| 74 | + selected.asSubclass(Transaction.class); | ||
| 75 | + | ||
| 76 | + } catch (org.apache.commons.configuration.ConfigurationException cause) { | ||
| 77 | + throw new ConfigurationException(getBundle().getString("file-not-found", "demoiselle.properties")); | ||
| 78 | + | ||
| 79 | + } catch (ClassNotFoundException cause) { | ||
| 80 | + throw new ConfigurationException(getBundle().getString("transaction-class-not-found", canonicalName)); | ||
| 81 | + | ||
| 82 | + } catch (ClassCastException cause) { | ||
| 83 | + throw new ConfigurationException(getBundle().getString("transaction-class-must-be-of-type", | ||
| 84 | + canonicalName, Transaction.class.getCanonicalName())); | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + return selected; | ||
| 89 | + } | ||
| 90 | +} |
impl/core/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
| 1 | br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap | 1 | br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap |
| 2 | br.gov.frameworkdemoiselle.internal.bootstrap.ConfigurationBootstrap | 2 | br.gov.frameworkdemoiselle.internal.bootstrap.ConfigurationBootstrap |
| 3 | -br.gov.frameworkdemoiselle.internal.bootstrap.DefaultTransactionBootstrap | 3 | +br.gov.frameworkdemoiselle.internal.bootstrap.TransactionBootstrap |
| 4 | br.gov.frameworkdemoiselle.internal.bootstrap.StartupBootstrap | 4 | br.gov.frameworkdemoiselle.internal.bootstrap.StartupBootstrap |
| 5 | br.gov.frameworkdemoiselle.internal.bootstrap.ShutdownBootstrap | 5 | br.gov.frameworkdemoiselle.internal.bootstrap.ShutdownBootstrap |