From 1d574acad6bcf6067fa4f9865561101e078fa845 Mon Sep 17 00:00:00 2001 From: Cleverson Sacramento Date: Wed, 6 Feb 2013 16:37:10 -0300 Subject: [PATCH] Ajustes no carregamento de configurações Map e correções na extensão JDBC --- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java | 7 ++++--- impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/DataSourceConfig.java | 55 ------------------------------------------------------- impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JdbcConfig.java | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/producer/DataSourceProducer.java | 6 +++--- impl/extension/jdbc/src/test/resources/META-INF/beans.xml | 40 ++++++++++++++++++++++++++++++++++++++++ impl/extension/jdbc/src/test/resources/demoiselle.properties | 0 6 files changed, 110 insertions(+), 61 deletions(-) delete mode 100644 impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/DataSourceConfig.java create mode 100644 impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JdbcConfig.java create mode 100644 impl/extension/jdbc/src/test/resources/META-INF/beans.xml create mode 100644 impl/extension/jdbc/src/test/resources/demoiselle.properties diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java index 6eb29b4..c60cbca 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java @@ -217,7 +217,8 @@ public class ConfigurationLoader implements Serializable { private Object getMap(Key key, Field field, org.apache.commons.configuration.Configuration config) { Map value = null; - Pattern pattern = Pattern.compile("^(" + key.getPrefix() + ")(.+)\\.(" + key.getName() + ")$"); + String regexp = "^(" + key.getPrefix() + ")((.+)\\.)?(" + key.getName() + ")$"; + Pattern pattern = Pattern.compile(regexp); Matcher matcher; String iterKey; @@ -230,13 +231,13 @@ public class ConfigurationLoader implements Serializable { matcher = pattern.matcher(iterKey); if (matcher.matches()) { - mapKey = matcher.group(2); - confKey = matcher.group(1) + matcher.group(2) + "." + matcher.group(3); + confKey = matcher.group(1) + (matcher.group(2) == null ? "" : matcher.group(2)) + matcher.group(4); if (value == null) { value = new HashMap(); } + mapKey = matcher.group(3) == null ? "default" : matcher.group(3); value.put(mapKey, config.getProperty(confKey)); } } diff --git a/impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/DataSourceConfig.java b/impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/DataSourceConfig.java deleted file mode 100644 index 8363b65..0000000 --- a/impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/DataSourceConfig.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Demoiselle Framework - * Copyright (C) 2010 SERPRO - * ---------------------------------------------------------------------------- - * This file is part of Demoiselle Framework. - * - * Demoiselle Framework is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License version 3 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License version 3 - * along with this program; if not, see - * or write to the Free Software Foundation, Inc., 51 Franklin Street, - * Fifth Floor, Boston, MA 02110-1301, USA. - * ---------------------------------------------------------------------------- - * Este arquivo é parte do Framework Demoiselle. - * - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação - * do Software Livre (FSF). - * - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português - * para maiores detalhes. - * - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título - * "LICENCA.txt", junto com esse programa. Se não, acesse - * ou escreva para a Fundação do Software Livre (FSF) Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. - */ -package br.gov.frameworkdemoiselle.internal.configuration; - -import java.io.Serializable; - -import br.gov.frameworkdemoiselle.annotation.Name; -import br.gov.frameworkdemoiselle.configuration.Configuration; - -@Configuration(prefix = "frameworkdemoiselle.jdbc.") -public class DataSourceConfig implements Serializable { - - private static final long serialVersionUID = 1L; - - @Name("jndi.name") - private String jndiName; - - public String getJndiName() { - return jndiName; - } -} diff --git a/impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JdbcConfig.java b/impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JdbcConfig.java new file mode 100644 index 0000000..41f1f28 --- /dev/null +++ b/impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JdbcConfig.java @@ -0,0 +1,63 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package br.gov.frameworkdemoiselle.internal.configuration; + +import java.io.Serializable; +import java.util.Map; + +import br.gov.frameworkdemoiselle.annotation.Name; +import br.gov.frameworkdemoiselle.configuration.Configuration; + +@Configuration(prefix = "frameworkdemoiselle.jdbc.") +public class JdbcConfig implements Serializable { + + private static final long serialVersionUID = 1L; + + @Name("jndi.name") + private Map jndiName; + + @Name("driver.class") + private Map driverClass; + + public Map getJndiName() { + return jndiName; + } + + public Map getDriverClass() { + return driverClass; + } +} diff --git a/impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/producer/DataSourceProducer.java b/impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/producer/DataSourceProducer.java index 9da03f9..598f0fd 100644 --- a/impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/producer/DataSourceProducer.java +++ b/impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/producer/DataSourceProducer.java @@ -9,7 +9,7 @@ import javax.naming.InitialContext; import javax.sql.DataSource; import br.gov.frameworkdemoiselle.configuration.ConfigurationException; -import br.gov.frameworkdemoiselle.internal.configuration.DataSourceConfig; +import br.gov.frameworkdemoiselle.internal.configuration.JdbcConfig; import br.gov.frameworkdemoiselle.util.Beans; @ApplicationScoped @@ -32,8 +32,8 @@ public class DataSourceProducer implements Serializable { DataSource result; try { - DataSourceConfig config = Beans.getReference(DataSourceConfig.class); - String jndi = config.getJndiName(); + JdbcConfig config = Beans.getReference(JdbcConfig.class); + String jndi = config.getJndiName().get("default"); // TODO Lançar exceção caso o JNDI esteja vazio ou nulo. diff --git a/impl/extension/jdbc/src/test/resources/META-INF/beans.xml b/impl/extension/jdbc/src/test/resources/META-INF/beans.xml new file mode 100644 index 0000000..527e828 --- /dev/null +++ b/impl/extension/jdbc/src/test/resources/META-INF/beans.xml @@ -0,0 +1,40 @@ + + + + \ No newline at end of file diff --git a/impl/extension/jdbc/src/test/resources/demoiselle.properties b/impl/extension/jdbc/src/test/resources/demoiselle.properties new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/impl/extension/jdbc/src/test/resources/demoiselle.properties -- libgit2 0.21.2