Commit 79fdcb49ff8451ff2d70089c288310141aa7ead3
Exists in
master
Merge branch 'master' of git@github.com:demoiselle/framework.git
Showing
23 changed files
with
716 additions
and
95 deletions
Show diff stats
documentation/reference/pt-BR/bookinfo.xml
... | ... | @@ -3,11 +3,11 @@ |
3 | 3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" []> |
4 | 4 | <bookinfo> |
5 | 5 | |
6 | - <title>Framework Demoiselle &version;</title> | |
6 | + <title>Framework Demoiselle 2.4.0-RC2</title> | |
7 | 7 | <subtitle>Guia de Referência</subtitle> |
8 | 8 | |
9 | - <abstract>Demoiselle &version;: Framework de Código Aberto para o Desenvolvimento de Aplicações Java EE 6</abstract> | |
10 | - <titleabbrev>Demoiselle &version; - Guia de Referência</titleabbrev> | |
9 | + <abstract>Demoiselle 2.4.0-RC2: Framework de Código Aberto para o Desenvolvimento de Aplicações Java EE 6</abstract> | |
10 | + <titleabbrev>Demoiselle 2.4.0-RC2 - Guia de Referência</titleabbrev> | |
11 | 11 | |
12 | 12 | <xi:include href="authorgroup.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> |
13 | 13 | ... | ... |
documentation/reference/pt-BR/configuracao.xml
... | ... | @@ -160,15 +160,15 @@ public class BookmarkConfig { |
160 | 160 | <section> |
161 | 161 | <title>Especificando os parâmetros</title> |
162 | 162 | <para> |
163 | - Atualmente são suportados nativamente pelo <emphasis>Demoiselle Framework</emphasis> parâmetros de cinco tipos | |
164 | - diferentes, são eles: <emphasis>primitivo</emphasis>, <emphasis>wrapped</emphasis>, <emphasis>String</emphasis>, | |
165 | - <emphasis>class</emphasis>, <emphasis>map</emphasis> e <emphasis>array</emphasis>, sendo que os três últimos | |
166 | - são suportados a partir da versão 2.4.0. A seguir vamos explicar e exemplificar como utilizar cada um desses | |
163 | + Atualmente são suportados nativamente pelo <emphasis>Demoiselle Framework</emphasis> parâmetros de sete categorias | |
164 | + diferentes. São eles: tipos primitivos (<emphasis>int, float, boolean, etc</emphasis>), classes <emphasis>wrapper</emphasis> (<emphasis>Integer, Float, Boolean, etc.</emphasis>) | |
165 | + , <emphasis>String</emphasis>, <emphasis>Class</emphasis>, <emphasis>Map</emphasis>, <emphasis>Array</emphasis> e instâncias de <emphasis>Enum</emphasis>. | |
166 | + A seguir vamos explicar e exemplificar como utilizar cada um desses | |
167 | 167 | tipos, e alertar para as possíveis exceções que poderão ser lançadas para sua aplicação. |
168 | 168 | </para> |
169 | 169 | <caution> |
170 | 170 | <para> |
171 | - A partir da versão 2.4.0 não são mais reconhecidas as convenções. Os parâmetros serão procurados exatamente | |
171 | + A partir da versão 2.4.0 não são mais reconhecidas as convenções de substituição de nomes. Os parâmetros serão procurados exatamente | |
172 | 172 | como foram definidos na classe de configuração. |
173 | 173 | </para> |
174 | 174 | </caution> |
... | ... | @@ -332,58 +332,42 @@ untypedClass=package.MyOtherClass |
332 | 332 | <entry> |
333 | 333 | <para> |
334 | 334 | Para utilizar parâmetros do tipo <emphasis>Map</emphasis>, o arquivo de configurações deve usar a seguinte |
335 | - estrutura na formação da chave: <emphasis>prefixo+chavedomap+nomedoatributo</emphasis>. Vejamos um exemplo. | |
335 | + estrutura na formação da chave: <emphasis>prefixo+nomedoatributo+chavedomap</emphasis>. Vejamos um exemplo. | |
336 | 336 | Se temos em nossa aplicação uma classe de configuração como a mostrada abaixo: |
337 | 337 | </para> |
338 | 338 | <programlisting role="JAVA"><![CDATA[ |
339 | 339 | @Configuration |
340 | 340 | public class BookmarkConfig { |
341 | 341 | |
342 | - private Map<String, String> url; | |
342 | + private Map<String, String> connectionConfiguration; | |
343 | 343 | |
344 | - private Map<String, String> driverClass; | |
345 | - | |
346 | - public Map<String, String> getUrl() { | |
347 | - return url; | |
348 | - } | |
349 | - | |
350 | - public Map<String, String> DriverClass() { | |
351 | - return driverClass; | |
344 | + public Map<String, String> getConnectionConfiguration() { | |
345 | + return connectionConfiguration; | |
352 | 346 | } |
353 | 347 | } |
354 | 348 | ]]></programlisting> |
355 | 349 | <para> |
356 | - O arquivo de configuração deverá ser preenchido no formato seguinte (se for do tipo <emphasis>properties</emphasis>): | |
350 | + O arquivo de configuração deverá ser preenchido no seguinte formato (se for do tipo <emphasis>properties</emphasis>): | |
357 | 351 | </para> |
358 | - <programlisting role="PROPERTIES"><![CDATA[ | |
359 | -mapkey1.url=jdbc:postgresql://localhost:5432/app | |
360 | -mapkey2.url=jdbc:mysql://localhost:3306/app | |
361 | -mapkey1.driverClass=org.postgresql.Driver | |
362 | -mapkey2.driverClass=com.mysql.Driver | |
363 | - ]]></programlisting> | |
352 | + <programlisting role="PROPERTIES"><![CDATA[connectionConfiguration.ip=192.168.0.120 | |
353 | +connectionConfiguration.gateway=192.168.0.1 | |
354 | +connectionConfiguration.dns1=200.10.128.99 | |
355 | +connectionConfiguration.dns2=200.10.128.88]]></programlisting> | |
364 | 356 | <para> |
365 | - Dessa forma, ao fazer a chamada <emphasis>url.get("mapkey2");</emphasis>por exemplo, o valor retornado será | |
366 | - <emphasis>jdbc:mysql://localhost:3306/app</emphasis>. | |
357 | + Dessa forma, ao fazer a chamada <emphasis>connectionConfiguration.get("gateway");</emphasis> por exemplo, o valor retornado será | |
358 | + <emphasis>192.168.0.1</emphasis>. | |
367 | 359 | </para> |
368 | - <note> | |
369 | - <para> | |
370 | - O ponto entre a chave do <emphasis>Map</emphasis> e o nome do parâmetro é adicionado automaticamente pelo | |
371 | - framework. | |
372 | - </para> | |
373 | - </note> | |
360 | + | |
374 | 361 | <tip> |
375 | 362 | <para> |
376 | 363 | Você pode utilizar a chave do Map com nome "default" para indicar que, no arquivo de configuração, a chave é formada |
377 | - apenas pela junção do prefixo com o atributo, sem utilizar a própria chave do Map. Por exemplo, se na sua classe | |
378 | - existir um comando como este: | |
379 | - </para> | |
380 | - <programlisting role="JAVA"><![CDATA[ | |
381 | - myMap.get("default"); | |
382 | - ]]></programlisting> | |
383 | - <para>o framework irá procurar no arquivo de configuração uma linha como esta:</para> | |
384 | - <programlisting role="JAVA"><![CDATA[ | |
385 | - prefix.myMap=Default Value | |
386 | - ]]></programlisting> | |
364 | + apenas pela junção do prefixo com o atributo, sem utilizar a própria chave do Map. Por exemplo, se o seu arquivo de propriedades | |
365 | + contiver uma chave: | |
366 | + </para> | |
367 | + <programlisting role="JAVA"><![CDATA[prefix.myMap=Default Value]]></programlisting> | |
368 | + <para>então seu código poderá ter um comando:</para> | |
369 | + <programlisting role="JAVA"><![CDATA[String value = myMap.get("default");]]></programlisting> | |
370 | + <para>e o valor de <emphasis>value</emphasis> será <emphasis>"Default Value"</emphasis>.</para> | |
387 | 371 | </tip> |
388 | 372 | <para> |
389 | 373 | Caso a classe de configuração não esteja associada a um arquivo que contenha a chave de um de seus parâmetros |
... | ... | @@ -427,7 +411,66 @@ integerArray=1 |
427 | 411 | </row> |
428 | 412 | </tbody> |
429 | 413 | </tgroup> |
430 | - </informaltable> | |
414 | + </informaltable> | |
415 | + | |
416 | + <informaltable> | |
417 | + <tgroup cols="1"> | |
418 | + <colspec colwidth="100*" /> | |
419 | + <tbody> | |
420 | + <row> | |
421 | + <entry> | |
422 | + <emphasis role="bold">Enum</emphasis> | |
423 | + </entry> | |
424 | + </row> | |
425 | + <row> | |
426 | + <entry> | |
427 | + <para> | |
428 | + É possível criar uma lista de constantes do tipo <emphasis>Enum</emphasis> e carregar um valor de constante | |
429 | + através de um arquivo de configuração. Por exemplo, caso exista o seguinte <emphasis>Enum</emphasis> | |
430 | + </para> | |
431 | + | |
432 | + <programlisting role="JAVA"><![CDATA[public enum ConfigurationType { | |
433 | + | |
434 | + PROPERTIES , XML , SYSTEM; | |
435 | + | |
436 | +}]]></programlisting> | |
437 | + | |
438 | + <para>e ele seja usado no seguinte arquivo de configuração</para> | |
439 | + | |
440 | + <programlisting role="JAVA"><![CDATA[@Configuration | |
441 | +public class ConfigurationLoader { | |
442 | + | |
443 | + private ConfigurationType loadedConfigurationType; | |
444 | + | |
445 | + public ConfigurationType getLoadedConfigurationType(){ | |
446 | + return loadedConfigurationType; | |
447 | + } | |
448 | +}]]></programlisting> | |
449 | + | |
450 | + <para>O arquivo do tipo <emphasis>properties</emphasis> pode ser criado assim:</para> | |
451 | + | |
452 | + <programlisting role="PROPERTIES"><![CDATA[loadedConfigurationType=SYSTEM]]></programlisting> | |
453 | + | |
454 | + <note> | |
455 | + <para> | |
456 | + O valor definido no arquivo de configuração para atributos do tipo <emphasis>Enum</emphasis> deve | |
457 | + ser idêntico ao nome da constante definida no <emphasis>Enum</emphasis>, inclusive casando letras maiúsculas e | |
458 | + minúsculas. De fato, o valor da propriedade deve casar com o valor retornado no código: | |
459 | + <emphasis>Enum.name()</emphasis>. | |
460 | + </para> | |
461 | + | |
462 | + <para> | |
463 | + Caso o valor definido no arquivo de configuração não case com nenhuma constante definida no <emphasis>Enum</emphasis>, | |
464 | + uma exceção de tipo <emphasis>ConfigurationException</emphasis> de causa <emphasis>ConversionException</emphasis> | |
465 | + será lançada. Já se à propriedade for atribuido um valor vazio, o atributo do tipo <emphasis>Enum</emphasis> receberá | |
466 | + o valor <emphasis>null</emphasis>. | |
467 | + </para> | |
468 | + </note> | |
469 | + </entry> | |
470 | + </row> | |
471 | + </tbody> | |
472 | + </tgroup> | |
473 | + </informaltable> | |
431 | 474 | |
432 | 475 | </section> |
433 | 476 | ... | ... |
documentation/reference/pt-BR/master.xml
... | ... | @@ -14,7 +14,7 @@ |
14 | 14 | </para> |
15 | 15 | <note> |
16 | 16 | <para> |
17 | - Esta documentação refere-se à release &version; do <emphasis>Demoiselle Framework</emphasis> | |
17 | + Esta documentação refere-se à release 2.4.0-RC2 do <emphasis>Demoiselle Framework</emphasis> | |
18 | 18 | e pode diferir significativamente das versões anteriores. |
19 | 19 | </para> |
20 | 20 | </note> | ... | ... |
documentation/reference/pt-BR/security.xml
... | ... | @@ -508,13 +508,13 @@ class GerenciadorBookmark { |
508 | 508 | <programlisting role="JAVA"><![CDATA[public class MeuAuthenticator implements Authenticator { |
509 | 509 | |
510 | 510 | @Override |
511 | - public boolean authenticate() { | |
511 | + public boolean authenticate() throws Exception { | |
512 | 512 | // Escreva aqui seu codigo de autenticacao e retorne true caso o processo seja um sucesso |
513 | 513 | return true; |
514 | 514 | } |
515 | 515 | |
516 | 516 | @Override |
517 | - public Principal getUser() { | |
517 | + public User getUser(){ | |
518 | 518 | // Obtenha dados sobre o usuario autenticado e retorne na forma da interface javax.security.Principal |
519 | 519 | return new Principal(){ |
520 | 520 | public String getName(){ |
... | ... | @@ -524,7 +524,7 @@ class GerenciadorBookmark { |
524 | 524 | } |
525 | 525 | |
526 | 526 | @Override |
527 | - public void unAuthenticate() { | |
527 | + public void unauthenticate() throws Exception { | |
528 | 528 | // Remova qualquer informacao de autenticacao do usuario, apas o retorno deste metodo o usuario |
529 | 529 | // deve ser considerado nao autenticado. |
530 | 530 | } |
... | ... | @@ -532,13 +532,13 @@ class GerenciadorBookmark { |
532 | 532 | <programlisting role="JAVA"><![CDATA[public class MeuAuthorizer implements Authorizer { |
533 | 533 | |
534 | 534 | @Override |
535 | - public boolean hasRole(String role) { | |
535 | + public boolean hasRole(String role) throws Exception { | |
536 | 536 | // Verifique se o usuario autenticado tem o papel informado, retorne true em caso positivo |
537 | 537 | return false; |
538 | 538 | } |
539 | 539 | |
540 | 540 | @Override |
541 | - public boolean hasPermission(String resource, String operation) { | |
541 | + public boolean hasPermission(String resource, String operation) throws Exception { | |
542 | 542 | // Escreva aqui seu codigo de verificação de permissao |
543 | 543 | return false; |
544 | 544 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationEnumValueExtractor.java
... | ... | @@ -58,11 +58,11 @@ public class ConfigurationEnumValueExtractor implements ConfigurationValueExtrac |
58 | 58 | public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception { |
59 | 59 | String value = configuration.getString(prefix + key); |
60 | 60 | |
61 | - if (value!=null){ | |
61 | + if (value!=null && !value.trim().equals("")){ | |
62 | 62 | Object enums[] = field.getType().getEnumConstants(); |
63 | 63 | |
64 | 64 | for (int i=0; i<enums.length; i++){ |
65 | - if ( ((Enum<?>)enums[i]).toString().equalsIgnoreCase(value) ){ | |
65 | + if ( ((Enum<?>)enums[i]).name().equals(value) ){ | |
66 | 66 | return enums[i]; |
67 | 67 | } |
68 | 68 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationMapValueExtractor.java
... | ... | @@ -50,12 +50,6 @@ import org.apache.commons.configuration.Configuration; |
50 | 50 | import br.gov.frameworkdemoiselle.annotation.Priority; |
51 | 51 | import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; |
52 | 52 | |
53 | -/** | |
54 | - * | |
55 | - * TODO Adicionar verificação da existência de duas ou mais configurações JDBC com mesmo nome. Lançar INFO ou Exceção. | |
56 | - * | |
57 | - */ | |
58 | - | |
59 | 53 | @Priority(L2_PRIORITY) |
60 | 54 | public class ConfigurationMapValueExtractor implements ConfigurationValueExtractor { |
61 | 55 | |
... | ... | @@ -63,7 +57,7 @@ public class ConfigurationMapValueExtractor implements ConfigurationValueExtract |
63 | 57 | public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception { |
64 | 58 | Map<String, Object> value = null; |
65 | 59 | |
66 | - String regexp = "^(" + prefix + ")((.+)\\.)?(" + key + ")$"; | |
60 | + String regexp = "^(" + prefix + ")(" + key + ")(\\.(\\w+))?$"; | |
67 | 61 | Pattern pattern = Pattern.compile(regexp); |
68 | 62 | |
69 | 63 | for (Iterator<String> iter = configuration.getKeys(); iter.hasNext();) { |
... | ... | @@ -71,14 +65,16 @@ public class ConfigurationMapValueExtractor implements ConfigurationValueExtract |
71 | 65 | Matcher matcher = pattern.matcher(iterKey); |
72 | 66 | |
73 | 67 | if (matcher.matches()) { |
74 | - String confKey = matcher.group(1) + (matcher.group(2) == null ? "" : matcher.group(2)) | |
75 | - + matcher.group(4); | |
68 | + String confKey = matcher.group(1) + matcher.group(2) + ( matcher.group(3)!=null ? matcher.group(3) : "" ); | |
69 | + | |
70 | + /*matcher.group(1) + (matcher.group(2) == null ? "" : matcher.group(2)) | |
71 | + + matcher.group(4);*/ | |
76 | 72 | |
77 | 73 | if (value == null) { |
78 | 74 | value = new HashMap<String, Object>(); |
79 | 75 | } |
80 | 76 | |
81 | - String mapKey = matcher.group(3) == null ? "default" : matcher.group(3); | |
77 | + String mapKey = matcher.group(4) == null ? "default" : matcher.group(4); | |
82 | 78 | value.put(mapKey, configuration.getString(confKey)); |
83 | 79 | } |
84 | 80 | } | ... | ... |
impl/core/src/test/java/configuration/field/enumeration/AbstractEnumValueConfig.java
0 → 100644
... | ... | @@ -0,0 +1,62 @@ |
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 configuration.field.enumeration; | |
38 | + | |
39 | +import java.io.Serializable; | |
40 | + | |
41 | +public abstract class AbstractEnumValueConfig implements Serializable { | |
42 | + | |
43 | + private static final long serialVersionUID = 1L; | |
44 | + | |
45 | + private ListOfEnum enumValue; | |
46 | + | |
47 | + private ListOfEnum anotherValue; | |
48 | + | |
49 | + private ListOfEnum emptyValue; | |
50 | + | |
51 | + public ListOfEnum getEnumValue() { | |
52 | + return enumValue; | |
53 | + } | |
54 | + | |
55 | + public ListOfEnum getAnotherValue() { | |
56 | + return anotherValue; | |
57 | + } | |
58 | + | |
59 | + public ListOfEnum getEmptyValue() { | |
60 | + return emptyValue; | |
61 | + } | |
62 | +} | ... | ... |
impl/core/src/test/java/configuration/field/enumeration/ConfigurationEnumValueTest.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 configuration.field.enumeration; | |
38 | + | |
39 | +import javax.inject.Inject; | |
40 | + | |
41 | +import org.jboss.arquillian.container.test.api.Deployment; | |
42 | +import org.jboss.arquillian.junit.Arquillian; | |
43 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
44 | +import org.junit.Assert; | |
45 | +import org.junit.Test; | |
46 | +import org.junit.runner.RunWith; | |
47 | + | |
48 | +import test.Tests; | |
49 | +import br.gov.frameworkdemoiselle.configuration.ConfigurationException; | |
50 | + | |
51 | +@RunWith(Arquillian.class) | |
52 | +public class ConfigurationEnumValueTest { | |
53 | + | |
54 | + private static final String PATH = "src/test/resources/configuration/field/enumeration"; | |
55 | + | |
56 | + @Inject | |
57 | + private PropertiesEnumConfig propertiesEnumConfig; | |
58 | + | |
59 | + @Inject | |
60 | + private XmlEnumConfig xmlEnumConfig; | |
61 | + | |
62 | + @Inject | |
63 | + private WrongPropertyEnumConfig wrongPropertyEnumConfig; | |
64 | + | |
65 | + @Deployment | |
66 | + public static JavaArchive createDeployment() { | |
67 | + JavaArchive deployment = Tests.createDeployment(ConfigurationEnumValueTest.class); | |
68 | + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties"); | |
69 | + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.xml"), "demoiselle.xml"); | |
70 | + return deployment; | |
71 | + } | |
72 | + | |
73 | + @Test | |
74 | + public void loadEnumConfig(){ | |
75 | + Assert.assertEquals(ListOfEnum.VALUE_2, propertiesEnumConfig.getEnumValue()); | |
76 | + Assert.assertEquals(ListOfEnum.VALUE_2, xmlEnumConfig.getEnumValue()); | |
77 | + Assert.assertNull(propertiesEnumConfig.getEmptyValue()); | |
78 | + } | |
79 | + | |
80 | + @Test(expected=ConfigurationException.class) | |
81 | + public void checkConverstionException(){ | |
82 | + wrongPropertyEnumConfig.getAnotherValue(); | |
83 | + } | |
84 | +} | ... | ... |
impl/core/src/test/java/configuration/field/enumeration/ListOfEnum.java
0 → 100644
... | ... | @@ -0,0 +1,44 @@ |
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 configuration.field.enumeration; | |
38 | + | |
39 | + | |
40 | +public enum ListOfEnum { | |
41 | + | |
42 | + VALUE_1 , VALUE_2 , VALUE_3; | |
43 | + | |
44 | +} | ... | ... |
impl/core/src/test/java/configuration/field/enumeration/PropertiesEnumConfig.java
0 → 100644
... | ... | @@ -0,0 +1,47 @@ |
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 configuration.field.enumeration; | |
38 | + | |
39 | +import br.gov.frameworkdemoiselle.configuration.ConfigType; | |
40 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | |
41 | + | |
42 | +@Configuration(resource="demoiselle" , type=ConfigType.PROPERTIES , prefix="prefix1") | |
43 | +public class PropertiesEnumConfig extends AbstractEnumValueConfig { | |
44 | + | |
45 | + private static final long serialVersionUID = 1L; | |
46 | + | |
47 | +} | ... | ... |
impl/core/src/test/java/configuration/field/enumeration/WrongPropertyEnumConfig.java
0 → 100644
... | ... | @@ -0,0 +1,47 @@ |
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 configuration.field.enumeration; | |
38 | + | |
39 | +import br.gov.frameworkdemoiselle.configuration.ConfigType; | |
40 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | |
41 | + | |
42 | +@Configuration(resource="demoiselle" , type=ConfigType.PROPERTIES , prefix="prefix2") | |
43 | +public class WrongPropertyEnumConfig extends AbstractEnumValueConfig { | |
44 | + | |
45 | + private static final long serialVersionUID = 1L; | |
46 | + | |
47 | +} | ... | ... |
impl/core/src/test/java/configuration/field/enumeration/XmlEnumConfig.java
0 → 100644
... | ... | @@ -0,0 +1,47 @@ |
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 configuration.field.enumeration; | |
38 | + | |
39 | +import br.gov.frameworkdemoiselle.configuration.ConfigType; | |
40 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | |
41 | + | |
42 | +@Configuration(resource="demoiselle" , type=ConfigType.XML , prefix="prefix1") | |
43 | +public class XmlEnumConfig extends AbstractEnumValueConfig { | |
44 | + | |
45 | + private static final long serialVersionUID = 1L; | |
46 | + | |
47 | +} | ... | ... |
impl/core/src/test/java/configuration/field/map/PropertiesMapFieldConfig.java
... | ... | @@ -39,6 +39,6 @@ package configuration.field.map; |
39 | 39 | import static br.gov.frameworkdemoiselle.configuration.ConfigType.PROPERTIES; |
40 | 40 | import br.gov.frameworkdemoiselle.configuration.Configuration; |
41 | 41 | |
42 | -@Configuration(type = PROPERTIES) | |
42 | +@Configuration(type = PROPERTIES,prefix="configuration.test") | |
43 | 43 | public class PropertiesMapFieldConfig extends AbstractMapFieldConfig { |
44 | 44 | } | ... | ... |
impl/core/src/test/resources/configuration/field/enumeration/demoiselle.properties
0 → 100644
... | ... | @@ -0,0 +1,38 @@ |
1 | +# Demoiselle Framework | |
2 | +# Copyright (C) 2010 SERPRO | |
3 | +# ---------------------------------------------------------------------------- | |
4 | +# This file is part of Demoiselle Framework. | |
5 | +# | |
6 | +# Demoiselle Framework is free software; you can redistribute it and/or | |
7 | +# modify it under the terms of the GNU Lesser General Public License version 3 | |
8 | +# as published by the Free Software Foundation. | |
9 | +# | |
10 | +# This program is distributed in the hope that it will be useful, | |
11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | +# GNU General Public License for more details. | |
14 | +# | |
15 | +# You should have received a copy of the GNU Lesser General Public License version 3 | |
16 | +# along with this program; if not, see <http://www.gnu.org/licenses/> | |
17 | +# or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
18 | +# Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | +# ---------------------------------------------------------------------------- | |
20 | +# Este arquivo é parte do Framework Demoiselle. | |
21 | +# | |
22 | +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
23 | +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
24 | +# do Software Livre (FSF). | |
25 | +# | |
26 | +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
27 | +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
28 | +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
29 | +# para maiores detalhes. | |
30 | +# | |
31 | +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
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., | |
34 | +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
35 | + | |
36 | +prefix1.enumValue=VALUE_2 | |
37 | +prefix1.emptyValue= | |
38 | +prefix2.anotherValue=value_2 | ... | ... |
impl/core/src/test/resources/configuration/field/enumeration/demoiselle.xml
0 → 100644
... | ... | @@ -0,0 +1,45 @@ |
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 | +<configuration> | |
39 | + <prefix1> | |
40 | + <enumValue>VALUE_2</enumValue> | |
41 | + </prefix1> | |
42 | + <prefix2> | |
43 | + <anotherValue>value_2</anotherValue> | |
44 | + </prefix2> | |
45 | +</configuration> | ... | ... |
impl/core/src/test/resources/configuration/field/map/demoiselle.properties
... | ... | @@ -33,9 +33,9 @@ |
33 | 33 | # ou escreva para a Fundação do Software Livre (FSF) Inc., |
34 | 34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
35 | 35 | |
36 | -item1.stringWithDefinedKeyMap=demoiselle | |
37 | -item2.stringWithDefinedKeyMap=framework | |
38 | -item1.emptyValueMap= | |
39 | -item2.emptyValueMap= | |
36 | +configuration.test.stringWithDefinedKeyMap.item1=demoiselle | |
37 | +configuration.test.stringWithDefinedKeyMap.item2=framework | |
38 | +configuration.test.emptyValueMap.item1= | |
39 | +configuration.test.emptyValueMap.item2= | |
40 | 40 | |
41 | -stringWithUndefinedKeyMap=undefined | |
41 | +configuration.test.stringWithUndefinedKeyMap=undefined | ... | ... |
impl/core/src/test/resources/configuration/field/map/demoiselle.xml
... | ... | @@ -36,17 +36,15 @@ |
36 | 36 | --> |
37 | 37 | |
38 | 38 | <configuration> |
39 | - <item1> | |
40 | - <stringWithDefinedKeyMap>demoiselle</stringWithDefinedKeyMap> | |
41 | - </item1> | |
42 | - <item2> | |
43 | - <stringWithDefinedKeyMap>framework</stringWithDefinedKeyMap> | |
44 | - </item2> | |
45 | - <stringWithUndefinedKeyMap>undefined</stringWithUndefinedKeyMap> | |
46 | - <item1> | |
47 | - <emptyValueMap></emptyValueMap> | |
48 | - </item1> | |
49 | - <item2> | |
50 | - <emptyValueMap></emptyValueMap> | |
51 | - </item2> | |
39 | + <stringWithDefinedKeyMap> | |
40 | + <item1>demoiselle</item1> | |
41 | + <item2>framework</item2> | |
42 | + </stringWithDefinedKeyMap> | |
43 | + | |
44 | + <stringWithUndefinedKeyMap>undefined</stringWithUndefinedKeyMap> | |
45 | + | |
46 | + <emptyValueMap> | |
47 | + <item1></item1> | |
48 | + <item2></item2> | |
49 | + </emptyValueMap> | |
52 | 50 | </configuration> | ... | ... |
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JDBCConfig.java
... | ... | @@ -37,10 +37,10 @@ |
37 | 37 | package br.gov.frameworkdemoiselle.internal.configuration; |
38 | 38 | |
39 | 39 | import java.io.Serializable; |
40 | -import java.util.Map; | |
41 | 40 | |
42 | 41 | import br.gov.frameworkdemoiselle.annotation.Name; |
43 | 42 | import br.gov.frameworkdemoiselle.configuration.Configuration; |
43 | + | |
44 | 44 | /** |
45 | 45 | * Provide used to access the configurations of the JDBC connection |
46 | 46 | * |
... | ... | @@ -56,41 +56,41 @@ public class JDBCConfig implements Serializable { |
56 | 56 | private String defaultDataSourceName; |
57 | 57 | |
58 | 58 | @Name("jndi.name") |
59 | - private Map<String, String> jndiName; | |
59 | + private JDBCConfigurationStore jndiName; | |
60 | 60 | |
61 | 61 | @Name("driver.class") |
62 | - private Map<String, String> driverClass; | |
62 | + private JDBCConfigurationStore driverClass; | |
63 | 63 | |
64 | 64 | @Name("url") |
65 | - private Map<String, String> url; | |
65 | + private JDBCConfigurationStore url; | |
66 | 66 | |
67 | 67 | @Name("username") |
68 | - private Map<String, String> username; | |
68 | + private JDBCConfigurationStore username; | |
69 | 69 | |
70 | 70 | @Name("password") |
71 | - private Map<String, String> password; | |
71 | + private JDBCConfigurationStore password; | |
72 | 72 | |
73 | 73 | public String getDefaultDataSourceName() { |
74 | 74 | return defaultDataSourceName; |
75 | 75 | } |
76 | 76 | |
77 | - public Map<String, String> getJndiName() { | |
77 | + public JDBCConfigurationStore getJndiName() { | |
78 | 78 | return jndiName; |
79 | 79 | } |
80 | 80 | |
81 | - public Map<String, String> getDriverClass() { | |
81 | + public JDBCConfigurationStore getDriverClass() { | |
82 | 82 | return driverClass; |
83 | 83 | } |
84 | 84 | |
85 | - public Map<String, String> getUrl() { | |
85 | + public JDBCConfigurationStore getUrl() { | |
86 | 86 | return url; |
87 | 87 | } |
88 | 88 | |
89 | - public Map<String, String> getUsername() { | |
89 | + public JDBCConfigurationStore getUsername() { | |
90 | 90 | return username; |
91 | 91 | } |
92 | 92 | |
93 | - public Map<String, String> getPassword() { | |
93 | + public JDBCConfigurationStore getPassword() { | |
94 | 94 | return password; |
95 | 95 | } |
96 | 96 | } | ... | ... |
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JDBCConfigValueExtractor.java
0 → 100644
... | ... | @@ -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.configuration; | |
38 | + | |
39 | +import static br.gov.frameworkdemoiselle.annotation.Priority.L2_PRIORITY; | |
40 | + | |
41 | +import java.lang.reflect.Field; | |
42 | +import java.util.Iterator; | |
43 | +import java.util.regex.Matcher; | |
44 | +import java.util.regex.Pattern; | |
45 | + | |
46 | +import org.apache.commons.configuration.Configuration; | |
47 | + | |
48 | +import br.gov.frameworkdemoiselle.annotation.Priority; | |
49 | +import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; | |
50 | + | |
51 | +/** | |
52 | + * | |
53 | + * TODO Adicionar verificação da existência de duas ou mais configurações JDBC com mesmo nome. Lançar INFO ou Exceção. | |
54 | + * | |
55 | + */ | |
56 | +@Priority(L2_PRIORITY) | |
57 | +public class JDBCConfigValueExtractor implements ConfigurationValueExtractor { | |
58 | + | |
59 | + @Override | |
60 | + public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception { | |
61 | + JDBCConfigurationStore value = null; | |
62 | + | |
63 | + String regexp = "^(" + prefix + ")((.+)\\.)?(" + key + ")$"; | |
64 | + Pattern pattern = Pattern.compile(regexp); | |
65 | + | |
66 | + for (Iterator<String> iter = configuration.getKeys(); iter.hasNext();) { | |
67 | + String iterKey = iter.next(); | |
68 | + Matcher matcher = pattern.matcher(iterKey); | |
69 | + | |
70 | + if (matcher.matches()) { | |
71 | + String confKey = matcher.group(1) + (matcher.group(2) == null ? "" : matcher.group(2)) | |
72 | + + matcher.group(4); | |
73 | + | |
74 | + if (value == null) { | |
75 | + value = new JDBCConfigurationStore(); | |
76 | + } | |
77 | + | |
78 | + String mapKey = matcher.group(3) == null ? "default" : matcher.group(3); | |
79 | + value.put(mapKey, configuration.getString(confKey)); | |
80 | + } | |
81 | + } | |
82 | + | |
83 | + return value; | |
84 | + } | |
85 | + | |
86 | + @Override | |
87 | + public boolean isSupported(Field field) { | |
88 | + return field.getType() == JDBCConfigurationStore.class; | |
89 | + } | |
90 | +} | ... | ... |
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JDBCConfigurationStore.java
0 → 100644
... | ... | @@ -0,0 +1,80 @@ |
1 | +package br.gov.frameworkdemoiselle.internal.configuration; | |
2 | + | |
3 | +import java.io.Serializable; | |
4 | +import java.util.Collection; | |
5 | +import java.util.HashMap; | |
6 | +import java.util.Map; | |
7 | +import java.util.Map.Entry; | |
8 | +import java.util.Set; | |
9 | + | |
10 | + | |
11 | +public class JDBCConfigurationStore implements Cloneable, Serializable { | |
12 | + | |
13 | + private static final long serialVersionUID = 1L; | |
14 | + | |
15 | + private HashMap<String, String> properties = new HashMap<String, String>(); | |
16 | + | |
17 | + public int size() { | |
18 | + return properties.size(); | |
19 | + } | |
20 | + | |
21 | + public boolean isEmpty() { | |
22 | + return properties.isEmpty(); | |
23 | + } | |
24 | + | |
25 | + public String get(Object key) { | |
26 | + return properties.get(key); | |
27 | + } | |
28 | + | |
29 | + public boolean equals(Object o) { | |
30 | + return properties.equals(o); | |
31 | + } | |
32 | + | |
33 | + public boolean containsKey(Object key) { | |
34 | + return properties.containsKey(key); | |
35 | + } | |
36 | + | |
37 | + public String put(String key, String value) { | |
38 | + return properties.put(key, value); | |
39 | + } | |
40 | + | |
41 | + public int hashCode() { | |
42 | + return properties.hashCode(); | |
43 | + } | |
44 | + | |
45 | + public String toString() { | |
46 | + return properties.toString(); | |
47 | + } | |
48 | + | |
49 | + public void putAll(Map<? extends String, ? extends String> m) { | |
50 | + properties.putAll(m); | |
51 | + } | |
52 | + | |
53 | + public String remove(Object key) { | |
54 | + return properties.remove(key); | |
55 | + } | |
56 | + | |
57 | + public void clear() { | |
58 | + properties.clear(); | |
59 | + } | |
60 | + | |
61 | + public boolean containsValue(Object value) { | |
62 | + return properties.containsValue(value); | |
63 | + } | |
64 | + | |
65 | + public Object clone() { | |
66 | + return properties.clone(); | |
67 | + } | |
68 | + | |
69 | + public Set<String> keySet() { | |
70 | + return properties.keySet(); | |
71 | + } | |
72 | + | |
73 | + public Collection<String> values() { | |
74 | + return properties.values(); | |
75 | + } | |
76 | + | |
77 | + public Set<Entry<String, String>> entrySet() { | |
78 | + return properties.entrySet(); | |
79 | + } | |
80 | +} | ... | ... |
impl/extension/jpa/src/test/resources/producer/demoiselle.properties
impl/extension/jpa/src/test/resources/producer/demoiselle_noscoped.properties
impl/extension/jpa/src/test/resources/producer/demoiselle_viewscoped.properties