Commit 1d574acad6bcf6067fa4f9865561101e078fa845
1 parent
9f3ffa23
Exists in
master
Ajustes no carregamento de configurações Map e correções na extensão
JDBC
Showing
6 changed files
with
110 additions
and
61 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java
| ... | ... | @@ -217,7 +217,8 @@ public class ConfigurationLoader implements Serializable { |
| 217 | 217 | private <T> Object getMap(Key key, Field field, org.apache.commons.configuration.Configuration config) { |
| 218 | 218 | Map<String, Object> value = null; |
| 219 | 219 | |
| 220 | - Pattern pattern = Pattern.compile("^(" + key.getPrefix() + ")(.+)\\.(" + key.getName() + ")$"); | |
| 220 | + String regexp = "^(" + key.getPrefix() + ")((.+)\\.)?(" + key.getName() + ")$"; | |
| 221 | + Pattern pattern = Pattern.compile(regexp); | |
| 221 | 222 | Matcher matcher; |
| 222 | 223 | |
| 223 | 224 | String iterKey; |
| ... | ... | @@ -230,13 +231,13 @@ public class ConfigurationLoader implements Serializable { |
| 230 | 231 | matcher = pattern.matcher(iterKey); |
| 231 | 232 | |
| 232 | 233 | if (matcher.matches()) { |
| 233 | - mapKey = matcher.group(2); | |
| 234 | - confKey = matcher.group(1) + matcher.group(2) + "." + matcher.group(3); | |
| 234 | + confKey = matcher.group(1) + (matcher.group(2) == null ? "" : matcher.group(2)) + matcher.group(4); | |
| 235 | 235 | |
| 236 | 236 | if (value == null) { |
| 237 | 237 | value = new HashMap<String, Object>(); |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | + mapKey = matcher.group(3) == null ? "default" : matcher.group(3); | |
| 240 | 241 | value.put(mapKey, config.getProperty(confKey)); |
| 241 | 242 | } |
| 242 | 243 | } | ... | ... |
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/DataSourceConfig.java
| ... | ... | @@ -1,55 +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.configuration; | |
| 38 | - | |
| 39 | -import java.io.Serializable; | |
| 40 | - | |
| 41 | -import br.gov.frameworkdemoiselle.annotation.Name; | |
| 42 | -import br.gov.frameworkdemoiselle.configuration.Configuration; | |
| 43 | - | |
| 44 | -@Configuration(prefix = "frameworkdemoiselle.jdbc.") | |
| 45 | -public class DataSourceConfig implements Serializable { | |
| 46 | - | |
| 47 | - private static final long serialVersionUID = 1L; | |
| 48 | - | |
| 49 | - @Name("jndi.name") | |
| 50 | - private String jndiName; | |
| 51 | - | |
| 52 | - public String getJndiName() { | |
| 53 | - return jndiName; | |
| 54 | - } | |
| 55 | -} |
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JdbcConfig.java
0 → 100644
| ... | ... | @@ -0,0 +1,63 @@ |
| 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.configuration; | |
| 38 | + | |
| 39 | +import java.io.Serializable; | |
| 40 | +import java.util.Map; | |
| 41 | + | |
| 42 | +import br.gov.frameworkdemoiselle.annotation.Name; | |
| 43 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | |
| 44 | + | |
| 45 | +@Configuration(prefix = "frameworkdemoiselle.jdbc.") | |
| 46 | +public class JdbcConfig implements Serializable { | |
| 47 | + | |
| 48 | + private static final long serialVersionUID = 1L; | |
| 49 | + | |
| 50 | + @Name("jndi.name") | |
| 51 | + private Map<String, String> jndiName; | |
| 52 | + | |
| 53 | + @Name("driver.class") | |
| 54 | + private Map<String, String> driverClass; | |
| 55 | + | |
| 56 | + public Map<String, String> getJndiName() { | |
| 57 | + return jndiName; | |
| 58 | + } | |
| 59 | + | |
| 60 | + public Map<String, String> getDriverClass() { | |
| 61 | + return driverClass; | |
| 62 | + } | |
| 63 | +} | ... | ... |
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/producer/DataSourceProducer.java
| ... | ... | @@ -9,7 +9,7 @@ import javax.naming.InitialContext; |
| 9 | 9 | import javax.sql.DataSource; |
| 10 | 10 | |
| 11 | 11 | import br.gov.frameworkdemoiselle.configuration.ConfigurationException; |
| 12 | -import br.gov.frameworkdemoiselle.internal.configuration.DataSourceConfig; | |
| 12 | +import br.gov.frameworkdemoiselle.internal.configuration.JdbcConfig; | |
| 13 | 13 | import br.gov.frameworkdemoiselle.util.Beans; |
| 14 | 14 | |
| 15 | 15 | @ApplicationScoped |
| ... | ... | @@ -32,8 +32,8 @@ public class DataSourceProducer implements Serializable { |
| 32 | 32 | DataSource result; |
| 33 | 33 | |
| 34 | 34 | try { |
| 35 | - DataSourceConfig config = Beans.getReference(DataSourceConfig.class); | |
| 36 | - String jndi = config.getJndiName(); | |
| 35 | + JdbcConfig config = Beans.getReference(JdbcConfig.class); | |
| 36 | + String jndi = config.getJndiName().get("default"); | |
| 37 | 37 | |
| 38 | 38 | // TODO Lançar exceção caso o JNDI esteja vazio ou nulo. |
| 39 | 39 | ... | ... |
impl/extension/jdbc/src/test/resources/META-INF/beans.xml
0 → 100644
| ... | ... | @@ -0,0 +1,40 @@ |
| 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 | +<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 38 | + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> | |
| 39 | + | |
| 40 | +</beans> | |
| 0 | 41 | \ No newline at end of file | ... | ... |
impl/extension/jdbc/src/test/resources/demoiselle.properties
0 → 100644