Commit a7df783ba26041e0fd09752ae2b2a6bc626e09e8

Authored by Cleverson Sacramento
2 parents bbe0efd1 267885c5
Exists in master

Merge branch '2.3'

Showing 229 changed files with 8718 additions and 6553 deletions   Show diff stats

Too many changes.

To preserve performance only 100 of 229 files displayed.

archetype/jsf-jpa/pom.xml
@@ -45,18 +45,33 @@ @@ -45,18 +45,33 @@
45 <parent> 45 <parent>
46 <groupId>br.gov.frameworkdemoiselle</groupId> 46 <groupId>br.gov.frameworkdemoiselle</groupId>
47 <artifactId>demoiselle-archetype-parent</artifactId> 47 <artifactId>demoiselle-archetype-parent</artifactId>
48 - <version>2.2.3-SNAPSHOT</version>  
49 - <relativePath>../../parent/archetype/pom.xml</relativePath> 48 + <version>2.3.0-RC2-SNAPSHOT</version>
  49 + <relativePath>../../parent/archetype</relativePath>
50 </parent> 50 </parent>
51 51
52 - <name>JSF and JPA Archetype</name>  
53 - <description>Archetype for web applications (JSF/JPA)</description> 52 + <name>Demoiselle Framework JSF and JPA Archetype</name>
  53 + <description>
  54 + Archetype for web applications (JSF/JPA)
  55 + </description>
  56 + <url>http://www.frameworkdemoiselle.gov.br</url>
  57 +
  58 + <licenses>
  59 + <license>
  60 + <name>GNU Lesser General Public License, Version 3</name>
  61 + <url>http://www.gnu.org/licenses/lgpl-3.0.txt</url>
  62 + </license>
  63 + </licenses>
  64 +
  65 + <organization>
  66 + <name>SERPRO - Serviço Federal de Processamento de Dados</name>
  67 + <url>http://www.serpro.gov.br</url>
  68 + </organization>
54 69
55 <repositories> 70 <repositories>
56 <repository> 71 <repository>
57 - <id>demoiselle.sourceforge.net</id>  
58 - <name>Demoiselle Maven Repository</name>  
59 - <url>http://demoiselle.sourceforge.net/repository/release</url> 72 + <id>sonatype-nexus-snapshots</id>
  73 + <name>Sonatype Nexus Snapshots</name>
  74 + <url>https://oss.sonatype.org/content/repositories/snapshots</url>
60 </repository> 75 </repository>
61 </repositories> 76 </repositories>
62 </project> 77 </project>
archetype/jsf-jpa/src/main/resources/archetype-resources/pom.xml
@@ -25,28 +25,30 @@ @@ -25,28 +25,30 @@
25 <artifactId>demoiselle-jpa</artifactId> 25 <artifactId>demoiselle-jpa</artifactId>
26 <scope>compile</scope> 26 <scope>compile</scope>
27 </dependency> 27 </dependency>
  28 + <!-- If you are using a JTA transaction then use this extension -->
  29 + <!--
28 <dependency> 30 <dependency>
29 <groupId>br.gov.frameworkdemoiselle</groupId> 31 <groupId>br.gov.frameworkdemoiselle</groupId>
30 <artifactId>demoiselle-jta</artifactId> 32 <artifactId>demoiselle-jta</artifactId>
31 <scope>compile</scope> 33 <scope>compile</scope>
32 </dependency> 34 </dependency>
  35 + -->
33 <dependency> 36 <dependency>
34 <groupId>org.primefaces</groupId> 37 <groupId>org.primefaces</groupId>
35 <artifactId>primefaces</artifactId> 38 <artifactId>primefaces</artifactId>
36 <scope>compile</scope> 39 <scope>compile</scope>
37 </dependency> 40 </dependency>
  41 +
38 <dependency> 42 <dependency>
39 - <groupId>org.powermock</groupId>  
40 - <artifactId>powermock-api-easymock</artifactId> 43 + <groupId>br.gov.frameworkdemoiselle.component</groupId>
  44 + <artifactId>demoiselle-junit</artifactId>
  45 + <version>2.3.0-RC1</version>
  46 + <scope>test</scope>
  47 + </dependency>
  48 + <dependency>
  49 + <groupId>org.slf4j</groupId>
  50 + <artifactId>slf4j-log4j12</artifactId>
41 <scope>test</scope> 51 <scope>test</scope>
42 </dependency> 52 </dependency>
43 </dependencies> 53 </dependencies>
44 -  
45 - <repositories>  
46 - <repository>  
47 - <id>demoiselle.sourceforge.net-release</id>  
48 - <url>http://demoiselle.sourceforge.net/repository/release</url>  
49 - </repository>  
50 - </repositories>  
51 -  
52 -</project>  
53 \ No newline at end of file 54 \ No newline at end of file
  55 +</project>
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/business/BookmarkBC.java
1 package ${package}.business; 1 package ${package}.business;
2 2
3 -import br.gov.frameworkdemoiselle.annotation.Startup; 3 +import br.gov.frameworkdemoiselle.lifecycle.Startup;
4 import br.gov.frameworkdemoiselle.stereotype.BusinessController; 4 import br.gov.frameworkdemoiselle.stereotype.BusinessController;
5 import br.gov.frameworkdemoiselle.template.DelegateCrud; 5 import br.gov.frameworkdemoiselle.template.DelegateCrud;
6 import br.gov.frameworkdemoiselle.transaction.Transactional; 6 import br.gov.frameworkdemoiselle.transaction.Transactional;
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/domain/Bookmark.java
1 package ${package}.domain; 1 package ${package}.domain;
2 2
  3 +import static javax.persistence.GenerationType.SEQUENCE;
  4 +
3 import java.io.Serializable; 5 import java.io.Serializable;
4 6
5 import javax.persistence.Column; 7 import javax.persistence.Column;
@@ -12,8 +14,11 @@ public class Bookmark implements Serializable { @@ -12,8 +14,11 @@ public class Bookmark implements Serializable {
12 14
13 private static final long serialVersionUID = 1L; 15 private static final long serialVersionUID = 1L;
14 16
  17 + /*
  18 + * If you are using Glassfish then remove the strategy attribute
  19 + */
15 @Id 20 @Id
16 - @GeneratedValue 21 + @GeneratedValue(strategy = SEQUENCE)
17 private Long id; 22 private Long id;
18 23
19 @Column 24 @Column
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/persistence/BookmarkDAO.java
1 package ${package}.persistence; 1 package ${package}.persistence;
2 2
3 -import javax.inject.Inject;  
4 -  
5 -import org.slf4j.Logger;  
6 -  
7 import br.gov.frameworkdemoiselle.stereotype.PersistenceController; 3 import br.gov.frameworkdemoiselle.stereotype.PersistenceController;
8 import br.gov.frameworkdemoiselle.template.JPACrud; 4 import br.gov.frameworkdemoiselle.template.JPACrud;
9 5
@@ -14,8 +10,4 @@ public class BookmarkDAO extends JPACrud&lt;Bookmark, Long&gt; { @@ -14,8 +10,4 @@ public class BookmarkDAO extends JPACrud&lt;Bookmark, Long&gt; {
14 10
15 private static final long serialVersionUID = 1L; 11 private static final long serialVersionUID = 1L;
16 12
17 - @Inject  
18 - @SuppressWarnings("unused")  
19 - private Logger logger;  
20 -  
21 } 13 }
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/resources/META-INF/beans.xml
1 <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 1 <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> 2 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
3 3
4 - <alternatives>  
5 - <class>br.gov.frameworkdemoiselle.transaction.JPATransaction</class>  
6 -  
7 - <!--  
8 - <class>br.gov.frameworkdemoiselle.transaction.JTATransaction</class>  
9 - -->  
10 - </alternatives>  
11 </beans> 4 </beans>
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/resources/META-INF/persistence.xml
@@ -2,10 +2,40 @@ @@ -2,10 +2,40 @@
2 <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> 3 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
4 4
5 - <!-- If you are using jboss6 with non JTA transaction then use this persistence-unit --> 5 + <!-- If you are using JBoss AS7 with non JTA transaction then use this persistence-unit -->
6 <!-- 6 <!--
7 --> 7 -->
8 <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL"> 8 <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL">
  9 + <non-jta-data-source>java:jboss/datasources/ExampleDS</non-jta-data-source>
  10 +
  11 + <class>${package}.domain.Bookmark</class>
  12 +
  13 + <properties>
  14 + <property name="hibernate.show_sql" value="true" />
  15 + <property name="hibernate.format_sql" value="false" />
  16 + <property name="hibernate.hbm2ddl.auto" value="create-drop" />
  17 + </properties>
  18 + </persistence-unit>
  19 +
  20 + <!-- If you are using JBoss AS7 with JTA transaction then use this persistence-unit -->
  21 + <!--
  22 + <persistence-unit name="bookmark-ds" transaction-type="JTA">
  23 + <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
  24 +
  25 + <class>${package}.domain.Bookmark</class>
  26 +
  27 + <properties>
  28 + <property name="hibernate.show_sql" value="true" />
  29 + <property name="hibernate.format_sql" value="false" />
  30 + <property name="hibernate.hbm2ddl.auto" value="update" />
  31 + <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
  32 + </properties>
  33 + </persistence-unit>
  34 + -->
  35 +
  36 + <!-- If you are using JBoss AS6 with non JTA transaction then use this persistence-unit -->
  37 + <!--
  38 + <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL">
9 <non-jta-data-source>java:/DefaultDS</non-jta-data-source> 39 <non-jta-data-source>java:/DefaultDS</non-jta-data-source>
10 40
11 <class>${package}.domain.Bookmark</class> 41 <class>${package}.domain.Bookmark</class>
@@ -14,11 +44,11 @@ @@ -14,11 +44,11 @@
14 <property name="hibernate.show_sql" value="true" /> 44 <property name="hibernate.show_sql" value="true" />
15 <property name="hibernate.format_sql" value="false" /> 45 <property name="hibernate.format_sql" value="false" />
16 <property name="hibernate.hbm2ddl.auto" value="create-drop" /> 46 <property name="hibernate.hbm2ddl.auto" value="create-drop" />
17 - <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />  
18 </properties> 47 </properties>
19 </persistence-unit> 48 </persistence-unit>
20 -  
21 - <!-- If you are using jboss6 with JTA transaction then use this persistence-unit --> 49 + -->
  50 +
  51 + <!-- If you are using JBoss AS6 with JTA transaction then use this persistence-unit -->
22 <!-- 52 <!--
23 <persistence-unit name="bookmark-ds" transaction-type="JTA"> 53 <persistence-unit name="bookmark-ds" transaction-type="JTA">
24 <jta-data-source>java:/DefaultDS</jta-data-source> 54 <jta-data-source>java:/DefaultDS</jta-data-source>
@@ -34,7 +64,37 @@ @@ -34,7 +64,37 @@
34 </persistence-unit> 64 </persistence-unit>
35 --> 65 -->
36 66
37 - <!-- If you are using tomcat6/tomcat7/junit then use this persistence-unit --> 67 + <!-- If you are using GlassFish 3 with non JTA transaction then use this persistence-unit -->
  68 + <!--
  69 + <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL">
  70 + <non-jta-data-source>jdbc/__default</non-jta-data-source>
  71 +
  72 + <class>${package}.domain.Bookmark</class>
  73 +
  74 + <properties>
  75 + <property name="eclipselink.logging.level" value="FINE" />
  76 + <property name="eclipselink.ddl-generation" value="create-tables" />
  77 + <property name="eclipselink.ddl-generation.output-mode" value="database" />
  78 + </properties>
  79 + </persistence-unit>
  80 + -->
  81 +
  82 + <!-- If you are using GlassFish 3 with JTA transaction then use this persistence-unit -->
  83 + <!--
  84 + <persistence-unit name="bookmark-ds" transaction-type="JTA">
  85 + <jta-data-source>jdbc/__TimerPool</jta-data-source>
  86 +
  87 + <class>${package}.domain.Bookmark</class>
  88 +
  89 + <properties>
  90 + <property name="eclipselink.logging.level" value="FINE" />
  91 + <property name="eclipselink.ddl-generation" value="create-tables" />
  92 + <property name="eclipselink.ddl-generation.output-mode" value="database" />
  93 + </properties>
  94 + </persistence-unit>
  95 + -->
  96 +
  97 + <!-- If you are using Tomcat 6 / Tomcat 7 / JUnit then use this persistence-unit -->
38 <!-- 98 <!--
39 <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL"> 99 <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL">
40 100
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/resources/demoiselle.properties
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. 1 +#Enables JPA transaction strategy, automatically detected if demoiselle-jpa component is detected. Use only if you need to overwrite the default behaviour
  2 +#frameworkdemoiselle.transaction.class=br.gov.frameworkdemoiselle.transaction.JPATransaction
35 3
  4 +#Enables JTA transaction strategy, automatically detected if demoiselle-jta component is detected. Use only if you need to overwrite the default behaviour
  5 +#frameworkdemoiselle.transaction.class=br.gov.frameworkdemoiselle.transaction.JTATransaction
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/resources/log4j.properties
1 -# Set root logger level to DEBUG and its only appender to A1.  
2 log4j.rootLogger=INFO, A1 1 log4j.rootLogger=INFO, A1
3 -log4j.logger.br.gov.demoiselle=DEBUG, A1  
4 -  
5 -# A1 is set to be a ConsoleAppender.  
6 log4j.appender.A1=org.apache.log4j.ConsoleAppender 2 log4j.appender.A1=org.apache.log4j.ConsoleAppender
7 -  
8 -# A1 uses PatternLayout.  
9 log4j.appender.A1.layout=org.apache.log4j.PatternLayout 3 log4j.appender.A1.layout=org.apache.log4j.PatternLayout
10 -log4j.appender.A1.layout.ConversionPattern=%-4r %-5p %c - %m%n  
11 \ No newline at end of file 4 \ No newline at end of file
  5 +log4j.appender.A1.layout.ConversionPattern=%-4r %-5p %c - %m%n
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/beans.xml 0 → 100644
@@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
  1 +<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2 + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
  3 +
  4 + <interceptors>
  5 + <class>br.gov.frameworkdemoiselle.internal.interceptor.ExceptionHandlerInterceptor</class>
  6 + <class>br.gov.frameworkdemoiselle.internal.interceptor.RequiredPermissionInterceptor</class>
  7 + <class>br.gov.frameworkdemoiselle.internal.interceptor.RequiredRoleInterceptor</class>
  8 + <class>br.gov.frameworkdemoiselle.internal.interceptor.TransactionalInterceptor</class>
  9 + </interceptors>
  10 +
  11 +</beans>
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
@@ -3,13 +3,28 @@ @@ -3,13 +3,28 @@
3 xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 3 xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
4 version="3.0"> 4 version="3.0">
5 5
6 - <!-- If you are using tomcat6/tomcat7 then uncomment this listener --> 6 + <!-- If you are using tomcat6/tomcat7/gae then uncomment this listener -->
7 <!-- 7 <!--
8 <listener> 8 <listener>
9 <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class> 9 <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
10 </listener> 10 </listener>
11 --> 11 -->
12 12
  13 + <!-- If you are using servlet 2.5 then uncomment this listener -->
  14 + <!--
  15 + <listener>
  16 + <listener-class>br.gov.frameworkdemoiselle.util.ServletListener</listener-class>
  17 + </listener>
  18 + <filter>
  19 + <filter-name>Demoiselle Servlet Filter</filter-name>
  20 + <filter-class>br.gov.frameworkdemoiselle.util.ServletFilter</filter-class>
  21 + </filter>
  22 + <filter-mapping>
  23 + <filter-name>Demoiselle Servlet Filter</filter-name>
  24 + <url-pattern>/*</url-pattern>
  25 + </filter-mapping>
  26 + -->
  27 +
13 <servlet> 28 <servlet>
14 <servlet-name>Faces Servlet</servlet-name> 29 <servlet-name>Faces Servlet</servlet-name>
15 <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 30 <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
@@ -29,5 +44,5 @@ @@ -29,5 +44,5 @@
29 </web-resource-collection> 44 </web-resource-collection>
30 <auth-constraint /> 45 <auth-constraint />
31 </security-constraint> 46 </security-constraint>
32 - 47 +
33 </web-app> 48 </web-app>
archetype/jsf-jpa/src/main/resources/archetype-resources/src/test/java/readme.txt
@@ -1 +0,0 @@ @@ -1 +0,0 @@
1 -resource files to test  
2 \ No newline at end of file 0 \ No newline at end of file
archetype/jsf-jpa/src/main/resources/archetype-resources/src/test/resources/META-INF/beans.xml
1 <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 1 <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> 2 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
3 - 3 +
  4 + <interceptors>
  5 + <class>br.gov.frameworkdemoiselle.internal.interceptor.ExceptionHandlerInterceptor</class>
  6 + <class>br.gov.frameworkdemoiselle.internal.interceptor.RequiredPermissionInterceptor</class>
  7 + <class>br.gov.frameworkdemoiselle.internal.interceptor.RequiredRoleInterceptor</class>
  8 + <class>br.gov.frameworkdemoiselle.internal.interceptor.TransactionalInterceptor</class>
  9 + </interceptors>
  10 +
4 </beans> 11 </beans>
archetype/jsf-jpa/src/main/resources/archetype-resources/src/test/resources/META-INF/persistence.xml
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" /> 13 <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
14 <property name="javax.persistence.jdbc.user" value="sa" /> 14 <property name="javax.persistence.jdbc.user" value="sa" />
15 <property name="javax.persistence.jdbc.password" value="" /> 15 <property name="javax.persistence.jdbc.password" value="" />
16 - <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:hsql:." /> 16 + <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:." />
17 17
18 <property name="hibernate.show_sql" value="true" /> 18 <property name="hibernate.show_sql" value="true" />
19 <property name="hibernate.format_sql" value="false" /> 19 <property name="hibernate.format_sql" value="false" />
archetype/minimal/pom.xml
@@ -45,18 +45,33 @@ @@ -45,18 +45,33 @@
45 <parent> 45 <parent>
46 <groupId>br.gov.frameworkdemoiselle</groupId> 46 <groupId>br.gov.frameworkdemoiselle</groupId>
47 <artifactId>demoiselle-archetype-parent</artifactId> 47 <artifactId>demoiselle-archetype-parent</artifactId>
48 - <version>2.2.3-SNAPSHOT</version>  
49 - <relativePath>../../parent/archetype/pom.xml</relativePath> 48 + <version>2.3.0-RC2-SNAPSHOT</version>
  49 + <relativePath>../../parent/archetype</relativePath>
50 </parent> 50 </parent>
51 51
52 - <name>Minimal Archetype</name>  
53 - <description>Basic archetype for generic applications</description> 52 + <name>Demoiselle Framework Minimal Archetype</name>
  53 + <description>
  54 + Basic archetype for generic applications
  55 + </description>
  56 + <url>http://www.frameworkdemoiselle.gov.br</url>
  57 +
  58 + <licenses>
  59 + <license>
  60 + <name>GNU Lesser General Public License, Version 3</name>
  61 + <url>http://www.gnu.org/licenses/lgpl-3.0.txt</url>
  62 + </license>
  63 + </licenses>
  64 +
  65 + <organization>
  66 + <name>SERPRO - Serviço Federal de Processamento de Dados</name>
  67 + <url>http://www.serpro.gov.br</url>
  68 + </organization>
54 69
55 <repositories> 70 <repositories>
56 <repository> 71 <repository>
57 - <id>demoiselle.sourceforge.net</id>  
58 - <name>Demoiselle Maven Repository</name>  
59 - <url>http://demoiselle.sourceforge.net/repository/release</url> 72 + <id>sonatype-nexus-snapshots</id>
  73 + <name>Sonatype Nexus Snapshots</name>
  74 + <url>https://oss.sonatype.org/content/repositories/snapshots</url>
60 </repository> 75 </repository>
61 </repositories> 76 </repositories>
62 </project> 77 </project>
archetype/minimal/src/main/resources/archetype-resources/pom.xml
@@ -21,16 +21,15 @@ @@ -21,16 +21,15 @@
21 21
22 <dependencies> 22 <dependencies>
23 <dependency> 23 <dependency>
  24 + <groupId>br.gov.frameworkdemoiselle.component</groupId>
  25 + <artifactId>demoiselle-junit</artifactId>
  26 + <version>2.3.0-RC1</version>
  27 + <scope>test</scope>
  28 + </dependency>
  29 + <dependency>
24 <groupId>org.slf4j</groupId> 30 <groupId>org.slf4j</groupId>
25 <artifactId>slf4j-log4j12</artifactId> 31 <artifactId>slf4j-log4j12</artifactId>
26 <scope>test</scope> 32 <scope>test</scope>
27 </dependency> 33 </dependency>
28 </dependencies> 34 </dependencies>
29 -  
30 - <repositories>  
31 - <repository>  
32 - <id>demoiselle.sourceforge.net-release</id>  
33 - <url>http://demoiselle.sourceforge.net/repository/release</url>  
34 - </repository>  
35 - </repositories>  
36 </project> 35 </project>
37 \ No newline at end of file 36 \ No newline at end of file
archetype/minimal/src/main/resources/archetype-resources/src/main/resources/META-INF/beans.xml
1 <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 1 <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> 2 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
3 -  
4 </beans> 3 </beans>
archetype/minimal/src/main/resources/archetype-resources/src/test/resources/META-INF/beans.xml
1 <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 1 <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> 2 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
3 3
  4 + <interceptors>
  5 + <class>br.gov.frameworkdemoiselle.internal.interceptor.ExceptionHandlerInterceptor</class>
  6 + <class>br.gov.frameworkdemoiselle.internal.interceptor.RequiredPermissionInterceptor</class>
  7 + <class>br.gov.frameworkdemoiselle.internal.interceptor.RequiredRoleInterceptor</class>
  8 + <class>br.gov.frameworkdemoiselle.internal.interceptor.TransactionalInterceptor</class>
  9 + </interceptors>
  10 +
4 </beans> 11 </beans>
archetype/pom.xml
@@ -1,89 +0,0 @@ @@ -1,89 +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 -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
38 -  
39 - <modelVersion>4.0.0</modelVersion>  
40 -  
41 - <groupId>br.gov.frameworkdemoiselle</groupId>  
42 - <artifactId>demoiselle-framework-archetype-build</artifactId>  
43 - <version>2.2.3-SNAPSHOT</version>  
44 - <packaging>pom</packaging>  
45 -  
46 - <name>Archetypes Build Aggregator</name>  
47 - <description>  
48 - </description>  
49 -  
50 - <modules>  
51 - <module>jsf-jpa</module>  
52 - <module>minimal</module>  
53 - </modules>  
54 -  
55 - <build>  
56 - <plugins>  
57 - <plugin>  
58 - <groupId>org.codehaus.mojo</groupId>  
59 - <artifactId>wagon-maven-plugin</artifactId>  
60 - <configuration>  
61 - <url>.</url>  
62 - <skip>true</skip>  
63 - </configuration>  
64 - </plugin>  
65 - <plugin>  
66 - <groupId>org.apache.maven.plugins</groupId>  
67 - <artifactId>maven-deploy-plugin</artifactId>  
68 - <configuration>  
69 - <skip>true</skip>  
70 - </configuration>  
71 - </plugin>  
72 - </plugins>  
73 - </build>  
74 -  
75 - <distributionManagement>  
76 - <repository>  
77 - <id />  
78 - <url />  
79 - </repository>  
80 - <snapshotRepository>  
81 - <id />  
82 - <url />  
83 - </snapshotRepository>  
84 - <site>  
85 - <id />  
86 - <url>file://${project.build.directory}/tmp</url>  
87 - </site>  
88 - </distributionManagement>  
89 -</project>  
documentation/pom.xml
@@ -1,89 +0,0 @@ @@ -1,89 +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 -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
38 -  
39 - <modelVersion>4.0.0</modelVersion>  
40 -  
41 - <groupId>br.gov.frameworkdemoiselle</groupId>  
42 - <artifactId>demoiselle-framework-documentation-build</artifactId>  
43 - <packaging>pom</packaging>  
44 - <version>2.2.3-SNAPSHOT</version>  
45 -  
46 - <name>Documentation Build Aggregator</name>  
47 - <description>  
48 - </description>  
49 -  
50 - <modules>  
51 - <module>reference</module>  
52 - <module>quickstart</module>  
53 - </modules>  
54 -  
55 - <build>  
56 - <plugins>  
57 - <plugin>  
58 - <groupId>org.codehaus.mojo</groupId>  
59 - <artifactId>wagon-maven-plugin</artifactId>  
60 - <configuration>  
61 - <url>.</url>  
62 - <skip>true</skip>  
63 - </configuration>  
64 - </plugin>  
65 - <plugin>  
66 - <groupId>org.apache.maven.plugins</groupId>  
67 - <artifactId>maven-deploy-plugin</artifactId>  
68 - <configuration>  
69 - <skip>true</skip>  
70 - </configuration>  
71 - </plugin>  
72 - </plugins>  
73 - </build>  
74 -  
75 - <distributionManagement>  
76 - <repository>  
77 - <id />  
78 - <url />  
79 - </repository>  
80 - <snapshotRepository>  
81 - <id />  
82 - <url />  
83 - </snapshotRepository>  
84 - <site>  
85 - <id />  
86 - <url>file://${project.build.directory}/tmp</url>  
87 - </site>  
88 - </distributionManagement>  
89 -</project>  
documentation/quickstart/pom.xml
@@ -40,16 +40,16 @@ @@ -40,16 +40,16 @@
40 40
41 <artifactId>demoiselle-framework-quickstart</artifactId> 41 <artifactId>demoiselle-framework-quickstart</artifactId>
42 <packaging>jdocbook</packaging> 42 <packaging>jdocbook</packaging>
43 - <version>2.2.3-SNAPSHOT</version> 43 + <version>2.3.0-RC2-SNAPSHOT</version>
44 44
45 <parent> 45 <parent>
46 <groupId>br.gov.frameworkdemoiselle</groupId> 46 <groupId>br.gov.frameworkdemoiselle</groupId>
47 <artifactId>demoiselle-documentation-parent</artifactId> 47 <artifactId>demoiselle-documentation-parent</artifactId>
48 - <version>2</version>  
49 - <relativePath>../../../internal/parent/documentation/pom.xml</relativePath> 48 + <version>3-SNAPSHOT</version>
  49 + <relativePath>../../../internal/parent/documentation</relativePath>
50 </parent> 50 </parent>
51 51
52 - <name>Quickstart Documentation</name> 52 + <name>Demoiselle Framework Quickstart Documentation</name>
53 <description /> 53 <description />
54 54
55 <build> 55 <build>
@@ -99,12 +99,12 @@ @@ -99,12 +99,12 @@
99 </plugins> 99 </plugins>
100 </pluginManagement> 100 </pluginManagement>
101 </build> 101 </build>
102 - 102 +
103 <repositories> 103 <repositories>
104 <repository> 104 <repository>
105 - <id>demoiselle.sourceforge.net</id>  
106 - <name>Demoiselle Maven Repository</name>  
107 - <url>http://demoiselle.sourceforge.net/repository/release</url> 105 + <id>sonatype-nexus-snapshots</id>
  106 + <name>Sonatype Nexus Snapshots</name>
  107 + <url>https://oss.sonatype.org/content/repositories/snapshots</url>
108 </repository> 108 </repository>
109 </repositories> 109 </repositories>
110 110
documentation/quickstart/pt-BR/criacao.xml
@@ -425,7 +425,7 @@ public class BookmarkListMB extends AbstractListPageBean&lt;Bookmark, Long&gt; { @@ -425,7 +425,7 @@ public class BookmarkListMB extends AbstractListPageBean&lt;Bookmark, Long&gt; {
425 <filename>bookmark_list.xhtml</filename> com o conteúdo seguinte: 425 <filename>bookmark_list.xhtml</filename> com o conteúdo seguinte:
426 </para> 426 </para>
427 <programlisting role="XML"><![CDATA[<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" 427 <programlisting role="XML"><![CDATA[<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
428 - xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:h="http://java.sun.com/jsf/html" 428 + xmlns:p="http://primefaces.org/ui" xmlns:h="http://java.sun.com/jsf/html"
429 xmlns:ui="http://java.sun.com/jsf/facelets" template="/template/main.xhtml"> 429 xmlns:ui="http://java.sun.com/jsf/facelets" template="/template/main.xhtml">
430 <ui:define name="body"> 430 <ui:define name="body">
431 <h:form> 431 <h:form>
@@ -470,7 +470,7 @@ public class BookmarkListMB extends AbstractListPageBean&lt;Bookmark, Long&gt; { @@ -470,7 +470,7 @@ public class BookmarkListMB extends AbstractListPageBean&lt;Bookmark, Long&gt; {
470 <filename>menu.xhtml</filename> com o conteúdo seguinte: 470 <filename>menu.xhtml</filename> com o conteúdo seguinte:
471 </para> 471 </para>
472 <programlisting role="XML"><![CDATA[<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" 472 <programlisting role="XML"><![CDATA[<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
473 - xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:h="http://java.sun.com/jsf/html" 473 + xmlns:p="http://primefaces.org/ui" xmlns:h="http://java.sun.com/jsf/html"
474 xmlns:ui="http://java.sun.com/jsf/facelets"> 474 xmlns:ui="http://java.sun.com/jsf/facelets">
475 <h:form> 475 <h:form>
476 <p:menubar> 476 <p:menubar>
documentation/quickstart/pt-BR/melhoria.xml
@@ -130,7 +130,7 @@ public class BookmarkListMB extends AbstractListPageBean&lt;Bookmark, Long&gt; { @@ -130,7 +130,7 @@ public class BookmarkListMB extends AbstractListPageBean&lt;Bookmark, Long&gt; {
130 <filename>bookmark_edit.xhtml</filename> com o conteúdo seguinte: 130 <filename>bookmark_edit.xhtml</filename> com o conteúdo seguinte:
131 </para> 131 </para>
132 <programlisting role="XML"><![CDATA[<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" 132 <programlisting role="XML"><![CDATA[<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
133 - xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:h="http://java.sun.com/jsf/html" 133 + xmlns:p="http://primefaces.org/ui" xmlns:h="http://java.sun.com/jsf/html"
134 xmlns:ui="http://java.sun.com/jsf/facelets" template="/template/main.xhtml"> 134 xmlns:ui="http://java.sun.com/jsf/facelets" template="/template/main.xhtml">
135 <ui:define name="body"> 135 <ui:define name="body">
136 <h:form prependId="false"> 136 <h:form prependId="false">
@@ -184,7 +184,7 @@ public class BookmarkListMB extends AbstractListPageBean&lt;Bookmark, Long&gt; { @@ -184,7 +184,7 @@ public class BookmarkListMB extends AbstractListPageBean&lt;Bookmark, Long&gt; {
184 <filename>bookmark_list.xhtml</filename> com o conteúdo seguinte: 184 <filename>bookmark_list.xhtml</filename> com o conteúdo seguinte:
185 </para> 185 </para>
186 <programlisting role="XML"><![CDATA[<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" 186 <programlisting role="XML"><![CDATA[<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
187 - xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:h="http://java.sun.com/jsf/html" 187 + xmlns:p="http://primefaces.org/ui" xmlns:h="http://java.sun.com/jsf/html"
188 xmlns:ui="http://java.sun.com/jsf/facelets" template="/template/main.xhtml"> 188 xmlns:ui="http://java.sun.com/jsf/facelets" template="/template/main.xhtml">
189 <ui:define name="body"> 189 <ui:define name="body">
190 <h:form> 190 <h:form>
@@ -242,7 +242,7 @@ public class BookmarkListMB extends AbstractListPageBean&lt;Bookmark, Long&gt; { @@ -242,7 +242,7 @@ public class BookmarkListMB extends AbstractListPageBean&lt;Bookmark, Long&gt; {
242 <filename>menu.xhtml</filename> conforme o conteúdo seguinte: 242 <filename>menu.xhtml</filename> conforme o conteúdo seguinte:
243 </para> 243 </para>
244 <programlisting role="XML"><![CDATA[<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" 244 <programlisting role="XML"><![CDATA[<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
245 - xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:h="http://java.sun.com/jsf/html" 245 + xmlns:p="http://primefaces.org/ui" xmlns:h="http://java.sun.com/jsf/html"
246 xmlns:ui="http://java.sun.com/jsf/facelets"> 246 xmlns:ui="http://java.sun.com/jsf/facelets">
247 <h:form> 247 <h:form>
248 <p:menubar> 248 <p:menubar>
documentation/reference/pom.xml
@@ -40,16 +40,16 @@ @@ -40,16 +40,16 @@
40 40
41 <artifactId>demoiselle-framework-reference</artifactId> 41 <artifactId>demoiselle-framework-reference</artifactId>
42 <packaging>jdocbook</packaging> 42 <packaging>jdocbook</packaging>
43 - <version>2.2.3-SNAPSHOT</version> 43 + <version>2.3.0-RC2-SNAPSHOT</version>
44 44
45 <parent> 45 <parent>
46 <groupId>br.gov.frameworkdemoiselle</groupId> 46 <groupId>br.gov.frameworkdemoiselle</groupId>
47 <artifactId>demoiselle-documentation-parent</artifactId> 47 <artifactId>demoiselle-documentation-parent</artifactId>
48 - <version>2</version>  
49 - <relativePath>../../../internal/parent/documentation/pom.xml</relativePath> 48 + <version>3-SNAPSHOT</version>
  49 + <relativePath>../../../internal/parent/documentation</relativePath>
50 </parent> 50 </parent>
51 51
52 - <name>Reference Documentation</name> 52 + <name>Demoiselle Framework Reference Documentation</name>
53 <description /> 53 <description />
54 54
55 <build> 55 <build>
@@ -102,12 +102,12 @@ @@ -102,12 +102,12 @@
102 102
103 <repositories> 103 <repositories>
104 <repository> 104 <repository>
105 - <id>demoiselle.sourceforge.net</id>  
106 - <name>Demoiselle Maven Repository</name>  
107 - <url>http://demoiselle.sourceforge.net/repository/release</url> 105 + <id>sonatype-nexus-snapshots</id>
  106 + <name>Sonatype Nexus Snapshots</name>
  107 + <url>https://oss.sonatype.org/content/repositories/snapshots</url>
108 </repository> 108 </repository>
109 </repositories> 109 </repositories>
110 - 110 +
111 <properties> 111 <properties>
112 <project.context>framework/reference</project.context> 112 <project.context>framework/reference</project.context>
113 </properties> 113 </properties>
documentation/reference/pt-BR/authorgroup.xml
@@ -34,4 +34,12 @@ @@ -34,4 +34,12 @@
34 <firstname>Wilson</firstname> 34 <firstname>Wilson</firstname>
35 <surname>Guimarães</surname> 35 <surname>Guimarães</surname>
36 </author> 36 </author>
  37 + <author>
  38 + <firstname>Emerson</firstname>
  39 + <surname>Oliveira</surname>
  40 + </author>
  41 + <author>
  42 + <firstname>Luciano</firstname>
  43 + <surname>Borges</surname>
  44 + </author>
37 </authorgroup> 45 </authorgroup>
documentation/reference/pt-BR/configuracao.xml
@@ -47,6 +47,25 @@ @@ -47,6 +47,25 @@
47 </section> 47 </section>
48 48
49 <section> 49 <section>
  50 + <title>Configurando</title>
  51 + <para>
  52 + Para um correto funcionamento do Demoiselle é necessário inserir o interceptador de configuração no arquivo <filename>src/main/WEB-INF/beans.xml</filename>.
  53 + </para>
  54 + <programlisting role="XML">
  55 + <![CDATA[
  56 + <beans xmlns="http://java.sun.com/xml/ns/javaee"
  57 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  58 + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  59 + http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
  60 + <interceptors>
  61 + <class>br.gov.frameworkdemoiselle.internal.interceptor.ConfigurationInterceptor</class>
  62 + </interceptors>
  63 + </beans>
  64 + ]]>
  65 + </programlisting>
  66 + </section>
  67 +
  68 + <section>
50 <title>As classes de configuração</title> 69 <title>As classes de configuração</title>
51 <para> 70 <para>
52 A primeira etapa para a utilização do mecanismo de configuração em uma aplicação consiste em criar uma classe específica 71 A primeira etapa para a utilização do mecanismo de configuração em uma aplicação consiste em criar uma classe específica
documentation/reference/pt-BR/excecao.xml
@@ -11,6 +11,25 @@ @@ -11,6 +11,25 @@
11 Oferecemos à você uma alternativa para resolver estes problemas, mas você estará livre para usá-la: isoladamente, 11 Oferecemos à você uma alternativa para resolver estes problemas, mas você estará livre para usá-la: isoladamente,
12 misturando com a forma verbosa ou até mesmo não usá-la. 12 misturando com a forma verbosa ou até mesmo não usá-la.
13 </para> 13 </para>
  14 +
  15 + <section>
  16 + <title>Configurando</title>
  17 + <para>
  18 + Para um correto funcionamento do Demoiselle é necessário inserir o interceptador de exceção no arquivo <filename>src/main/WEB-INF/beans.xml</filename>.
  19 + </para>
  20 + <programlisting role="XML">
  21 + <![CDATA[
  22 + <beans xmlns="http://java.sun.com/xml/ns/javaee"
  23 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24 + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  25 + http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
  26 + <interceptors>
  27 + <class>br.gov.frameworkdemoiselle.internal.interceptor.ExceptionHandlerInterceptor</class>
  28 + </interceptors>
  29 + </beans>
  30 + ]]>
  31 + </programlisting>
  32 + </section>
14 33
15 <section> 34 <section>
16 <title>Tratadores de exceção</title> 35 <title>Tratadores de exceção</title>
documentation/reference/pt-BR/master.xml
@@ -41,7 +41,8 @@ @@ -41,7 +41,8 @@
41 <xi:include href="logger.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> 41 <xi:include href="logger.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
42 <xi:include href="templates.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> 42 <xi:include href="templates.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
43 <xi:include href="security.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> 43 <xi:include href="security.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
44 - <!-- <xi:include href="paginacao.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> --> 44 + <xi:include href="paginacao.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
  45 + <xi:include href="properties.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
45 </part> 46 </part>
46 <!-- parte 2 --> 47 <!-- parte 2 -->
47 <!-- <part id="2">--> 48 <!-- <part id="2">-->
@@ -52,4 +53,4 @@ @@ -52,4 +53,4 @@
52 <!-- apêndices --> 53 <!-- apêndices -->
53 <xi:include href="instalacao.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> 54 <xi:include href="instalacao.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
54 55
55 -</book>  
56 \ No newline at end of file 56 \ No newline at end of file
  57 +</book>
documentation/reference/pt-BR/paginacao.xml
@@ -3,202 +3,289 @@ @@ -3,202 +3,289 @@
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" []> 3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" []>
4 <chapter id="paginacao"> 4 <chapter id="paginacao">
5 5
6 - <title>Paginação</title> 6 + <title>Paginação</title>
7 7
8 - <para>  
9 - Neste capítulo serão considerados os seguintes assuntos:  
10 - <itemizedlist>  
11 - <listitem>motivação para o uso de um mecanismo padronizado para <emphasis>paginação</emphasis>;</listitem>  
12 - <listitem>funcionamento e uso da estrutura <literal>Pagination</literal> e do contexto de paginação (<literal>PaginationContext</literal>).</listitem>  
13 - </itemizedlist>  
14 - </para>  
15 -  
16 - <section>  
17 - <title>Introdução ao mecanismo</title>  
18 - <para>  
19 - A apresentação de conjuntos de registros de médio a grande porte em formato de tabelas em aplicações Web geralmente requer um  
20 - <emphasis>mecanismo de paginação</emphasis>, o qual permite ao cliente ver apenas um pedaço do resultado final, podendo este  
21 - navegar para frente e para trás através dos registros. A menos que o conjunto de registros seja garantidamente pequeno, qualquer  
22 - aplicação do tipo Web com funcionalidades de busca precisa ser dotada de paginação.  
23 - </para>  
24 - <para>  
25 - O mecanismo de paginação para as aplicações fornecido pelo <emphasis>Demoiselle Framework</emphasis> consiste em um algoritmo de  
26 - direcionado ao banco de dados (i.e., Database-Driven Pagination). Essa abordagem, apesar de requerer instruções SQL específicas  
27 - para obter porções determinadas de registros, é a mais utilizada por ser mais eficiente e produzir menos redundância dos dados.  
28 - </para>  
29 - <para>  
30 - É fornecido em tempo de execução um <emphasis>contexto de paginação</emphasis>, o qual tem escopo de sessão e armazena a informação  
31 - de paginação de cada entidade (i.e., bean) que necessite de tal mecanismo. Esse contexto é compartilhado entre as diversas camadas  
32 - da aplicação, especificamente entre as camadas de visão e persistência. Dessa maneira, a paginação dos dados é transparente para a  
33 - camada intermediária (i.e., negócio) e não interfere na modelagem das classes de um projeto.  
34 - </para>  
35 - </section>  
36 -  
37 - <section>  
38 - <title>Códigos de suporte</title>  
39 - <para>  
40 - // TODO: explicar Pagination e PaginationContext  
41 - </para>  
42 - <para>  
43 - Veremos na seção seguinte como implementar a paginação em uma aplicação Java.  
44 -  
45 - - Farão parte do código de suporte para paginação:  
46 - * a classe Pagination: usada para manipular a paginação dos dados resultantes, contendo os campos currentPage (página atual, selecionada na camada de visão), pageSize (tamanho da página, a quantidade de registros que ela comportará) e totalResults (a quantidade de resultados existentes na base de dados);  
47 - * a classe PaginationContext: contexto usado para armazenar e fornecer estruturas do tipo Pagination;  
48 - * a classe PaginationConfig: armazenador de configurações referentes à paginação.  
49 -  
50 -- Códigos internos de suporte no Core:  
51 -  
52 - <programlisting role="JAVA"><![CDATA[  
53 -  
54 -public class Pagination {  
55 -  
56 - private int currentPage;  
57 - private int pageSize;  
58 -  
59 - private Long totalResults;  
60 - private Integer totalPages;  
61 -  
62 - // ...  
63 -}  
64 -  
65 -@SessionScoped  
66 -public class PaginationContext {  
67 -  
68 - private final Map<Class<?>, Pagination> map;  
69 -  
70 - public Pagination getPagination(Class<?> clazz) { ... }  
71 -  
72 - public Pagination getPagination(Class<?> clazz, boolean create) { ... }  
73 -  
74 -}  
75 -  
76 -@Configuration  
77 -public class PaginationConfig {  
78 -  
79 - @Key("default_page_size")  
80 - private int defaultPageSize = 10;  
81 -  
82 - @Key("max_page_links")  
83 - private int maxPageLinks = 5;  
84 -  
85 -}  
86 -  
87 - - Códigos internos de suporte em JPA:  
88 -  
89 -public class JPACrud<T, I> implements Crud<T, I> {  
90 -  
91 - @Inject  
92 - private PaginationContext paginationContext;  
93 -  
94 - // ...  
95 -  
96 - public List<T> findAll() {  
97 -  
98 - final String jpql = "select this from " + getBeanClass().getSimpleName() + " this";  
99 - final Query query = getEntityManager().createQuery(jpql);  
100 -  
101 - final Pagination pagination = paginationContext.getPagination(getBeanClass());  
102 - if (pagination != null) {  
103 - if (pagination.getTotalPages() == null) {  
104 - pagination.setTotalResults(this.countAll());  
105 - }  
106 - query.setFirstResult(pagination.getFirstResult());  
107 - query.setMaxResults(pagination.getPageSize());  
108 - }  
109 -  
110 - // ...  
111 - }  
112 -  
113 -}  
114 -  
115 - - Códigos internos de suporte em JSF:  
116 -  
117 -public abstract class AbstractListPageBean<T, I> extends AbstractPage implements ListPageBean<T, I> {  
118 -  
119 - @Inject  
120 - private PaginationContext paginationContext;  
121 -  
122 - @Inject  
123 - private PaginationConfig paginationConfig;  
124 -  
125 - // ...  
126 -  
127 - public Pagination getPagination() {  
128 - return paginationContext.getPagination(getBeanClass(), true);  
129 - }  
130 -  
131 - public int getPageSize() {  
132 - return paginationConfig.getDefaultPageSize();  
133 - }  
134 -  
135 - public int getMaxPageLinks() {  
136 - return paginationConfig.getMaxPageLinks();  
137 - }  
138 -  
139 -}  
140 -  
141 -frameworkdemoiselle.pagination.default_page_size=50  
142 -frameworkdemoiselle.pagination.max_page_links=10  
143 -  
144 -]]></programlisting>  
145 - </para>  
146 - </section> 8 + <para>
  9 + Neste capítulo serão considerados os seguintes assuntos:
  10 + <itemizedlist>
  11 + <listitem><para>Motivação para o uso de um mecanismo padronizado para <emphasis>paginação</emphasis>;</para></listitem>
  12 + <listitem><para>Funcionamento e uso da estrutura <literal>Pagination</literal> e do contexto de paginação
  13 + (<literal>PaginationContext</literal>).</para></listitem>
  14 + </itemizedlist>
  15 + </para>
  16 +
  17 + <section>
  18 + <title>Introdução ao mecanismo</title>
  19 + <para>
  20 + A apresentação de conjuntos de registros de médio a grande porte em formato de tabelas em aplicações Web geralmente requer um
  21 + <emphasis>mecanismo de paginação</emphasis>, o qual permite ao cliente ver apenas um pedaço do resultado final, podendo este
  22 + navegar para frente e para trás através dos registros. A menos que o conjunto de registros seja garantidamente pequeno, qualquer
  23 + aplicação do tipo Web com funcionalidades de busca precisa ser dotada de paginação.
  24 + </para>
  25 + <para>
  26 + O mecanismo de paginação para as aplicações fornecido pelo <emphasis>Demoiselle Framework</emphasis> consiste em um algoritmo
  27 + direcionado ao banco de dados (i.e., Database-Driven Pagination). Essa abordagem, apesar de requerer instruções SQL específicas
  28 + para obter porções determinadas de registros, é a mais utilizada por ser mais eficiente e produzir menos redundância de dados,
  29 + diminuindo assim tráfego de rede, consumo de memória e reduzindo o tempo de resposta.
  30 + </para>
  31 + <para>
  32 + É fornecido em tempo de execução um <emphasis>contexto de paginação</emphasis>, o qual tem escopo de sessão e armazena a informação
  33 + de paginação de cada entidade (i.e., bean) que necessite de tal mecanismo. Esse contexto é compartilhado entre as diversas camadas
  34 + da aplicação, especificamente entre as camadas de visão e persistência. Dessa maneira, a paginação dos dados é transparente para a
  35 + camada intermediária (i.e., negócio) e não interfere na modelagem das classes de um projeto.
  36 + </para>
  37 + </section>
  38 +
  39 + <section>
  40 + <title>Códigos de suporte</title>
  41 + <!--
  42 + <para>
  43 + // TODO: explicar Pagination e PaginationContext
  44 + </para>
  45 + -->
  46 + <para>
  47 + O <emphasis>mecanismo de paginação</emphasis> do <emphasis>Demoiselle Framework</emphasis> permite que os parâmetros para a consulta
  48 + no banco sejam configurados de forma bastante prática. Por outro lado, a consulta paginada ao banco já é feita pela extensão
  49 + <literal>demoiselle-jpa</literal>. Dessa forma, basta ajustar os parametros da paginação, e pedir as consultas normalmente.
  50 + O resultado da consulta é então passado para algum componente de iteração de dados com suporte ao mecanismo conhecido como <emphasis>Lazy
  51 + Load</emphasis> (ou <emphasis>Lazy Loading</emphasis>).
  52 + </para>
  53 + <para>
  54 + Farão parte do código de suporte para paginação:
  55 + <itemizedlist>
  56 + <listitem>
  57 + <para>
  58 + A classe <literal>Pagination</literal>: usada para manipular a paginação dos dados resultantes, contendo os campos <literal>currentPage</literal>
  59 + (página atual, selecionada na camada de visão), <literal>pageSize</literal> (tamanho da página, a quantidade de registros que ela comportará)
  60 + e <literal>totalResults</literal> (a quantidade de resultados existentes na base de dados);
  61 + </para>
  62 + </listitem>
  63 + <listitem>
  64 + <para>
  65 + A classe <literal>PaginationContext</literal>: contexto usado para armazenar e fornecer estruturas do tipo <literal>Pagination</literal>;
  66 + </para>
  67 + </listitem>
  68 + <listitem>
  69 + <para>
  70 + A classe <literal>PaginationConfig</literal>: armazenador de configurações referentes à paginação.
  71 + </para>
  72 + </listitem>
  73 + </itemizedlist>
  74 + </para>
  75 +
  76 + <para>Códigos internos de suporte no Core:</para>
  77 +
  78 + <programlisting role="JAVA"><![CDATA[
  79 + public class Pagination {
  80 +
  81 + private int currentPage;
  82 + private int pageSize;
  83 +
  84 + private Long totalResults;
  85 + private Integer totalPages;
  86 +
  87 + // ...
  88 + }
  89 +
  90 + @SessionScoped
  91 + public class PaginationContext {
  92 +
  93 + private final Map<Class<?>, Pagination> map;
  94 +
  95 + public Pagination getPagination(Class<?> clazz) { ... }
  96 +
  97 + public Pagination get -->Pagination(Class<?> clazz, boolean create) { ... }
  98 +
  99 + }
  100 +
  101 + @Configuration
  102 + public class PaginationConfig {
  103 +
  104 + @Key("default_page_size")
  105 + private int defaultPageSize = 10;
  106 +
  107 + @Key("max_page_links")
  108 + private int maxPageLinks = 5;
  109 +
  110 + }
  111 + ]]></programlisting>
  112 +
  113 + <para>Códigos internos de suporte em JPA:</para>
  114 +
  115 + <programlisting role="JAVA"><![CDATA[
  116 + public class JPACrud<T, I> implements Crud<T, I> {
  117 +
  118 + @Inject
  119 + private PaginationContext paginationContext;
  120 +
  121 + // ...
  122 +
  123 + public List<T> findAll() {
  124 +
  125 + final String jpql = "select this from " + getBeanClass().getSimpleName() + " this";
  126 + final Query query = getEntityManager().createQuery(jpql);
  127 +
  128 + final Pagination pagination = paginationContext.getPagination(getBeanClass());
  129 + if (pagination != null) {
  130 + if (pagination.getTotalPages() == null) {
  131 + pagination.setTotalResults(this.countAll());
  132 + }
  133 + query.setFirstResult(pagination.getFirstResult());
  134 + query.setMaxResults(pagination.getPageSize());
  135 + }
  136 +
  137 + // ...
  138 + }
  139 +
  140 + }
  141 + ]]></programlisting>
  142 +
  143 + <para>Códigos internos de suporte em JSF:</para>
  144 +
  145 + <programlisting role="JAVA"><![CDATA[
  146 + public abstract class AbstractListPageBean<T, I> extends AbstractPage
  147 + implements ListPageBean<T, I> {
  148 +
  149 + @Inject
  150 + private PaginationContext paginationContext;
  151 +
  152 + @Inject
  153 + private PaginationConfig paginationConfig;
  154 +
  155 + // ...
  156 +
  157 + public Pagination getPagination() {
  158 + return paginationContext.getPagination(getBeanClass(), true);
  159 + }
  160 +
  161 + public int getPageSize() {
  162 + return paginationConfig.getDefaultPageSize();
  163 + }
  164 +
  165 + public int getMaxPageLinks() {
  166 + return paginationConfig.getMaxPageLinks();
  167 + }
  168 +
  169 + }
  170 + ]]></programlisting>
  171 + </section>
147 172
148 - <section>  
149 - <title>Implementação na aplicação</title>  
150 - <!--  
151 - <para>  
152 - A fim de utilizar o mecanismo inerente do <emphasis>Demoiselle Framework</emphasis>, é preciso simplesmente anotar os métodos  
153 - contendo as instruções desejadas com <literal>@Startup</literal>, para a <emphasis>inicialização</emphasis>, ou  
154 - <literal>@Shutdown</literal>, para a <emphasis>finalização</emphasis>.  
155 - </para>  
156 - <tip>  
157 - <para>  
158 - O mecanismo de inicialização do <emphasis>Demoiselle Framework</emphasis> é independente da natureza da aplicação Java, isto é,  
159 - visa tanto aplicações do tipo Web quanto do tipo desktop (ex: Swing).  
160 - </para>  
161 - </tip>  
162 - <para>  
163 - As instruções contidas em um método anotado com <literal>@Startup</literal> serão executadas automaticamente quando a aplicação  
164 - Java for inicializada, seja ela hospedada em um contêiner Web ou executada através de um método <literal>main()</literal>.  
165 - Nenhum outro arquivo ou classe precisa ser definido. A anotação <literal>@Startup</literal> permite a indicação do argumento  
166 - <literal>priority</literal>, um número inteiro que serve para definir a prioridade de execução do respectivo método na existência  
167 - de mais de um inicializador para a aplicação.  
168 - </para>  
169 - <para>  
170 - De maneira análoga, um método anotado com <literal>@Shutdown</literal> será executado no momento de finalização de uma aplicação,  
171 - obedecendo também à ordem de prioridade definida com o argumento <literal>priority</literal>.  
172 - </para>  
173 - -->  
174 - <para>  
175 - Eis um exemplo de implementação de paginação em uma aplicação:  
176 - </para>  
177 - <programlisting role="JAVA"><![CDATA[  
178 - @Inject  
179 - private PaginationContext paginationContext;  
180 -]]></programlisting>  
181 - <programlisting role="JAVA"><![CDATA[  
182 - Pagination pagination = paginationContext.getPagination(Audit.class);  
183 -]]></programlisting>  
184 - <tip>  
185 - <para>  
186 - O método <literal>getPagination()</literal> do contexto <literal>PaginationContext</literal> é sobrecarregado, podendo aceitar  
187 - os seguintes argumentos: <literal>Class</literal> ou <literal>Class</literal> e <literal>boolean</literal>.  
188 - </para>  
189 - </tip>  
190 - <note>  
191 - <para>  
192 - A JPA 2.0, através da Query API, suporta controle de paginação independente de fornecedor de banco de dados.  
193 - Para controlar a paginação, a interface <literal>Query</literal> define os métodos <literal>setFirstResult()</literal> e  
194 - <literal>setMaxResults()</literal> para especificar o primeiro resultado a ser recebido e o número máximo de resultados a  
195 - serem retornados em relação àquele ponto. Internamente, são usadas instruções específicas do SGBD (ex: LIMIT e OFFSET no  
196 - PostgreSQL).  
197 - </para>  
198 - </note> 173 + <section>
  174 + <title>Implementação na aplicação</title>
  175 + <para>
  176 + Veremos nessa seção como implementar a paginação em uma aplicação Java. Para esse exmplo tomamos como base a aplicação de Bookmarks
  177 + fornecida pelo arquétipo <emphasis>JSF com JPA</emphasis> do <emphasis>Demoiselle Framework</emphasis> (para maiores detalhes
  178 + ver <link linkend="estrutura">Arquétipos</link>). Iremos utilizar o componente <literal>DataTable</literal> do <emphasis>PrimeFaces</emphasis>,
  179 + que oferece o mecanismo de <emphasis>Lazy Loading</emphasis> conhecido como <literal>LazyDataModel</literal>, muito útil para paginação
  180 + e classificação de dados.
  181 + </para>
  182 + <para>
  183 + Primeiro é preciso configurar um objeto <literal>LazyDataModel</literal> no construtor do <emphasis>Managed Bean</emphasis>
  184 + (<emphasis>BookmarkList</emphasis> nesse exemplo): instancia-lo e sobrescrever o método abstrado <literal>load</literal>, que recebe
  185 + vários argumentos. Esses argumentos são recuperados na página <literal>jsf</literal> que carrega a instância do objeto <literal>LazyDataModel</literal>.
  186 + </para>
  187 + <para>
  188 + Dentro do método <literal>load</literal> iremos pegar do contexto de paginação uma instância da implementação da interface <literal>Pagination</literal>
  189 + e ajustar alguns dos seus parâmetros para: indicar a partir de qual item a paginação deve iniciar, e o tamanho (quantidade de itens) de cada página.
  190 + Esses dados são usados no método <literal>findAll()</literal>, da classe <literal>JPACrud</literal> (extensão JPA), que utiliza o contexto de
  191 + paginação para pegar os parametros e fazer a consulta no banco buscando apenas os itens que estão dentro da pagina que o parametro
  192 + <literal>first</literal> indicar. O resultado é passado para a instancia do <literal>LazyDataModel</literal>, que é responsável por exibir
  193 + os dados de forma apropriada.
  194 + </para>
  195 + <para>
  196 + À classe <emphasis>BookmarkList</emphasis> devem ser adicionados os seguintes trechos de código:
  197 + </para>
  198 +
  199 + <programlisting role="JAVA"><![CDATA[
  200 + // ...
  201 + import java.util.Map;
  202 + import br.gov.frameworkdemoiselle.pagination.Pagination;
  203 +
  204 + // ...
  205 + private LazyDataModel<Bookmark> lazyModel;
  206 +
  207 + public BookmarkListMB() {
  208 + lazyModel = new LazyDataModel<Bookmark>() {
  209 +
  210 + @Override
  211 + public List<Bookmark> load (int first, int pageSize, String sortField,
  212 + SortOrder sortOrder, Map<String, String> filters){
  213 +
  214 + Pagination pagination = getPagination();
  215 + pagination.setPageSize(pageSize);
  216 + pagination.setFirstResult(first);
  217 +
  218 + List<Bookmark> itemsList = bc.findAll();
  219 +
  220 + lazyModel.setRowCount(pagination.getTotalResults());
  221 +
  222 + return itemsList;
  223 + }
  224 + };
  225 + }
  226 +
  227 + // ...
  228 +
  229 + public LazyDataModel<Bookmark> getLazyModel() {
  230 + return lazyModel;
  231 + }
  232 +
  233 + // ...
  234 + ]]></programlisting>
  235 +
  236 + <para>
  237 + No arquivo <literal>messages.properties</literal> adicione as linhas:
  238 + </para>
  239 +
  240 + <programlisting role="JAVA"><![CDATA[
  241 + page.first=0
  242 + page.rows=4
  243 + page.max.links=3
  244 + ]]></programlisting>
  245 +
  246 + <para>
  247 + Na página JSF <literal>bookmark_list.xhtml</literal>, substitua a linha:
  248 + </para>
  249 +
  250 + <programlisting role="JAVA"><![CDATA[
  251 + <p:dataTable id="list" var="bean" value="#{bookmarkListMB.resultList}">
  252 + ]]></programlisting>
  253 +
  254 + <para>
  255 + por:
  256 + </para>
  257 +
  258 + <programlisting role="JAVA"><![CDATA[
  259 + <p:dataTable id="list" var="bean"
  260 + value="#{bookmarkListMB.lazyModel}" lazy="true" paginator="true"
  261 + first="#{messages['page.first']}" rows="#{messages['page.rows']}"
  262 + pageLinks="#{messages['page.max.links']}">
  263 + ]]></programlisting>
  264 +
  265 + <para>
  266 + Com essas alterações simples, a aplicação Bookmarks passa a utilizar o mecanismo de paginação oferecido pelo <emphasis>Demoiselle Framework</emphasis>.
  267 + </para>
  268 +
  269 + <tip>
  270 + <para>
  271 + O método <literal>getPagination()</literal> do contexto <literal>PaginationContext</literal> é sobrecarregado, podendo aceitar
  272 + os seguintes argumentos: <literal>Class</literal> ou <literal>Class</literal> e <literal>boolean</literal>.
  273 + </para>
  274 + </tip>
  275 + <note>
  276 + <para>
  277 + A JPA 2.0, através da Query API, suporta controle de paginação independente de fornecedor de banco de dados.
  278 + Para controlar a paginação, a interface <literal>Query</literal> define os métodos <literal>setFirstResult()</literal> e
  279 + <literal>setMaxResults()</literal> para especificar o primeiro resultado a ser recebido e o número máximo de resultados a
  280 + serem retornados em relação àquele ponto. Internamente, são usadas instruções específicas do SGBD (ex: LIMIT e OFFSET no
  281 + PostgreSQL).
  282 + </para>
  283 + </note>
199 </section> 284 </section>
200 285
201 - <section> 286 +</chapter>
  287 +
  288 +<!--<section>
202 <title>Um exemplo usando PrimeFaces</title> 289 <title>Um exemplo usando PrimeFaces</title>
203 <para> 290 <para>
204 Eis um interessante caso de uso de paginação: ????. 291 Eis um interessante caso de uso de paginação: ????.
@@ -259,7 +346,8 @@ public class AuditMB extends AbstractListPageBean&lt;Audit, Long&gt; { @@ -259,7 +346,8 @@ public class AuditMB extends AbstractListPageBean&lt;Audit, Long&gt; {
259 value="#{auditMB.lazyModel}" lazy="true" paginator="true" 346 value="#{auditMB.lazyModel}" lazy="true" paginator="true"
260 rows="#{auditMB.pageSize}" pageLinks="#{auditMB.maxPageLinks}">]]></programlisting> 347 rows="#{auditMB.pageSize}" pageLinks="#{auditMB.maxPageLinks}">]]></programlisting>
261 </section> 348 </section>
262 - 349 + -->
  350 +<!--
263 <section> 351 <section>
264 <title>Referências</title> 352 <title>Referências</title>
265 <itemizedlist> 353 <itemizedlist>
@@ -267,8 +355,8 @@ public class AuditMB extends AbstractListPageBean&lt;Audit, Long&gt; { @@ -267,8 +355,8 @@ public class AuditMB extends AbstractListPageBean&lt;Audit, Long&gt; {
267 <listitem>Implementing Search Result Pagination in a Web Application (http://www.developer.com/java/other/article.php/3696226/)</listitem> 355 <listitem>Implementing Search Result Pagination in a Web Application (http://www.developer.com/java/other/article.php/3696226/)</listitem>
268 <listitem>A Pagination Technique Using Spring (http://www.developer.com/java/web/article.php/10935_3830886_1/)</listitem> 356 <listitem>A Pagination Technique Using Spring (http://www.developer.com/java/web/article.php/10935_3830886_1/)</listitem>
269 <listitem>Spring JDBC Pagination Tutorial (http://www.codefutures.com/tutorials/spring-pagination/)</listitem> 357 <listitem>Spring JDBC Pagination Tutorial (http://www.codefutures.com/tutorials/spring-pagination/)</listitem>
270 - <listitem>PrimeFaces DataTable - Lazy Loading (http://www.primefaces.org/showcase/ui/datatableLazy.jsf)</listitem> 358 + <listitem>PrimeFaces DataTable - Lazy Loading (http://www.primefaces.org/showcase/ui/datatableLazy.jsf)</listitem>
271 </itemizedlist> 359 </itemizedlist>
272 </section> 360 </section>
273 -  
274 -</chapter> 361 + -->
  362 +
documentation/reference/pt-BR/properties.xml 0 → 100644
@@ -0,0 +1,188 @@ @@ -0,0 +1,188 @@
  1 +<?xml version='1.0' encoding="utf-8"?>
  2 +<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3 + "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [ ]>
  4 +<chapter id="properties">
  5 +
  6 + <title>Demoiselle Properties</title>
  7 +
  8 + <para>
  9 + Em um projeto com o <emphasis>Demoiselle Framework</emphasis>, algumas propriedades e configurações
  10 + do <emphasis>Framework</emphasis> podem ser ajustadas no arquivo <literal>demoiselle.properties</literal>.
  11 + Além disso, a partir da versão 2.3.0 também é nesse arquivo que devem ser definidas as estratégias de
  12 + <emphasis>Transação</emphasis>, <emphasis>Autorização</emphasis> e <emphasis>Autenticação</emphasis>.
  13 + </para>
  14 + <para>
  15 + A seguir listamos as propriedades e configurações do <emphasis>Demoiselle Framework</emphasis> que o usuário pode modificar,
  16 + acompanhados de alguns exemplos ilustrativos. Também mostraremos como escolher as estratégias para
  17 + <emphasis>Transação</emphasis>, <emphasis>Autorização</emphasis> e <emphasis>Autenticação</emphasis>, oferecidas pelo
  18 + <emphasis>Demoiselle</emphasis>.
  19 + </para>
  20 +
  21 + <section>
  22 + <title>Configurações do Core</title>
  23 + <para>
  24 + <itemizedlist>
  25 + <listitem>
  26 + <para>
  27 + <literal>frameworkdemoiselle.pagination.page.size</literal> - Configura o número de linhas que será
  28 + exibido na grade de uma página. Por padrão, esse número é 10.
  29 + </para>
  30 + <para>
  31 + Exemplo de configuração: <literal>frameworkdemoiselle.pagination.page.size = 15</literal>, ajusta em 15
  32 + a quantidade de linhas em uma grade
  33 + </para>
  34 + </listitem>
  35 + <listitem>
  36 + <para>
  37 + <literal>frameworkdemoiselle.pagination.max.page.links</literal> - Configura a quantidade de links que
  38 + será exibido em uma página. Por padrão, esse valor é 5.
  39 + </para>
  40 + <para>
  41 + Exemplo de configuração: <literal>frameworkdemoiselle.pagination.max.page.links = 20</literal>, configura em 20
  42 + o número de links que podem ser exibidos em uma página.
  43 + </para>
  44 + </listitem>
  45 + <listitem>
  46 + <para>
  47 + <literal>frameworkdemoiselle.security.enabled</literal> - Configura a habilitação das funcionalidades do
  48 + <emphasis>Demoiselle</emphasis> relacionadas a segurança (como autenticação de usuário e verificação de
  49 + permissão de acesso à recursos). Por padrão, essas funcionalidades ficam habilitadas.
  50 + </para>
  51 + <para>
  52 + Exemplo de configuração: <literal>frameworkdemoiselle.security.enabled = false</literal>, desabilita as
  53 + funcionalidades de segurança do <emphasis>Demoiselle</emphasis>.
  54 + </para>
  55 + </listitem>
  56 + </itemizedlist>
  57 + </para>
  58 + </section>
  59 +
  60 + <section>
  61 + <title>Configurações da extensão JSF</title>
  62 + <para>
  63 + <itemizedlist>
  64 + <listitem>
  65 + <para>
  66 + <literal>frameworkdemoiselle.security.login.page</literal> - Configura a página de login. Por padrão, a página
  67 + configurada é <emphasis>“/login”</emphasis>.
  68 + </para>
  69 + <para>
  70 + Exemplo de configuração: <literal>frameworkdemoiselle.security.login.page = “/inicial”</literal>, configura a
  71 + página <emphasis>“/inicial”</emphasis> como a página de login.
  72 + </para>
  73 + </listitem>
  74 +
  75 + <listitem>
  76 + <para>
  77 + <literal>frameworkdemoiselle.security.redirect.after.login</literal> - Configura a página que será acessada após
  78 + o login. Por padrão, a página configurada é <emphasis>“/index”</emphasis>.
  79 + </para>
  80 + <para>
  81 + Exemplo de configuração: <literal>frameworkdemoiselle.security.redirect.after.login = "/menu"</literal>, configura
  82 + a página <emphasis>“/menu”</emphasis> para ser acessada no redirecionamento após o login do usuário.
  83 + </para>
  84 + </listitem>
  85 +
  86 + <listitem>
  87 + <para>
  88 + <literal>frameworkdemoiselle.security.redirect.after.logout</literal> - Configura a página para a qual a aplicação
  89 + será direcionada após o logout do usuário. Por padrão, a página configurada é <emphasis>“/login”</emphasis>.
  90 + </para>
  91 + <para>
  92 + Exemplo de configuração: <literal>frameworkdemoiselle.security.redirect.after.logout = "/index"</literal>, configura
  93 + a página "/index" para ser acessada no redirecionamento após o logout do usuário.
  94 + </para>
  95 + </listitem>
  96 +
  97 + <listitem>
  98 + <para>
  99 + <literal>frameworkdemoiselle.security.redirect.enebled</literal> - Configura a habilitação do redirecionamento da página
  100 + após <emphasis>login</emphasis> e <emphasis>logout</emphasis>. Por padrão, o valor dessa propriedade é <emphasis>true</emphasis>.
  101 + </para>
  102 + <para>
  103 + Exemplo de configuração: <literal>frameworkdemoiselle.security.redirect.enebled = false</literal>, desabilita os
  104 + redirecionamentos de páginas após <emphasis>login</emphasis> e <emphasis>logout</emphasis>.
  105 + </para>
  106 + </listitem>
  107 +
  108 + <listitem>
  109 + <para>
  110 + <literal>frameworkdemoiselle.handle.application.exception</literal> - Define se a extensão vai capturar ou não alguma exceção
  111 + lançada pela aplicação. Por padrão, essa configuração vem marcada como “true”, que diz para a extensão capturar a exceção.
  112 + </para>
  113 + <para>
  114 + Exemplo de configuração: <emphasis>frameworkdemoiselle.handle.application.exception = false</emphasis>, desabilita a captura
  115 + de exceções lançadas pela aplicação.
  116 + </para>
  117 + </listitem>
  118 +
  119 + <listitem>
  120 + <para>
  121 + <literal>frameworkdemoiselle.handle.aplication.exception.page</literal> - Configura a página para a qual a aplicação será
  122 + direcionada em caso de exceção. Por padrão, a página configurada é <emphasis>“/application_error”</emphasis>.
  123 + </para>
  124 + <para>
  125 + Exemplo de configuração: <emphasis>framework.handle.aplication.exception.page = “/exception_x_page”</emphasis>, redireciona a
  126 + aplicação para a página <emphasis>/exception_x_page</emphasis> caso ocorra alguma exceção.
  127 + </para>
  128 + </listitem>
  129 + </itemizedlist>
  130 + </para>
  131 + </section>
  132 +
  133 + <section>
  134 + <title>Configurações da Extensão JPA</title>
  135 + <para>
  136 + <itemizedlist>
  137 + <listitem>
  138 + <para>
  139 + <literal>frameworkdemoiselle.persistence.unit.name</literal> - Quando é definida mais de uma unidade de persitencia
  140 + no arquivo <literal>persistence.xml</literal>, muitas vezes é conveniente escolher uma unidade padrão, ao invés de
  141 + definir as unidades individualmente em cada <emphasis>Entity Manager</emphasis>. Esse parametro é utilizado para
  142 + indicar qual é a unidade de persistência que deve ser utilizada quando no <emphasis>Entity Manager</emphasis> não
  143 + houver essa definição.
  144 + </para>
  145 + <para>
  146 + Exemplo de configuração: <literal>frameworkdemoiselle.persistence.unit.name = database1-ds</literal>, configura a
  147 + unidade de persistencia <literal>database1-ds</literal> como padrão da aplicação.
  148 + </para>
  149 + </listitem>
  150 + </itemizedlist>
  151 + </para>
  152 + </section>
  153 +
  154 + <section>
  155 + <title>Escolhendo Estratégias</title>
  156 + <para>
  157 + Para escolher as estratégias de <emphasis>Transação</emphasis>, <emphasis>Autorização</emphasis> e <emphasis>Autenticação</emphasis>
  158 + devem ser configuradas as propriedades: <literal>frameworkdemoiselle.transaction.class</literal>,
  159 + <literal>frameworkdemoiselle.security.authorizer.class</literal> e <literal>frameworkdemoiselle.security.authenticator.class</literal>
  160 + , respectivamente.
  161 + </para>
  162 + <para>
  163 + Para utilizar as estratégias fornecidas pelo próprio <emphasis>Framework Demoiselle</emphasis>, você deve configurar essas
  164 + propriedades da seguinte forma:
  165 + <itemizedlist>
  166 + <listitem>
  167 + <para>
  168 + <literal>frameworkdemoiselle.transaction.class = br.gov.frameworkdemoiselle.transaction.JPATransaction</literal>,
  169 + para transações <emphasis>JPA</emphasis>, e <literal>frameworkdemoiselle.transaction.class =
  170 + br.gov.frameworkdemoiselle.transaction.JTATransaction</literal>, para transações <emphasis>JTA</emphasis>;
  171 + </para>
  172 + </listitem>
  173 + <listitem>
  174 + <para>
  175 + <literal>frameworkdemoiselle.security.authorizer.class = br.gov.serpro.inscricao.security.Autorizador</literal>;
  176 + </para>
  177 + </listitem>
  178 + <listitem>
  179 + <para>
  180 + <literal>frameworkdemoiselle.security.authenticator.class = br.gov.serpro.inscricao.security.Autenticador</literal>.
  181 + </para>
  182 + </listitem>
  183 + </itemizedlist>
  184 + As instruções para você construir e utilizar sua própria estratégia estãodescritas nos capítulos <link linkend="transacao">Transação</link>
  185 + e <link linkend="security">Segurança</link>.
  186 + </para>
  187 + </section>
  188 +</chapter>
documentation/reference/pt-BR/security.xml
@@ -18,6 +18,26 @@ @@ -18,6 +18,26 @@
18 </para> 18 </para>
19 19
20 <section> 20 <section>
  21 + <title>Configurando</title>
  22 + <para>
  23 + Para um correto funcionamento do Demoiselle é necessário inserir od interceptadores de segurança no arquivo <filename>src/main/WEB-INF/beans.xml</filename>.
  24 + </para>
  25 + <programlisting role="XML">
  26 + <![CDATA[
  27 + <beans xmlns="http://java.sun.com/xml/ns/javaee"
  28 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  29 + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  30 + http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
  31 + <interceptors>
  32 + <class>br.gov.frameworkdemoiselle.internal.interceptor.RequiredPermissionInterceptor</class>
  33 + <class>br.gov.frameworkdemoiselle.internal.interceptor.RequiredRoleInterceptor</class>
  34 + </interceptors>
  35 + </beans>
  36 + ]]>
  37 + </programlisting>
  38 + </section>
  39 +
  40 + <section>
21 <title>Autenticação</title> 41 <title>Autenticação</title>
22 <para> 42 <para>
23 O mecanismo de autenticação busca verificar a identidade do usuário de um sistema. A forma mais conhecida, e comum, 43 O mecanismo de autenticação busca verificar a identidade do usuário de um sistema. A forma mais conhecida, e comum,
@@ -201,20 +221,12 @@ public class MeuAuthorizer implements Authorizer { @@ -201,20 +221,12 @@ public class MeuAuthorizer implements Authorizer {
201 221
202 }]]></programlisting> 222 }]]></programlisting>
203 <para> 223 <para>
204 - Feito isso deve-se definir no arquivo META-INF/beans.xml, as classes criadas: 224 + Feito isso deve-se definir no arquivo <filename>demoiselle.properties</filename>, as classes criadas:
205 </para> 225 </para>
206 - <programlisting role="XML"><![CDATA[<?xml version="1.0"?>  
207 -<beans xmlns="http://java.sun.com/xml/ns/javaee"  
208 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
209 - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  
210 - http://java.sun.com/xml/ns/javaee/beans_1_1.xsd">  
211 -  
212 - <alternatives>  
213 - <class>projeto.MeuAuthenticator</class>  
214 - <class>projeto.MeuAuthorizer</class>  
215 - </alternatives>  
216 -  
217 -</beans>]]></programlisting> 226 + <programlisting>
  227 + frameworkdemoiselle.security.authenticator.class=projeto.MeuAuthenticator
  228 + frameworkdemoiselle.security.authorizer.class=projeto.MeuAuthorizer
  229 + </programlisting>
218 <para> 230 <para>
219 À partir desse momento, a aplicação já possui uma implementação de segurança definida. 231 À partir desse momento, a aplicação já possui uma implementação de segurança definida.
220 </para> 232 </para>
documentation/reference/pt-BR/transacao.xml
@@ -22,6 +22,25 @@ @@ -22,6 +22,25 @@
22 Neste capítulo apresentaremos para você como usar a nossa solução de controle de transação, as estratégias 22 Neste capítulo apresentaremos para você como usar a nossa solução de controle de transação, as estratégias
23 prontas que oferecemos e a criação de sua própria estratégia. 23 prontas que oferecemos e a criação de sua própria estratégia.
24 </para> 24 </para>
  25 +
  26 + <section>
  27 + <title>Configurando</title>
  28 + <para>
  29 + Para um correto funcionamento do Demoiselle é necessário inserir o interceptador de transação no arquivo <filename>src/main/WEB-INF/beans.xml</filename>.
  30 + </para>
  31 + <programlisting role="XML">
  32 + <![CDATA[
  33 + <beans xmlns="http://java.sun.com/xml/ns/javaee"
  34 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  35 + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  36 + http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
  37 + <interceptors>
  38 + <class>br.gov.frameworkdemoiselle.internal.interceptor.TransactionalInterceptor</class>
  39 + </interceptors>
  40 + </beans>
  41 + ]]>
  42 + </programlisting>
  43 + </section>
25 44
26 <section> 45 <section>
27 <title>Métodos transacionais</title> 46 <title>Métodos transacionais</title>
@@ -99,19 +118,11 @@ public class AbacaxiException { @@ -99,19 +118,11 @@ public class AbacaxiException {
99 </para> 118 </para>
100 <para> 119 <para>
101 A transação JPA é simples de configurar e não exige nenhum recurso externo à sua aplicação. 120 A transação JPA é simples de configurar e não exige nenhum recurso externo à sua aplicação.
102 - Basta definir no arquivo <filename>META-INF/beans.xml</filename> a seguinte configuração: 121 + Basta definir no arquivo <filename>demoiselle.properties</filename> a seguinte configuração:
103 </para> 122 </para>
104 - <programlisting role="XML"><![CDATA[<?xml version="1.0"?>  
105 -<beans xmlns="http://java.sun.com/xml/ns/javaee"  
106 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
107 - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  
108 - http://java.sun.com/xml/ns/javaee/beans_1_1.xsd">  
109 -  
110 - <alternatives>  
111 - <class>br.gov.frameworkdemoiselle.transaction.JPATransaction</class>  
112 - </alternatives>  
113 -  
114 -</beans>]]></programlisting> 123 + <programlisting>
  124 + frameworkdemoiselle.transaction.class=br.gov.frameworkdemoiselle.transaction.JPATransaction
  125 + </programlisting>
115 <tip><para> Caso não esteja utilizando o arquétipo JSF-JPA fornecidos pelo Demoiselle, confira se a dependência para a 126 <tip><para> Caso não esteja utilizando o arquétipo JSF-JPA fornecidos pelo Demoiselle, confira se a dependência para a
116 extensão está indicada corretamente no arquivo POM.XML.</para> 127 extensão está indicada corretamente no arquivo POM.XML.</para>
117 <programlisting role="XML"><![CDATA[<dependency> 128 <programlisting role="XML"><![CDATA[<dependency>
@@ -132,23 +143,13 @@ public class AbacaxiException { @@ -132,23 +143,13 @@ public class AbacaxiException {
132 <para> 143 <para>
133 A estratégia JTA não serve apenas para persistência em banco de dados, serve também para integrar com 144 A estratégia JTA não serve apenas para persistência em banco de dados, serve também para integrar com
134 tecnologias que façam acesso ao contexto JTA, como é o caso do EJB. Para ativar esta estratégia defina no 145 tecnologias que façam acesso ao contexto JTA, como é o caso do EJB. Para ativar esta estratégia defina no
135 - arquivo <filename>META-INF/beans.xml</filename> a seguinte configuração: 146 + arquivo <filename>demoiselle.properties</filename> a seguinte configuração:
136 </para> 147 </para>
137 - <programlisting role="XML"><![CDATA[<?xml version="1.0"?>  
138 -<beans xmlns="http://java.sun.com/xml/ns/javaee"  
139 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
140 - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  
141 - http://java.sun.com/xml/ns/javaee/beans_1_1.xsd">  
142 -  
143 - <alternatives>  
144 - <class>br.gov.frameworkdemoiselle.transaction.JTATransaction</class>  
145 - </alternatives>  
146 -  
147 -</beans>]]></programlisting> 148 + <programlisting>frameworkdemoiselle.transaction.class=br.gov.frameworkdemoiselle.transaction.JTATransaction</programlisting>
148 <para> 149 <para>
149 Feito isto, o controle transacional será delegado para a transação acessível via JNDI com o nome 150 Feito isto, o controle transacional será delegado para a transação acessível via JNDI com o nome
150 <literal>UserTransaction</literal>. A estratégia acessa o objeto da seguinte maneira: 151 <literal>UserTransaction</literal>. A estratégia acessa o objeto da seguinte maneira:
151 - <literal>context.lookup("UserTransaction")</literal>. Portanto, para você utilizar esta estratégia, 152 + <literal>Beans.getReference(UserTransaction.class)</literal>. Portanto, para você utilizar esta estratégia,
152 você precisa de um container JEE ou de um servidor JTA qualquer. 153 você precisa de um container JEE ou de um servidor JTA qualquer.
153 </para> 154 </para>
154 <para> 155 <para>
@@ -156,18 +157,20 @@ public class AbacaxiException { @@ -156,18 +157,20 @@ public class AbacaxiException {
156 JTA gerenciada. Veja um exemplo utilizando o servidor de aplicações JBoss-AS6 e com o provider Hibernate (embutido no JBoss-AS) como implementação JPA: 157 JTA gerenciada. Veja um exemplo utilizando o servidor de aplicações JBoss-AS6 e com o provider Hibernate (embutido no JBoss-AS) como implementação JPA:
157 </para> 158 </para>
158 <programlisting role="XML"><![CDATA[<?xml version="1.0" encoding="UTF-8"?> 159 <programlisting role="XML"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
159 -<persistence version="2.0"  
160 - xmlns="http://java.sun.com/xml/ns/persistence" 160 +<persistence version="2.0"
  161 + xmlns="http://java.sun.com/xml/ns/persistence"
161 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 162 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
162 - xsi:schemaLocation="http://java.sun.com/xml/ns/persistence  
163 - http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> 163 + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
  164 + http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
164 165
165 - <persistence-unit name="contactlist-ds">  
166 - <jta-data-source>java:/DefaultDS</jta-data-source> 166 + <persistence-unit name="bookmark-ds" transaction-type="JTA">
  167 + <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
167 <properties> 168 <properties>
168 - <property name="hibernate.transaction.factory_class"  
169 - value="org.hibernate.transaction.JTATransactionFactory" />  
170 - <property name="jta.UserTransaction" value="UserTransaction" /> 169 + <property name="hibernate.show_sql" value="true" />
  170 + <property name="hibernate.format_sql" value="false" />
  171 + <property name="hibernate.hbm2ddl.auto" value="update" />
  172 + <property name="hibernate.transaction.jta.platform"
  173 + value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
171 </properties> 174 </properties>
172 </persistence-unit> 175 </persistence-unit>
173 </persistence>]]></programlisting> 176 </persistence>]]></programlisting>
@@ -221,19 +224,11 @@ public class MegaTransaction implements Transaction { @@ -221,19 +224,11 @@ public class MegaTransaction implements Transaction {
221 } 224 }
222 ]]></programlisting> 225 ]]></programlisting>
223 <para> 226 <para>
224 - Basta agora definir no arquivo <filename>META-INF/beans.xml</filename> a sua estratégia: 227 + Basta agora definir no arquivo <filename>demoiselle.properties</filename> a sua estratégia:
225 </para> 228 </para>
226 - <programlisting role="XML"><![CDATA[<?xml version="1.0"?>  
227 -<beans xmlns="http://java.sun.com/xml/ns/javaee"  
228 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
229 - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  
230 - http://java.sun.com/xml/ns/javaee/beans_1_1.xsd">  
231 -  
232 - <alternatives>  
233 - <class>projeto.MegaTransaction</class>  
234 - </alternatives>  
235 -  
236 -</beans>]]></programlisting> 229 + <programlisting>
  230 + frameworkdemoiselle.transaction.class=projeto.MegaTransaction
  231 + </programlisting>
237 </section> 232 </section>
238 233
239 </chapter> 234 </chapter>
impl/core/pom.xml
@@ -44,20 +44,40 @@ @@ -44,20 +44,40 @@
44 <parent> 44 <parent>
45 <groupId>br.gov.frameworkdemoiselle</groupId> 45 <groupId>br.gov.frameworkdemoiselle</groupId>
46 <artifactId>demoiselle-framework-parent</artifactId> 46 <artifactId>demoiselle-framework-parent</artifactId>
47 - <version>2.2.3-SNAPSHOT</version>  
48 - <relativePath>../../parent/framework/pom.xml</relativePath> 47 + <version>2.3.0-RC2-SNAPSHOT</version>
  48 + <relativePath>../../parent/framework</relativePath>
49 </parent> 49 </parent>
50 50
51 - <organization>  
52 - <name>Serpro</name>  
53 - <url>http://www.serpro.gov.br</url>  
54 - </organization>  
55 -  
56 - <name>Core</name> 51 + <name>Demoiselle Framework Core</name>
57 <description> 52 <description>
58 Contém funcionalidades comuns a todos os projetos e extensões do framework de forma independente de 53 Contém funcionalidades comuns a todos os projetos e extensões do framework de forma independente de
59 camadas de apresentação e persistência. 54 camadas de apresentação e persistência.
60 </description> 55 </description>
  56 + <url>http://www.frameworkdemoiselle.gov.br</url>
  57 +
  58 + <licenses>
  59 + <license>
  60 + <name>GNU Lesser General Public License, Version 3</name>
  61 + <url>http://www.gnu.org/licenses/lgpl-3.0.txt</url>
  62 + </license>
  63 + </licenses>
  64 +
  65 + <organization>
  66 + <name>SERPRO - Serviço Federal de Processamento de Dados</name>
  67 + <url>http://www.serpro.gov.br</url>
  68 + </organization>
  69 +
  70 + <dependencyManagement>
  71 + <dependencies>
  72 + <dependency>
  73 + <groupId>br.gov.frameworkdemoiselle</groupId>
  74 + <artifactId>demoiselle-framework-bom</artifactId>
  75 + <version>2.3.0-RC2-SNAPSHOT</version>
  76 + <type>pom</type>
  77 + <scope>import</scope>
  78 + </dependency>
  79 + </dependencies>
  80 + </dependencyManagement>
61 81
62 <build> 82 <build>
63 <plugins> 83 <plugins>
@@ -94,6 +114,11 @@ @@ -94,6 +114,11 @@
94 <artifactId>slf4j-api</artifactId> 114 <artifactId>slf4j-api</artifactId>
95 </dependency> 115 </dependency>
96 <dependency> 116 <dependency>
  117 + <groupId>org.javassist</groupId>
  118 + <artifactId>javassist</artifactId>
  119 + </dependency>
  120 +
  121 + <dependency>
97 <groupId>commons-configuration</groupId> 122 <groupId>commons-configuration</groupId>
98 <artifactId>commons-configuration</artifactId> 123 <artifactId>commons-configuration</artifactId>
99 <exclusions> 124 <exclusions>
@@ -155,9 +180,9 @@ @@ -155,9 +180,9 @@
155 180
156 <repositories> 181 <repositories>
157 <repository> 182 <repository>
158 - <id>demoiselle.sourceforge.net</id>  
159 - <name>Demoiselle Maven Repository</name>  
160 - <url>http://demoiselle.sourceforge.net/repository/release</url> 183 + <id>sonatype-nexus-snapshots</id>
  184 + <name>Sonatype Nexus Snapshots</name>
  185 + <url>https://oss.sonatype.org/content/repositories/snapshots</url>
161 </repository> 186 </repository>
162 </repositories> 187 </repositories>
163 </project> 188 </project>
impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Priority.java 0 → 100644
@@ -0,0 +1,67 @@ @@ -0,0 +1,67 @@
  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.annotation;
  38 +
  39 +import static java.lang.annotation.ElementType.METHOD;
  40 +import static java.lang.annotation.ElementType.TYPE;
  41 +import static java.lang.annotation.RetentionPolicy.RUNTIME;
  42 +
  43 +import java.lang.annotation.Retention;
  44 +import java.lang.annotation.Target;
  45 +
  46 +/**
  47 + * @author SERPRO
  48 + */
  49 +@Target({ TYPE, METHOD })
  50 +@Retention(RUNTIME)
  51 +public @interface Priority {
  52 +
  53 + /**
  54 + * Most important priority value.
  55 + */
  56 + public static int MAX_PRIORITY = Integer.MIN_VALUE;
  57 +
  58 + /**
  59 + * Less important priority value.
  60 + */
  61 + public static int MIN_PRIORITY = Integer.MAX_VALUE;
  62 +
  63 + /**
  64 + * An integer value defines the priority order.
  65 + */
  66 + int value();
  67 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Shutdown.java
@@ -1,91 +0,0 @@ @@ -1,91 +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.annotation;  
38 -  
39 -import static java.lang.annotation.ElementType.METHOD;  
40 -import static java.lang.annotation.RetentionPolicy.RUNTIME;  
41 -  
42 -import java.lang.annotation.Retention;  
43 -import java.lang.annotation.Target;  
44 -  
45 -/**  
46 - * Identifies a method eligible to be executed automatically during <b>application finalization</b>.  
47 - * <p>  
48 - * Take a look at the following usage sample:  
49 - * <p>  
50 - * <blockquote>  
51 - *  
52 - * <pre>  
53 - * public class Finalizer {  
54 - *  
55 - * &#064;Shutdown(priority = 5)  
56 - * public void finalize() {  
57 - * ...  
58 - * }  
59 - * }  
60 - *  
61 - *  
62 - *  
63 - * </pre>  
64 - *  
65 - * </blockquote>  
66 - * <p>  
67 - * The <code>@Shutdown</code> annotation allows an integer value to be defined, which stands for the method execution  
68 - * priority when several finalizer classes are available in the application.  
69 - *  
70 - * @author SERPRO  
71 - */  
72 -@Target(METHOD)  
73 -@Retention(RUNTIME)  
74 -public @interface Shutdown {  
75 -  
76 - /**  
77 - * Most important priority value.  
78 - */  
79 - public static int MAX_PRIORITY = Integer.MIN_VALUE;  
80 -  
81 - /**  
82 - * Less important priority value.  
83 - */  
84 - public static int MIN_PRIORITY = Integer.MAX_VALUE;  
85 -  
86 - /**  
87 - * An integer value defines method execution order (i.e., priority).  
88 - */  
89 - int priority() default MIN_PRIORITY;  
90 -  
91 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Startup.java
@@ -1,90 +0,0 @@ @@ -1,90 +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.annotation;  
38 -  
39 -import static java.lang.annotation.ElementType.METHOD;  
40 -import static java.lang.annotation.RetentionPolicy.RUNTIME;  
41 -  
42 -import java.lang.annotation.Retention;  
43 -import java.lang.annotation.Target;  
44 -  
45 -/**  
46 - * Identifies a method eligible to be executed automatically during <b>application initialization</b>.  
47 - * <p>  
48 - * Take a look at the following usage sample:  
49 - * <p>  
50 - * <blockquote>  
51 - *  
52 - * <pre>  
53 - * public class Initializer {  
54 - *  
55 - * &#064;Startup(priority = 1)  
56 - * public void initialize() {  
57 - * ...  
58 - * }  
59 - * }  
60 - *  
61 - *  
62 - * </pre>  
63 - *  
64 - * </blockquote>  
65 - * <p>  
66 - * The <code>@Startup</code> annotation allows an integer value to be defined, which stands for the method execution  
67 - * priority when several initializer classes are available in the application.  
68 - *  
69 - * @author SERPRO  
70 - */  
71 -@Target(METHOD)  
72 -@Retention(RUNTIME)  
73 -public @interface Startup {  
74 -  
75 - /**  
76 - * Most important priority value.  
77 - */  
78 - public static int MAX_PRIORITY = Integer.MIN_VALUE;  
79 -  
80 - /**  
81 - * Less important priority value.  
82 - */  
83 - public static int MIN_PRIORITY = Integer.MAX_VALUE;  
84 -  
85 - /**  
86 - * An integer value defines method execution order (i.e., priority).  
87 - */  
88 - int priority() default MIN_PRIORITY;  
89 -  
90 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/configuration/Configuration.java
@@ -44,7 +44,7 @@ import java.lang.annotation.Retention; @@ -44,7 +44,7 @@ import java.lang.annotation.Retention;
44 import java.lang.annotation.Target; 44 import java.lang.annotation.Target;
45 45
46 import javax.enterprise.inject.Stereotype; 46 import javax.enterprise.inject.Stereotype;
47 -import javax.inject.Singleton; 47 +import javax.enterprise.util.Nonbinding;
48 48
49 /** 49 /**
50 * Identifies a <b>configuration class</b>, that is, a structure reserved to store configuration values retrieved from a 50 * Identifies a <b>configuration class</b>, that is, a structure reserved to store configuration values retrieved from a
@@ -61,7 +61,7 @@ import javax.inject.Singleton; @@ -61,7 +61,7 @@ import javax.inject.Singleton;
61 * 61 *
62 * @author SERPRO 62 * @author SERPRO
63 */ 63 */
64 -@Singleton 64 +// @Singleton
65 @Stereotype 65 @Stereotype
66 @Inherited 66 @Inherited
67 @Target(TYPE) 67 @Target(TYPE)
@@ -80,6 +80,7 @@ public @interface Configuration { @@ -80,6 +80,7 @@ public @interface Configuration {
80 * 80 *
81 * @return ConfigType 81 * @return ConfigType
82 */ 82 */
  83 + @Nonbinding
83 ConfigType type() default ConfigType.PROPERTIES; 84 ConfigType type() default ConfigType.PROPERTIES;
84 85
85 /** 86 /**
@@ -91,6 +92,7 @@ public @interface Configuration { @@ -91,6 +92,7 @@ public @interface Configuration {
91 * 92 *
92 * @return String 93 * @return String
93 */ 94 */
  95 + @Nonbinding
94 String prefix() default ""; 96 String prefix() default "";
95 97
96 /** 98 /**
@@ -104,6 +106,7 @@ public @interface Configuration { @@ -104,6 +106,7 @@ public @interface Configuration {
104 * 106 *
105 * @return String 107 * @return String
106 */ 108 */
  109 + @Nonbinding
107 String resource() default DEFAULT_RESOURCE; 110 String resource() default DEFAULT_RESOURCE;
108 111
109 } 112 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/configuration/ConfigurationException.java
@@ -68,5 +68,4 @@ public class ConfigurationException extends DemoiselleException { @@ -68,5 +68,4 @@ public class ConfigurationException extends DemoiselleException {
68 public ConfigurationException(String message, Throwable cause) { 68 public ConfigurationException(String message, Throwable cause) {
69 super(message, cause); 69 super(message, cause);
70 } 70 }
71 -  
72 } 71 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractBootstrap.java
@@ -1,79 +0,0 @@ @@ -1,79 +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.bootstrap;  
38 -  
39 -import java.util.Locale;  
40 -  
41 -import javax.enterprise.inject.spi.AfterBeanDiscovery;  
42 -import javax.enterprise.inject.spi.Extension;  
43 -  
44 -import org.slf4j.Logger;  
45 -  
46 -import br.gov.frameworkdemoiselle.internal.context.Contexts;  
47 -import br.gov.frameworkdemoiselle.internal.context.CustomContext;  
48 -import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;  
49 -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;  
50 -import br.gov.frameworkdemoiselle.util.ResourceBundle;  
51 -  
52 -public abstract class AbstractBootstrap implements Extension {  
53 -  
54 - private static ResourceBundleProducer bundleFactory = new ResourceBundleProducer();  
55 -  
56 - protected static ResourceBundle getBundle() {  
57 - return getBundle("demoiselle-core-bundle");  
58 - }  
59 -  
60 - protected static ResourceBundle getBundle(String baseName) {  
61 - return bundleFactory.create(baseName, Locale.getDefault());  
62 - }  
63 -  
64 - protected static Logger getLogger() {  
65 - return LoggerProducer.create(AbstractBootstrap.class);  
66 - }  
67 -  
68 - protected static void addContext(final CustomContext context, final AfterBeanDiscovery event) {  
69 - Contexts.add(context, event);  
70 - getLogger()  
71 - .trace(getBundle().getString("custom-context-was-registered", context.getScope().getCanonicalName()));  
72 - }  
73 -  
74 - protected static void disableContext(final CustomContext context) {  
75 - Contexts.remove(context);  
76 - getLogger()  
77 - .trace(getBundle().getString("custom-context-was-registered", context.getScope().getCanonicalName()));  
78 - }  
79 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractLifecycleBootstrap.java 0 → 100644
@@ -0,0 +1,175 @@ @@ -0,0 +1,175 @@
  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 java.lang.annotation.Annotation;
  40 +import java.util.ArrayList;
  41 +import java.util.Collections;
  42 +import java.util.Iterator;
  43 +import java.util.List;
  44 +import java.util.Locale;
  45 +
  46 +import javax.enterprise.context.ConversationScoped;
  47 +import javax.enterprise.context.RequestScoped;
  48 +import javax.enterprise.context.SessionScoped;
  49 +import javax.enterprise.event.Observes;
  50 +import javax.enterprise.inject.spi.AfterBeanDiscovery;
  51 +import javax.enterprise.inject.spi.AnnotatedMethod;
  52 +import javax.enterprise.inject.spi.AnnotatedType;
  53 +import javax.enterprise.inject.spi.Extension;
  54 +import javax.enterprise.inject.spi.ProcessAnnotatedType;
  55 +
  56 +import org.slf4j.Logger;
  57 +
  58 +import br.gov.frameworkdemoiselle.DemoiselleException;
  59 +import br.gov.frameworkdemoiselle.annotation.ViewScoped;
  60 +import br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader;
  61 +import br.gov.frameworkdemoiselle.internal.context.Contexts;
  62 +import br.gov.frameworkdemoiselle.internal.context.CustomContext;
  63 +import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext;
  64 +import br.gov.frameworkdemoiselle.internal.implementation.AnnotatedMethodProcessor;
  65 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
  66 +import br.gov.frameworkdemoiselle.util.Reflections;
  67 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
  68 +
  69 +public abstract class AbstractLifecycleBootstrap<A extends Annotation> implements Extension {
  70 +
  71 + private Class<A> annotationClass;
  72 +
  73 + @SuppressWarnings("rawtypes")
  74 + private List<AnnotatedMethodProcessor> processors = Collections
  75 + .synchronizedList(new ArrayList<AnnotatedMethodProcessor>());
  76 +
  77 + private List<CustomContext> tempContexts = new ArrayList<CustomContext>();
  78 +
  79 + private AfterBeanDiscovery afterBeanDiscoveryEvent;
  80 +
  81 + private boolean registered = false;
  82 +
  83 + private ResourceBundle bundle;
  84 +
  85 + protected abstract Logger getLogger();
  86 +
  87 + protected ResourceBundle getBundle() {
  88 + if (this.bundle == null) {
  89 + this.bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault());
  90 + }
  91 +
  92 + return this.bundle;
  93 + }
  94 +
  95 + protected <T> AnnotatedMethodProcessor<T> newProcessorInstance(AnnotatedMethod<T> annotatedMethod) {
  96 + return new AnnotatedMethodProcessor<T>(annotatedMethod);
  97 + }
  98 +
  99 + protected Class<A> getAnnotationClass() {
  100 + if (this.annotationClass == null) {
  101 + this.annotationClass = Reflections.getGenericTypeArgument(this.getClass(), 0);
  102 + }
  103 +
  104 + return this.annotationClass;
  105 + }
  106 +
  107 + public <T> void processAnnotatedType(@Observes final ProcessAnnotatedType<T> event) {
  108 + final AnnotatedType<T> annotatedType = event.getAnnotatedType();
  109 +
  110 + for (AnnotatedMethod<?> am : annotatedType.getMethods()) {
  111 + if (am.isAnnotationPresent(getAnnotationClass())) {
  112 + @SuppressWarnings("unchecked")
  113 + AnnotatedMethod<T> annotatedMethod = (AnnotatedMethod<T>) am;
  114 + processors.add(newProcessorInstance(annotatedMethod));
  115 + }
  116 + }
  117 + }
  118 +
  119 + public void loadTempContexts(@Observes final AfterBeanDiscovery event) {
  120 + // Não registrar o contexto de aplicação pq ele já é registrado pela implementação do CDI
  121 + tempContexts.add(new ThreadLocalContext(ViewScoped.class));
  122 + tempContexts.add(new ThreadLocalContext(SessionScoped.class));
  123 + tempContexts.add(new ThreadLocalContext(ConversationScoped.class));
  124 + tempContexts.add(new ThreadLocalContext(RequestScoped.class));
  125 +
  126 + afterBeanDiscoveryEvent = event;
  127 + }
  128 +
  129 + @SuppressWarnings({ "unchecked", "rawtypes" })
  130 + protected synchronized void proccessEvent() {
  131 + getLogger().debug(getBundle().getString("executing-all", annotationClass.getSimpleName()));
  132 +
  133 + Collections.sort(processors);
  134 + Throwable failure = null;
  135 +
  136 + if (!registered) {
  137 + for (CustomContext tempContext : tempContexts) {
  138 + Contexts.add(tempContext, afterBeanDiscoveryEvent);
  139 + }
  140 +
  141 + registered = true;
  142 + }
  143 +
  144 + for (Iterator<AnnotatedMethodProcessor> iter = processors.iterator(); iter.hasNext();) {
  145 + AnnotatedMethodProcessor<?> processor = iter.next();
  146 +
  147 + try {
  148 + ClassLoader classLoader = ConfigurationLoader.getClassLoaderForClass(processor.getAnnotatedMethod()
  149 + .getDeclaringType().getJavaClass().getCanonicalName());
  150 +
  151 + if (Thread.currentThread().getContextClassLoader().equals(classLoader)) {
  152 + processor.process();
  153 + iter.remove();
  154 + }
  155 +
  156 + } catch (Throwable cause) {
  157 + failure = cause;
  158 + }
  159 + }
  160 +
  161 + if (processors.isEmpty()) {
  162 + unloadTempContexts();
  163 + }
  164 +
  165 + if (failure != null) {
  166 + throw new DemoiselleException(failure);
  167 + }
  168 + }
  169 +
  170 + private void unloadTempContexts() {
  171 + for (CustomContext tempContext : tempContexts) {
  172 + Contexts.remove(tempContext);
  173 + }
  174 + }
  175 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractStrategyBootstrap.java 0 → 100644
@@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
  1 +package br.gov.frameworkdemoiselle.internal.bootstrap;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.Collections;
  5 +import java.util.List;
  6 +
  7 +import javax.enterprise.event.Observes;
  8 +import javax.enterprise.inject.spi.AnnotatedType;
  9 +import javax.enterprise.inject.spi.Extension;
  10 +import javax.enterprise.inject.spi.ProcessAnnotatedType;
  11 +
  12 +import org.slf4j.Logger;
  13 +
  14 +import br.gov.frameworkdemoiselle.util.Reflections;
  15 +
  16 +public abstract class AbstractStrategyBootstrap<I> implements Extension {
  17 +
  18 + private Class<? extends I> strategyClass;
  19 +
  20 + private List<Class<? extends I>> cache;
  21 +
  22 + protected abstract Logger getLogger();
  23 +
  24 + protected Class<? extends I> getStrategyClass() {
  25 + if (this.strategyClass == null) {
  26 + this.strategyClass = Reflections.getGenericTypeArgument(this.getClass(), 0);
  27 + }
  28 +
  29 + return this.strategyClass;
  30 + }
  31 +
  32 + public List<Class<? extends I>> getCache() {
  33 + if (this.cache == null) {
  34 + this.cache = Collections.synchronizedList(new ArrayList<Class<? extends I>>());
  35 + }
  36 +
  37 + return this.cache;
  38 + }
  39 +
  40 + @SuppressWarnings("unchecked")
  41 + public <T> void processAnnotatedType(@Observes final ProcessAnnotatedType<T> event) {
  42 + final AnnotatedType<T> annotatedType = event.getAnnotatedType();
  43 +
  44 + if (Reflections.isOfType(annotatedType.getJavaClass(), this.getStrategyClass())) {
  45 + this.getCache().add((Class<I>) annotatedType.getJavaClass());
  46 + }
  47 + }
  48 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AuthenticatorBootstrap.java 0 → 100644
@@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
  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 org.slf4j.Logger;
  40 +
  41 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  42 +import br.gov.frameworkdemoiselle.security.Authenticator;
  43 +
  44 +public class AuthenticatorBootstrap extends AbstractStrategyBootstrap<Authenticator> {
  45 +
  46 + private Logger logger;
  47 +
  48 + @Override
  49 + protected Logger getLogger() {
  50 + if (logger == null) {
  51 + logger = LoggerProducer.create(AuthenticatorBootstrap.class);
  52 + }
  53 +
  54 + return logger;
  55 + }
  56 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AuthorizerBootstrap.java 0 → 100644
@@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
  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 org.slf4j.Logger;
  40 +
  41 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  42 +import br.gov.frameworkdemoiselle.security.Authorizer;
  43 +
  44 +public class AuthorizerBootstrap extends AbstractStrategyBootstrap<Authorizer> {
  45 +
  46 + private Logger logger;
  47 +
  48 + @Override
  49 + protected Logger getLogger() {
  50 + if (logger == null) {
  51 + logger = LoggerProducer.create(AuthorizerBootstrap.class);
  52 + }
  53 +
  54 + return logger;
  55 + }
  56 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ConfigurationBootstrap.java
@@ -40,56 +40,69 @@ import java.util.ArrayList; @@ -40,56 +40,69 @@ import java.util.ArrayList;
40 import java.util.Collections; 40 import java.util.Collections;
41 import java.util.List; 41 import java.util.List;
42 42
43 -import javax.enterprise.context.RequestScoped;  
44 -import javax.enterprise.context.SessionScoped; 43 +import javassist.ClassPool;
  44 +import javassist.CtClass;
  45 +import javassist.CtMethod;
  46 +import javassist.CtNewMethod;
  47 +import javassist.LoaderClassPath;
  48 +
45 import javax.enterprise.event.Observes; 49 import javax.enterprise.event.Observes;
46 import javax.enterprise.inject.spi.AfterBeanDiscovery; 50 import javax.enterprise.inject.spi.AfterBeanDiscovery;
47 -import javax.enterprise.inject.spi.AfterDeploymentValidation;  
48 import javax.enterprise.inject.spi.AnnotatedType; 51 import javax.enterprise.inject.spi.AnnotatedType;
49 import javax.enterprise.inject.spi.BeanManager; 52 import javax.enterprise.inject.spi.BeanManager;
  53 +import javax.enterprise.inject.spi.Extension;
50 import javax.enterprise.inject.spi.ProcessAnnotatedType; 54 import javax.enterprise.inject.spi.ProcessAnnotatedType;
51 55
52 import br.gov.frameworkdemoiselle.configuration.Configuration; 56 import br.gov.frameworkdemoiselle.configuration.Configuration;
53 -import br.gov.frameworkdemoiselle.configuration.ConfigurationException;  
54 -import br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader;  
55 -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext;  
56 -import br.gov.frameworkdemoiselle.util.Beans; 57 +import br.gov.frameworkdemoiselle.internal.implementation.ConfigurationImpl;
57 58
58 -/**  
59 - * @author SERPRO  
60 - */  
61 -public class ConfigurationBootstrap extends AbstractBootstrap { 59 +public class ConfigurationBootstrap implements Extension {
62 60
63 - private static List<AnnotatedType<?>> types = Collections.synchronizedList(new ArrayList<AnnotatedType<?>>()); 61 + private final List<Class<Object>> cache = Collections.synchronizedList(new ArrayList<Class<Object>>());
64 62
65 - private static final String MSG_PROCESSING = "bootstrap.configuration.processing"; 63 + public void processAnnotatedType(@Observes final ProcessAnnotatedType<Object> event) {
  64 + final AnnotatedType<Object> annotatedType = event.getAnnotatedType();
66 65
67 - private ThreadLocalContext c1; 66 + if (annotatedType.getJavaClass().isAnnotationPresent(Configuration.class)) {
  67 + cache.add(annotatedType.getJavaClass());
  68 + event.veto();
  69 + }
  70 + }
68 71
69 - private ThreadLocalContext c2; 72 + public void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager beanManager) throws Exception {
  73 + Class<Object> proxy;
70 74
71 - public <T> void detectAnnotation(@Observes final ProcessAnnotatedType<T> event, final BeanManager beanManager) {  
72 - if (event.getAnnotatedType().isAnnotationPresent(Configuration.class)) {  
73 - types.add(event.getAnnotatedType()); 75 + for (Class<Object> config : cache) {
  76 + proxy = createProxy(config);
  77 + event.addBean(new CustomBean(proxy, beanManager));
74 } 78 }
75 } 79 }
76 80
77 - public void loadTempContexts(@Observes final AfterBeanDiscovery event) {  
78 - c1 = new ThreadLocalContext(RequestScoped.class);  
79 - addContext(c1, event);  
80 - c2 = new ThreadLocalContext(SessionScoped.class);  
81 - addContext(c2, event);  
82 - } 81 + @SuppressWarnings("unchecked")
  82 + private Class<Object> createProxy(Class<Object> type) throws Exception {
  83 + String superClassName = type.getCanonicalName();
  84 + String chieldClassName = superClassName + "__DemoiselleProxy";
  85 +
  86 + ClassPool pool = ClassPool.getDefault();
  87 + CtClass ctChieldClass = pool.getOrNull(chieldClassName);
83 88
84 - public void processLoader(@Observes final AfterDeploymentValidation event)  
85 - throws ConfigurationException {  
86 - ConfigurationLoader configurationLoader = Beans.getReference(ConfigurationLoader.class);  
87 - for (AnnotatedType<?> type : types) {  
88 - getLogger().debug(getBundle().getString(MSG_PROCESSING, type.toString()));  
89 - configurationLoader.load(Beans.getReference(type.getJavaClass())); 89 + ClassLoader classLoader = type.getClassLoader();
  90 + if (ctChieldClass == null) {
  91 + pool.appendClassPath(new LoaderClassPath(classLoader));
  92 + CtClass ctSuperClass = pool.get(superClassName);
  93 +
  94 + ctChieldClass = pool.getAndRename(ConfigurationImpl.class.getCanonicalName(), chieldClassName);
  95 + ctChieldClass.setSuperclass(ctSuperClass);
  96 +
  97 + CtMethod ctChieldMethod;
  98 + for (CtMethod ctSuperMethod : ctSuperClass.getDeclaredMethods()) {
  99 + ctChieldMethod = CtNewMethod.delegator(ctSuperMethod, ctChieldClass);
  100 + ctChieldMethod.insertBefore("load(this);");
  101 +
  102 + ctChieldClass.addMethod(ctChieldMethod);
  103 + }
90 } 104 }
91 - disableContext(c1);  
92 - disableContext(c2);  
93 - }  
94 105
  106 + return ctChieldClass.toClass(classLoader, type.getProtectionDomain());
  107 + }
95 } 108 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CoreBootstrap.java
@@ -37,6 +37,7 @@ @@ -37,6 +37,7 @@
37 package br.gov.frameworkdemoiselle.internal.bootstrap; 37 package br.gov.frameworkdemoiselle.internal.bootstrap;
38 38
39 import java.util.HashMap; 39 import java.util.HashMap;
  40 +import java.util.Locale;
40 import java.util.Map; 41 import java.util.Map;
41 42
42 import javax.enterprise.event.Observes; 43 import javax.enterprise.event.Observes;
@@ -45,18 +46,41 @@ import javax.enterprise.inject.spi.AnnotatedType; @@ -45,18 +46,41 @@ import javax.enterprise.inject.spi.AnnotatedType;
45 import javax.enterprise.inject.spi.BeanManager; 46 import javax.enterprise.inject.spi.BeanManager;
46 import javax.enterprise.inject.spi.BeforeBeanDiscovery; 47 import javax.enterprise.inject.spi.BeforeBeanDiscovery;
47 import javax.enterprise.inject.spi.BeforeShutdown; 48 import javax.enterprise.inject.spi.BeforeShutdown;
  49 +import javax.enterprise.inject.spi.Extension;
48 import javax.enterprise.inject.spi.ProcessAnnotatedType; 50 import javax.enterprise.inject.spi.ProcessAnnotatedType;
49 51
50 import org.slf4j.Logger; 52 import org.slf4j.Logger;
51 53
  54 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  55 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
52 import br.gov.frameworkdemoiselle.util.Beans; 56 import br.gov.frameworkdemoiselle.util.Beans;
  57 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
53 58
54 -//TODO Inter [NQ]: verificar o melhor nome para todas as classes desta natureza.  
55 -public class CoreBootstrap extends AbstractBootstrap { 59 +public class CoreBootstrap implements Extension {
56 60
57 - private static final Map<Class<?>, AnnotatedType<?>> beans = new HashMap<Class<?>, AnnotatedType<?>>(); 61 + private final Map<Class<?>, AnnotatedType<?>> beans = new HashMap<Class<?>, AnnotatedType<?>>();
58 62
59 - public static boolean isAnnotatedType(Class<?> type) { 63 + private Logger logger;
  64 +
  65 + private ResourceBundle bundle;
  66 +
  67 + private Logger getLogger() {
  68 + if (this.logger == null) {
  69 + this.logger = LoggerProducer.create(CoreBootstrap.class);
  70 + }
  71 +
  72 + return this.logger;
  73 + }
  74 +
  75 + private ResourceBundle getBundle() {
  76 + if (this.bundle == null) {
  77 + this.bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault());
  78 + }
  79 +
  80 + return this.bundle;
  81 + }
  82 +
  83 + public boolean isAnnotatedType(Class<?> type) {
60 return beans.containsKey(type); 84 return beans.containsKey(type);
61 } 85 }
62 86
@@ -64,13 +88,12 @@ public class CoreBootstrap extends AbstractBootstrap { @@ -64,13 +88,12 @@ public class CoreBootstrap extends AbstractBootstrap {
64 String description; 88 String description;
65 Logger log = getLogger(); 89 Logger log = getLogger();
66 90
67 - description = getBundle("demoiselle-core-bundle").getString("engine-on"); 91 + description = getBundle().getString("engine-on");
68 log.info(description); 92 log.info(description);
69 93
70 Beans.setBeanManager(beanManager); 94 Beans.setBeanManager(beanManager);
71 95
72 - description = getBundle("demoiselle-core-bundle").getString("setting-up-bean-manager",  
73 - Beans.class.getCanonicalName()); 96 + description = getBundle().getString("setting-up-bean-manager", Beans.class.getCanonicalName());
74 log.info(description); 97 log.info(description);
75 } 98 }
76 99
@@ -78,15 +101,15 @@ public class CoreBootstrap extends AbstractBootstrap { @@ -78,15 +101,15 @@ public class CoreBootstrap extends AbstractBootstrap {
78 beans.put(event.getAnnotatedType().getJavaClass(), event.getAnnotatedType()); 101 beans.put(event.getAnnotatedType().getJavaClass(), event.getAnnotatedType());
79 } 102 }
80 103
81 - public static void takeOff(@Observes final AfterDeploymentValidation event) {  
82 - String description = getBundle("demoiselle-core-bundle").getString("taking-off"); 104 + public void takeOff(@Observes final AfterDeploymentValidation event) {
  105 + String description = getBundle().getString("taking-off");
83 106
84 Logger log = getLogger(); 107 Logger log = getLogger();
85 log.info(description); 108 log.info(description);
86 } 109 }
87 110
88 - public static void engineOff(@Observes final BeforeShutdown event) {  
89 - String description = getBundle("demoiselle-core-bundle").getString("engine-off"); 111 + public void engineOff(@Observes final BeforeShutdown event) {
  112 + String description = getBundle().getString("engine-off");
90 113
91 Logger log = getLogger(); 114 Logger log = getLogger();
92 log.info(description); 115 log.info(description);
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CustomBean.java 0 → 100644
@@ -0,0 +1,193 @@ @@ -0,0 +1,193 @@
  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 java.io.Serializable;
  40 +import java.lang.annotation.Annotation;
  41 +import java.lang.reflect.Type;
  42 +import java.util.HashSet;
  43 +import java.util.Set;
  44 +
  45 +import javax.enterprise.context.Dependent;
  46 +import javax.enterprise.context.NormalScope;
  47 +import javax.enterprise.context.spi.CreationalContext;
  48 +import javax.enterprise.inject.Alternative;
  49 +import javax.enterprise.inject.Any;
  50 +import javax.enterprise.inject.Default;
  51 +import javax.enterprise.inject.Stereotype;
  52 +import javax.enterprise.inject.spi.AnnotatedType;
  53 +import javax.enterprise.inject.spi.Bean;
  54 +import javax.enterprise.inject.spi.BeanManager;
  55 +import javax.enterprise.inject.spi.InjectionPoint;
  56 +import javax.enterprise.inject.spi.InjectionTarget;
  57 +import javax.enterprise.util.AnnotationLiteral;
  58 +import javax.inject.Named;
  59 +import javax.inject.Qualifier;
  60 +import javax.inject.Scope;
  61 +
  62 +import br.gov.frameworkdemoiselle.util.Beans;
  63 +
  64 +/**
  65 + * @see http://docs.jboss.org/weld/reference/latest/en-US/html_single/#d0e5035
  66 + */
  67 +public class CustomBean implements Bean<Object>, Serializable {
  68 +
  69 + private static final long serialVersionUID = 1L;
  70 +
  71 + private Class<Object> beanClass;
  72 +
  73 + private transient InjectionTarget<Object> injectionTarget;
  74 +
  75 + private transient BeanManager beanManager;
  76 +
  77 + private InjectionTarget<Object> getInjectionTarget() {
  78 + if (this.injectionTarget == null) {
  79 + AnnotatedType<Object> annotatedType = getBeanManager().createAnnotatedType(beanClass);
  80 + this.injectionTarget = getBeanManager().createInjectionTarget(annotatedType);
  81 + }
  82 +
  83 + return this.injectionTarget;
  84 + }
  85 +
  86 + private BeanManager getBeanManager() {
  87 + if (this.beanManager == null) {
  88 + this.beanManager = Beans.getBeanManager();
  89 + }
  90 +
  91 + return this.beanManager;
  92 + }
  93 +
  94 + public CustomBean(Class<Object> beanClass, BeanManager beanManager) {
  95 + this.beanClass = beanClass;
  96 + this.beanManager = beanManager;
  97 + }
  98 +
  99 + public Object create(CreationalContext<Object> creationalContext) {
  100 + Object instance = getInjectionTarget().produce(creationalContext);
  101 + getInjectionTarget().inject(instance, creationalContext);
  102 + getInjectionTarget().postConstruct(instance);
  103 +
  104 + return instance;
  105 + }
  106 +
  107 + public void destroy(Object instance, CreationalContext<Object> creationalContext) {
  108 + getInjectionTarget().preDestroy(instance);
  109 + getInjectionTarget().dispose(instance);
  110 + creationalContext.release();
  111 + }
  112 +
  113 + public Set<Type> getTypes() {
  114 + Set<Type> types = new HashSet<Type>();
  115 + types.add(beanClass.getSuperclass());
  116 + types.add(Object.class);
  117 +
  118 + return types;
  119 + }
  120 +
  121 + @SuppressWarnings("serial")
  122 + public Set<Annotation> getQualifiers() {
  123 + Set<Annotation> result = new HashSet<Annotation>();
  124 +
  125 + result.add(new AnnotationLiteral<Default>() {
  126 + });
  127 + result.add(new AnnotationLiteral<Any>() {
  128 + });
  129 +
  130 + for (Annotation annotation : beanClass.getAnnotations()) {
  131 + if (annotation.getClass().isAnnotationPresent(Qualifier.class)) {
  132 + result.add(annotation);
  133 + }
  134 + }
  135 +
  136 + return result;
  137 + }
  138 +
  139 + public Class<? extends Annotation> getScope() {
  140 + Class<? extends Annotation> result = Dependent.class;
  141 +
  142 + Class<? extends Annotation> annotationClass;
  143 + for (Annotation annotation : beanClass.getAnnotations()) {
  144 + annotationClass = annotation.getClass();
  145 +
  146 + if (annotationClass.isAnnotationPresent(Scope.class)
  147 + || annotationClass.isAnnotationPresent(NormalScope.class)) {
  148 + result = annotationClass;
  149 + break;
  150 + }
  151 + }
  152 +
  153 + return result;
  154 + }
  155 +
  156 + public String getName() {
  157 + String result = null;
  158 +
  159 + if (beanClass.isAnnotationPresent(Named.class)) {
  160 + result = beanClass.getAnnotation(Named.class).value();
  161 + }
  162 +
  163 + return result;
  164 + }
  165 +
  166 + public Set<Class<? extends Annotation>> getStereotypes() {
  167 + Set<Class<? extends Annotation>> result = new HashSet<Class<? extends Annotation>>();
  168 +
  169 + for (Annotation annotation : beanClass.getAnnotations()) {
  170 + if (annotation.getClass().isAnnotationPresent(Stereotype.class)) {
  171 + result.add(annotation.getClass());
  172 + }
  173 + }
  174 +
  175 + return result;
  176 + }
  177 +
  178 + public Class<Object> getBeanClass() {
  179 + return beanClass;
  180 + }
  181 +
  182 + public boolean isAlternative() {
  183 + return beanClass.isAnnotationPresent(Alternative.class);
  184 + }
  185 +
  186 + public boolean isNullable() {
  187 + return false;
  188 + }
  189 +
  190 + public Set<InjectionPoint> getInjectionPoints() {
  191 + return getInjectionTarget().getInjectionPoints();
  192 + }
  193 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ShutdownBootstrap.java
@@ -36,103 +36,31 @@ @@ -36,103 +36,31 @@
36 */ 36 */
37 package br.gov.frameworkdemoiselle.internal.bootstrap; 37 package br.gov.frameworkdemoiselle.internal.bootstrap;
38 38
39 -import java.lang.annotation.Annotation;  
40 -import java.util.ArrayList;  
41 -import java.util.Collections;  
42 -import java.util.List;  
43 -  
44 -import javax.enterprise.context.ConversationScoped;  
45 -import javax.enterprise.context.RequestScoped;  
46 -import javax.enterprise.context.SessionScoped;  
47 import javax.enterprise.event.Observes; 39 import javax.enterprise.event.Observes;
48 -import javax.enterprise.inject.spi.AfterBeanDiscovery;  
49 -import javax.enterprise.inject.spi.AnnotatedMethod;  
50 -import javax.enterprise.inject.spi.AnnotatedType;  
51 -import javax.enterprise.inject.spi.BeanManager;  
52 -import javax.enterprise.inject.spi.BeforeShutdown;  
53 -import javax.enterprise.inject.spi.ProcessAnnotatedType;  
54 40
55 -import br.gov.frameworkdemoiselle.annotation.Shutdown;  
56 -import br.gov.frameworkdemoiselle.annotation.ViewScoped;  
57 -import br.gov.frameworkdemoiselle.internal.context.CustomContext;  
58 -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext;  
59 -import br.gov.frameworkdemoiselle.internal.processor.ShutdownProcessor; 41 +import org.slf4j.Logger;
  42 +
  43 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  44 +import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess;
  45 +import br.gov.frameworkdemoiselle.lifecycle.Shutdown;
60 46
61 /** 47 /**
62 * This class run at application shutdown 48 * This class run at application shutdown
63 */ 49 */
64 -public class ShutdownBootstrap extends AbstractBootstrap {  
65 -  
66 - private static final Class<? extends Annotation> annotationClass = Shutdown.class;  
67 -  
68 - private static final List<CustomContext> tempContexts = new ArrayList<CustomContext>();  
69 -  
70 - @SuppressWarnings("rawtypes")  
71 - private static final List<ShutdownProcessor> processors = Collections  
72 - .synchronizedList(new ArrayList<ShutdownProcessor>()); 50 +public class ShutdownBootstrap extends AbstractLifecycleBootstrap<Shutdown> {
73 51
74 - private static AfterBeanDiscovery event; 52 + private Logger logger;
75 53
76 - /**  
77 - * Observes all methods annotated with @Shutdown and create an instance of ShutdownProcessor for them  
78 - *  
79 - * @param <T>  
80 - * @param event  
81 - * @param beanManager  
82 - */  
83 - public <T> void processAnnotatedType(@Observes final ProcessAnnotatedType<T> event, final BeanManager beanManager) {  
84 - final AnnotatedType<T> annotatedType = event.getAnnotatedType();  
85 - for (AnnotatedMethod<?> am : annotatedType.getMethods()) {  
86 - if (am.isAnnotationPresent(annotationClass)) {  
87 - @SuppressWarnings("unchecked")  
88 - AnnotatedMethod<T> annotatedMethod = (AnnotatedMethod<T>) am;  
89 - processors.add(new ShutdownProcessor<T>(annotatedMethod, beanManager));  
90 - } 54 + @Override
  55 + protected Logger getLogger() {
  56 + if (logger == null) {
  57 + logger = LoggerProducer.create(ShutdownBootstrap.class);
91 } 58 }
92 - }  
93 59
94 - public void saveEvent(@Observes final AfterBeanDiscovery event) {  
95 - ShutdownBootstrap.event = event; 60 + return logger;
96 } 61 }
97 62
98 - public static void loadTempContexts(final AfterBeanDiscovery event) {  
99 - // Não registrar o contexto de aplicação pq ele já é registrado pela  
100 - // implementação do CDI  
101 - tempContexts.add(new ThreadLocalContext(ViewScoped.class));  
102 - tempContexts.add(new ThreadLocalContext(SessionScoped.class, false));  
103 - tempContexts.add(new ThreadLocalContext(ConversationScoped.class));  
104 - tempContexts.add(new ThreadLocalContext(RequestScoped.class));  
105 -  
106 - for (CustomContext tempContext : tempContexts) {  
107 - addContext(tempContext, event);  
108 - }  
109 - }  
110 -  
111 - /**  
112 - * Before Shutdown it execute the methods annotateds with @Shutdown considering the priority order;  
113 - *  
114 - * @param event  
115 - * @throws Exception  
116 - */  
117 - @SuppressWarnings("unchecked")  
118 - public static void shuttingDown(@Observes final BeforeShutdown event) throws Throwable {  
119 - loadTempContexts(ShutdownBootstrap.event);  
120 -  
121 - getLogger().debug(  
122 - getBundle("demoiselle-core-bundle").getString("executing-all", annotationClass.getSimpleName()));  
123 - Collections.sort(processors);  
124 -  
125 - for (ShutdownProcessor<?> processor : processors) {  
126 - processor.process();  
127 - }  
128 -  
129 - processors.clear();  
130 - unloadTempContexts();  
131 - }  
132 -  
133 - private static void unloadTempContexts() {  
134 - for (CustomContext tempContext : tempContexts) {  
135 - disableContext(tempContext);  
136 - } 63 + public void shutdown(@Observes AfterShutdownProccess event) {
  64 + proccessEvent();
137 } 65 }
138 } 66 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/StartupBootstrap.java
@@ -36,93 +36,31 @@ @@ -36,93 +36,31 @@
36 */ 36 */
37 package br.gov.frameworkdemoiselle.internal.bootstrap; 37 package br.gov.frameworkdemoiselle.internal.bootstrap;
38 38
39 -import java.lang.annotation.Annotation;  
40 -import java.util.ArrayList;  
41 -import java.util.Collections;  
42 -import java.util.List;  
43 -  
44 -import javax.enterprise.context.ConversationScoped;  
45 -import javax.enterprise.context.RequestScoped;  
46 -import javax.enterprise.context.SessionScoped;  
47 import javax.enterprise.event.Observes; 39 import javax.enterprise.event.Observes;
48 -import javax.enterprise.inject.spi.AfterBeanDiscovery;  
49 -import javax.enterprise.inject.spi.AfterDeploymentValidation;  
50 -import javax.enterprise.inject.spi.AnnotatedMethod;  
51 -import javax.enterprise.inject.spi.AnnotatedType;  
52 -import javax.enterprise.inject.spi.BeanManager;  
53 -import javax.enterprise.inject.spi.ProcessAnnotatedType;  
54 40
55 -import br.gov.frameworkdemoiselle.annotation.Startup;  
56 -import br.gov.frameworkdemoiselle.annotation.ViewScoped;  
57 -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext;  
58 -import br.gov.frameworkdemoiselle.internal.processor.StartupProcessor; 41 +import org.slf4j.Logger;
  42 +
  43 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  44 +import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess;
  45 +import br.gov.frameworkdemoiselle.lifecycle.Startup;
59 46
60 /** 47 /**
61 * This class is the bootstrap to execute the processes at load time. 48 * This class is the bootstrap to execute the processes at load time.
62 */ 49 */
63 -public class StartupBootstrap extends AbstractBootstrap {  
64 -  
65 - private static final Class<? extends Annotation> annotationClass = Startup.class;  
66 -  
67 - private final List<ThreadLocalContext> tempContexts = new ArrayList<ThreadLocalContext>();  
68 -  
69 - @SuppressWarnings("rawtypes")  
70 - private static final List<StartupProcessor> processors = Collections  
71 - .synchronizedList(new ArrayList<StartupProcessor>());  
72 -  
73 - /**  
74 - * Observes all methods annotated with @Startup and create an instance of StartupAction for them  
75 - *  
76 - * @param <T>  
77 - * @param event  
78 - * @param beanManager  
79 - */  
80 - public <T> void processAnnotatedType(@Observes final ProcessAnnotatedType<T> event, final BeanManager beanManager) {  
81 - final AnnotatedType<T> annotatedType = event.getAnnotatedType();  
82 - for (AnnotatedMethod<?> am : annotatedType.getMethods()) {  
83 - if (am.isAnnotationPresent(annotationClass)) {  
84 - @SuppressWarnings("unchecked")  
85 - AnnotatedMethod<T> annotatedMethod = (AnnotatedMethod<T>) am;  
86 - processors.add(new StartupProcessor<T>(annotatedMethod, beanManager));  
87 - }  
88 - }  
89 - } 50 +public class StartupBootstrap extends AbstractLifecycleBootstrap<Startup> {
90 51
91 - public void loadTempContexts(@Observes final AfterBeanDiscovery event) {  
92 - //Não registrar o contexto de aplicação pq ele já é registrado pela implementação do CDI  
93 - this.tempContexts.add(new ThreadLocalContext(ViewScoped.class));  
94 - this.tempContexts.add(new ThreadLocalContext(SessionScoped.class));  
95 - this.tempContexts.add(new ThreadLocalContext(ConversationScoped.class));  
96 - this.tempContexts.add(new ThreadLocalContext(RequestScoped.class)); 52 + private Logger logger;
97 53
98 - for (ThreadLocalContext tempContext : this.tempContexts) {  
99 - addContext(tempContext, event); 54 + @Override
  55 + protected Logger getLogger() {
  56 + if (logger == null) {
  57 + logger = LoggerProducer.create(StartupBootstrap.class);
100 } 58 }
101 - }  
102 59
103 - /**  
104 - * After the deployment validation it execute the methods annotateds with @Startup considering the priority order;  
105 - *  
106 - * @param event  
107 - * @throws Exception  
108 - * @throws StartupException  
109 - */  
110 - @SuppressWarnings("unchecked")  
111 - public void startup(@Observes final AfterDeploymentValidation event) throws Throwable {  
112 - getLogger().debug(  
113 - getBundle("demoiselle-core-bundle").getString("executing-all", annotationClass.getSimpleName()));  
114 - Collections.sort(processors);  
115 -  
116 - for (StartupProcessor<?> action : processors) {  
117 - action.process();  
118 - }  
119 - processors.clear();  
120 - unloadTempContexts(); 60 + return logger;
121 } 61 }
122 62
123 - private void unloadTempContexts() {  
124 - for (ThreadLocalContext tempContext : this.tempContexts) {  
125 - disableContext(tempContext);  
126 - } 63 + public void startup(@Observes AfterStartupProccess event) {
  64 + proccessEvent();
127 } 65 }
128 } 66 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/TransactionBootstrap.java 0 → 100644
@@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
  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 org.slf4j.Logger;
  40 +
  41 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  42 +import br.gov.frameworkdemoiselle.transaction.Transaction;
  43 +
  44 +public class TransactionBootstrap extends AbstractStrategyBootstrap<Transaction> {
  45 +
  46 + private Logger logger;
  47 +
  48 + @Override
  49 + protected Logger getLogger() {
  50 + if (logger == null) {
  51 + logger = LoggerProducer.create(TransactionBootstrap.class);
  52 + }
  53 +
  54 + return logger;
  55 + }
  56 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java
@@ -36,16 +36,18 @@ @@ -36,16 +36,18 @@
36 */ 36 */
37 package br.gov.frameworkdemoiselle.internal.configuration; 37 package br.gov.frameworkdemoiselle.internal.configuration;
38 38
  39 +import java.io.FileNotFoundException;
  40 +import java.io.Serializable;
39 import java.lang.reflect.Field; 41 import java.lang.reflect.Field;
40 import java.lang.reflect.Method; 42 import java.lang.reflect.Method;
41 import java.lang.reflect.ParameterizedType; 43 import java.lang.reflect.ParameterizedType;
42 import java.lang.reflect.Type; 44 import java.lang.reflect.Type;
  45 +import java.net.URL;
43 import java.util.HashSet; 46 import java.util.HashSet;
44 import java.util.Iterator; 47 import java.util.Iterator;
45 import java.util.Properties; 48 import java.util.Properties;
46 import java.util.Set; 49 import java.util.Set;
47 50
48 -import javax.inject.Inject;  
49 import javax.validation.constraints.NotNull; 51 import javax.validation.constraints.NotNull;
50 52
51 import org.apache.commons.configuration.DataConfiguration; 53 import org.apache.commons.configuration.DataConfiguration;
@@ -60,6 +62,9 @@ import br.gov.frameworkdemoiselle.configuration.ConfigType; @@ -60,6 +62,9 @@ import br.gov.frameworkdemoiselle.configuration.ConfigType;
60 import br.gov.frameworkdemoiselle.configuration.Configuration; 62 import br.gov.frameworkdemoiselle.configuration.Configuration;
61 import br.gov.frameworkdemoiselle.configuration.ConfigurationException; 63 import br.gov.frameworkdemoiselle.configuration.ConfigurationException;
62 import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; 64 import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap;
  65 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  66 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
  67 +import br.gov.frameworkdemoiselle.util.Beans;
63 import br.gov.frameworkdemoiselle.util.Reflections; 68 import br.gov.frameworkdemoiselle.util.Reflections;
64 import br.gov.frameworkdemoiselle.util.ResourceBundle; 69 import br.gov.frameworkdemoiselle.util.ResourceBundle;
65 import br.gov.frameworkdemoiselle.util.Strings; 70 import br.gov.frameworkdemoiselle.util.Strings;
@@ -70,15 +75,14 @@ import br.gov.frameworkdemoiselle.util.Strings; @@ -70,15 +75,14 @@ import br.gov.frameworkdemoiselle.util.Strings;
70 * 75 *
71 * @author SERPRO 76 * @author SERPRO
72 */ 77 */
73 -public class ConfigurationLoader { 78 +public class ConfigurationLoader implements Serializable {
74 79
75 - @Inject  
76 - @Name("demoiselle-core-bundle")  
77 - private ResourceBundle bundle; 80 + private static final long serialVersionUID = 1L;
78 81
79 - @Inject  
80 - private Logger logger; 82 + private static ResourceBundle bundle;
81 83
  84 + private static Logger logger;
  85 +
82 /** 86 /**
83 * Loads a config class filling it with the corresponding values. 87 * Loads a config class filling it with the corresponding values.
84 * 88 *
@@ -88,13 +92,14 @@ public class ConfigurationLoader { @@ -88,13 +92,14 @@ public class ConfigurationLoader {
88 */ 92 */
89 public void load(Object object) throws ConfigurationException { 93 public void load(Object object) throws ConfigurationException {
90 Class<?> config = object.getClass(); 94 Class<?> config = object.getClass();
  95 + CoreBootstrap bootstrap = Beans.getReference(CoreBootstrap.class);
91 96
92 - if (!CoreBootstrap.isAnnotatedType(config)) { 97 + if (!bootstrap.isAnnotatedType(config)) {
93 config = config.getSuperclass(); 98 config = config.getSuperclass();
94 - logger.debug(bundle.getString("proxy-detected", config, config.getClass().getSuperclass())); 99 + getLogger().debug(getBundle().getString("proxy-detected", config, config.getClass().getSuperclass()));
95 } 100 }
96 101
97 - logger.debug(bundle.getString("loading-configuration-class", config.getName())); 102 + getLogger().debug(getBundle().getString("loading-configuration-class", config.getName()));
98 103
99 for (Field field : Reflections.getNonStaticDeclaredFields(config)) { 104 for (Field field : Reflections.getNonStaticDeclaredFields(config)) {
100 loadField(field, object, config); 105 loadField(field, object, config);
@@ -107,24 +112,27 @@ public class ConfigurationLoader { @@ -107,24 +112,27 @@ public class ConfigurationLoader {
107 ConfigType type = clazz.getAnnotation(Configuration.class).type(); 112 ConfigType type = clazz.getAnnotation(Configuration.class).type();
108 org.apache.commons.configuration.Configuration config = getConfiguration(resource, type); 113 org.apache.commons.configuration.Configuration config = getConfiguration(resource, type);
109 114
110 - String key = getKey(field, clazz, config);  
111 - Object value = getValue(key, field, config); 115 + if (config != null) {
  116 + String key = getKey(field, clazz, config);
  117 + Object value = getValue(key, field, config);
112 118
113 - validate(field, key, value, resource);  
114 - setValue(field, key, object, value); 119 + validate(field, key, value, resource);
  120 + setValue(field, key, object, value);
  121 + }
115 } 122 }
116 } 123 }
117 124
118 private void setValue(Field field, String key, Object object, Object value) { 125 private void setValue(Field field, String key, Object object, Object value) {
119 if (value != null) { 126 if (value != null) {
120 Reflections.setFieldValue(field, object, value); 127 Reflections.setFieldValue(field, object, value);
121 - logger.debug(bundle.getString("configuration-field-loaded", key, field.getName(), value)); 128 + getLogger().debug(getBundle().getString("configuration-field-loaded", key, field.getName(), value));
122 } 129 }
123 } 130 }
124 131
125 private void validate(Field field, String key, Object value, String resource) { 132 private void validate(Field field, String key, Object value, String resource) {
126 if (field.isAnnotationPresent(NotNull.class) && value == null) { 133 if (field.isAnnotationPresent(NotNull.class) && value == null) {
127 - throw new ConfigurationException(bundle.getString("configuration-attribute-is-mandatory", key, resource)); 134 + throw new ConfigurationException(getBundle().getString("configuration-attribute-is-mandatory", key,
  135 + resource));
128 } 136 }
129 } 137 }
130 138
@@ -161,7 +169,7 @@ public class ConfigurationLoader { @@ -161,7 +169,7 @@ public class ConfigurationLoader {
161 169
162 Name nameAnnotation = field.getAnnotation(Name.class); 170 Name nameAnnotation = field.getAnnotation(Name.class);
163 if (Strings.isEmpty(nameAnnotation.value())) { 171 if (Strings.isEmpty(nameAnnotation.value())) {
164 - throw new ConfigurationException(bundle.getString("configuration-name-attribute-cant-be-empty")); 172 + throw new ConfigurationException(getBundle().getString("configuration-name-attribute-cant-be-empty"));
165 } else { 173 } else {
166 key = nameAnnotation.value(); 174 key = nameAnnotation.value();
167 } 175 }
@@ -188,9 +196,9 @@ public class ConfigurationLoader { @@ -188,9 +196,9 @@ public class ConfigurationLoader {
188 } 196 }
189 197
190 if (matches == 0) { 198 if (matches == 0) {
191 - logger.debug(bundle.getString("configuration-key-not-found", key, conventions)); 199 + getLogger().debug(getBundle().getString("configuration-key-not-found", key, conventions));
192 } else if (matches > 1) { 200 } else if (matches > 1) {
193 - throw new ConfigurationException(bundle.getString("ambiguous-key", field.getName(), 201 + throw new ConfigurationException(getBundle().getString("ambiguous-key", field.getName(),
194 field.getDeclaringClass())); 202 field.getDeclaringClass()));
195 } 203 }
196 204
@@ -205,33 +213,45 @@ public class ConfigurationLoader { @@ -205,33 +213,45 @@ public class ConfigurationLoader {
205 * @return a configuration 213 * @return a configuration
206 */ 214 */
207 private org.apache.commons.configuration.Configuration getConfiguration(String resource, ConfigType type) { 215 private org.apache.commons.configuration.Configuration getConfiguration(String resource, ConfigType type) {
208 - org.apache.commons.configuration.Configuration config = null; 216 + org.apache.commons.configuration.Configuration result = null;
209 217
210 try { 218 try {
  219 + URL url;
  220 +
211 switch (type) { 221 switch (type) {
212 case SYSTEM: 222 case SYSTEM:
213 - config = new SystemConfiguration(); 223 + result = new SystemConfiguration();
214 break; 224 break;
215 225
216 case PROPERTIES: 226 case PROPERTIES:
217 - config = new DataConfiguration(new PropertiesConfiguration(resource + ".properties")); 227 + url = getResourceAsURL(resource + ".properties");
  228 +
  229 + if (url != null) {
  230 + result = new DataConfiguration(new PropertiesConfiguration(url));
  231 + }
  232 +
218 break; 233 break;
219 234
220 case XML: 235 case XML:
221 - config = new DataConfiguration(new XMLConfiguration(resource + ".xml")); 236 + url = getResourceAsURL(resource + ".xml");
  237 +
  238 + if (url != null) {
  239 + result = new DataConfiguration(new XMLConfiguration(url));
  240 + }
  241 +
222 break; 242 break;
223 243
224 default: 244 default:
225 - throw new ConfigurationException(bundle.getString("configuration-type-not-implemented-yet", 245 + throw new ConfigurationException(getBundle().getString("configuration-type-not-implemented-yet",
226 type.name())); 246 type.name()));
227 } 247 }
228 248
229 } catch (Exception cause) { 249 } catch (Exception cause) {
230 - throw new ConfigurationException(bundle.getString("error-creating-configuration-from-resource", resource),  
231 - cause); 250 + throw new ConfigurationException(getBundle().getString("error-creating-configuration-from-resource",
  251 + resource), cause);
232 } 252 }
233 253
234 - return config; 254 + return result;
235 } 255 }
236 256
237 @SuppressWarnings("unchecked") 257 @SuppressWarnings("unchecked")
@@ -239,39 +259,43 @@ public class ConfigurationLoader { @@ -239,39 +259,43 @@ public class ConfigurationLoader {
239 Object value; 259 Object value;
240 260
241 Class<?> fieldClass = (Class<?>) field.getType(); 261 Class<?> fieldClass = (Class<?>) field.getType();
242 - 262 +
243 if (fieldClass.isArray()) { 263 if (fieldClass.isArray()) {
244 value = getArray(key, field, config); 264 value = getArray(key, field, config);
  265 +
245 } else if (fieldClass.equals(Properties.class)) { 266 } else if (fieldClass.equals(Properties.class)) {
246 value = getProperty(key, config); 267 value = getProperty(key, config);
247 268
  269 + } else if (fieldClass.equals(Class.class)) {
  270 + value = getClass(key, field, config);
  271 +
248 } else { 272 } else {
249 value = getBasic(key, field, config); 273 value = getBasic(key, field, config);
250 } 274 }
251 275
252 return (T) value; 276 return (T) value;
253 } 277 }
254 - 278 +
255 private <T> Object getArray(String key, Field field, org.apache.commons.configuration.Configuration config) { 279 private <T> Object getArray(String key, Field field, org.apache.commons.configuration.Configuration config) {
256 Object value = null; 280 Object value = null;
257 281
258 Class<?> fieldClass = (Class<?>) field.getType(); 282 Class<?> fieldClass = (Class<?>) field.getType();
259 - 283 +
260 try { 284 try {
261 Method method; 285 Method method;
262 -  
263 String methodName = "get"; 286 String methodName = "get";
264 - 287 +
265 methodName += Strings.firstToUpper(fieldClass.getSimpleName()); 288 methodName += Strings.firstToUpper(fieldClass.getSimpleName());
266 methodName = Strings.removeChars(methodName, '[', ']'); 289 methodName = Strings.removeChars(methodName, '[', ']');
267 - 290 +
268 methodName += "Array"; 291 methodName += "Array";
269 292
270 method = config.getClass().getMethod(methodName, String.class); 293 method = config.getClass().getMethod(methodName, String.class);
271 value = method.invoke(config, key); 294 value = method.invoke(config, key);
272 295
273 } catch (Throwable cause) { 296 } catch (Throwable cause) {
274 - throw new ConfigurationException(bundle.getString("error-converting-to-type", fieldClass.getName()), cause); 297 + throw new ConfigurationException(getBundle().getString("error-converting-to-type", fieldClass.getName()),
  298 + cause);
275 } 299 }
276 300
277 return value; 301 return value;
@@ -281,62 +305,78 @@ public class ConfigurationLoader { @@ -281,62 +305,78 @@ public class ConfigurationLoader {
281 Object value = null; 305 Object value = null;
282 306
283 Class<?> fieldClass = (Class<?>) field.getType(); 307 Class<?> fieldClass = (Class<?>) field.getType();
284 - 308 +
285 try { 309 try {
286 Method method; 310 Method method;
287 -  
288 String methodName = "get"; 311 String methodName = "get";
289 - 312 +
290 methodName += discoveryGenericType(field); 313 methodName += discoveryGenericType(field);
291 -  
292 methodName += Strings.firstToUpper(fieldClass.getSimpleName()); 314 methodName += Strings.firstToUpper(fieldClass.getSimpleName());
293 315
294 if (!fieldClass.isPrimitive()) { 316 if (!fieldClass.isPrimitive()) {
295 method = config.getClass().getMethod(methodName, String.class, fieldClass); 317 method = config.getClass().getMethod(methodName, String.class, fieldClass);
296 value = method.invoke(config, key, null); 318 value = method.invoke(config, key, null);
297 - 319 +
298 } else if (config.containsKey(key)) { 320 } else if (config.containsKey(key)) {
299 method = config.getClass().getMethod(methodName, String.class); 321 method = config.getClass().getMethod(methodName, String.class);
300 value = method.invoke(config, key); 322 value = method.invoke(config, key);
301 } 323 }
302 324
303 } catch (Throwable cause) { 325 } catch (Throwable cause) {
304 - throw new ConfigurationException(bundle.getString("error-converting-to-type", fieldClass.getName()), cause); 326 + throw new ConfigurationException(getBundle().getString("error-converting-to-type", fieldClass.getName()),
  327 + cause);
  328 + }
  329 +
  330 + return value;
  331 + }
  332 +
  333 + private <T> Object getClass(String key, Field field, org.apache.commons.configuration.Configuration config) {
  334 + Object value = null;
  335 +
  336 + try {
  337 + String canonicalName = config.getString(key);
  338 +
  339 + if (canonicalName != null) {
  340 + ClassLoader classLoader = getClassLoaderForClass(canonicalName);
  341 + value = Class.forName(canonicalName, true, classLoader);
  342 + }
  343 +
  344 + } catch (Exception cause) {
  345 + // TODO Lançar a mensagem correta
  346 + throw new ConfigurationException(null, cause);
305 } 347 }
306 348
307 return value; 349 return value;
308 } 350 }
309 351
310 /** 352 /**
311 - * Discovery the Generic's type.  
312 - *  
313 - * for example: the generic's type of List<Integer> list is an Integer type 353 + * Discovery the Generic's type. for example: the generic's type of List<Integer> list is an Integer type
314 * 354 *
315 * @param field 355 * @param field
316 * @return 356 * @return
317 */ 357 */
318 private String discoveryGenericType(Field field) { 358 private String discoveryGenericType(Field field) {
319 - 359 +
320 Type genericFieldType = field.getGenericType(); 360 Type genericFieldType = field.getGenericType();
321 -  
322 - if(genericFieldType instanceof ParameterizedType){  
323 - ParameterizedType type = (ParameterizedType) genericFieldType;  
324 - Type[] fieldArgumentTypes = type.getActualTypeArguments();  
325 - for(Type fieldArgumentType : fieldArgumentTypes){  
326 - @SuppressWarnings("rawtypes") 361 +
  362 + if (genericFieldType instanceof ParameterizedType) {
  363 + ParameterizedType type = (ParameterizedType) genericFieldType;
  364 + Type[] fieldArgumentTypes = type.getActualTypeArguments();
  365 + for (Type fieldArgumentType : fieldArgumentTypes) {
  366 + @SuppressWarnings("rawtypes")
327 Class fieldArgumentClass = (Class) fieldArgumentType; 367 Class fieldArgumentClass = (Class) fieldArgumentType;
328 -  
329 - if("String".equals(fieldArgumentClass.getSimpleName())) {  
330 - return "";  
331 - }  
332 -  
333 - return fieldArgumentClass.getSimpleName();  
334 - } 368 +
  369 + if ("String".equals(fieldArgumentClass.getSimpleName())) {
  370 + return "";
  371 + }
  372 +
  373 + return fieldArgumentClass.getSimpleName();
  374 + }
335 } 375 }
336 - 376 +
337 return ""; 377 return "";
338 } 378 }
339 - 379 +
340 private Object getProperty(String key, org.apache.commons.configuration.Configuration config) { 380 private Object getProperty(String key, org.apache.commons.configuration.Configuration config) {
341 Object value = null; 381 Object value = null;
342 382
@@ -357,4 +397,51 @@ public class ConfigurationLoader { @@ -357,4 +397,51 @@ public class ConfigurationLoader {
357 397
358 return value; 398 return value;
359 } 399 }
  400 +
  401 + public static ClassLoader getClassLoaderForClass(final String canonicalName) throws FileNotFoundException {
  402 + return getClassLoaderForResource(canonicalName.replaceAll("\\.", "/") + ".class");
  403 + }
  404 +
  405 + public static ClassLoader getClassLoaderForResource(final String resource) throws FileNotFoundException {
  406 + final String stripped = resource.startsWith("/") ? resource.substring(1) : resource;
  407 +
  408 + URL url = null;
  409 + ClassLoader result = Thread.currentThread().getContextClassLoader();
  410 +
  411 + if (result != null) {
  412 + url = result.getResource(stripped);
  413 + }
  414 +
  415 + if (url == null) {
  416 + result = ConfigurationLoader.class.getClassLoader();
  417 + url = ConfigurationLoader.class.getClassLoader().getResource(stripped);
  418 + }
  419 +
  420 + if (url == null) {
  421 + result = null;
  422 + }
  423 +
  424 + return result;
  425 + }
  426 +
  427 + public static URL getResourceAsURL(final String resource) throws FileNotFoundException {
  428 + ClassLoader classLoader = getClassLoaderForResource(resource);
  429 + return classLoader != null ? classLoader.getResource(resource) : null;
  430 + }
  431 +
  432 + private static ResourceBundle getBundle() {
  433 + if (bundle == null) {
  434 + bundle = ResourceBundleProducer.create("demoiselle-core-bundle");
  435 + }
  436 +
  437 + return bundle;
  438 + }
  439 +
  440 + private static Logger getLogger() {
  441 + if (logger == null) {
  442 + logger = LoggerProducer.create(ConfigurationLoader.class);
  443 + }
  444 +
  445 + return logger;
  446 + }
360 } 447 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/PaginationConfig.java
@@ -77,5 +77,4 @@ public class PaginationConfig implements Serializable { @@ -77,5 +77,4 @@ public class PaginationConfig implements Serializable {
77 public int getMaxPageLinks() { 77 public int getMaxPageLinks() {
78 return maxPageLinks; 78 return maxPageLinks;
79 } 79 }
80 -  
81 } 80 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/SecurityConfig.java
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; 1 package br.gov.frameworkdemoiselle.internal.configuration;
38 2
39 -import java.io.Serializable;  
40 -  
41 -import br.gov.frameworkdemoiselle.annotation.Name;  
42 -import br.gov.frameworkdemoiselle.configuration.Configuration; 3 +import br.gov.frameworkdemoiselle.security.Authenticator;
  4 +import br.gov.frameworkdemoiselle.security.Authorizer;
43 5
44 /** 6 /**
45 * A <code>SecurityConfig</code> object is responsible for specifying which security configurations should be used for a 7 * A <code>SecurityConfig</code> object is responsible for specifying which security configurations should be used for a
@@ -47,13 +9,7 @@ import br.gov.frameworkdemoiselle.configuration.Configuration; @@ -47,13 +9,7 @@ import br.gov.frameworkdemoiselle.configuration.Configuration;
47 * 9 *
48 * @author SERPRO 10 * @author SERPRO
49 */ 11 */
50 -@Configuration(prefix = "frameworkdemoiselle.security")  
51 -public class SecurityConfig implements Serializable {  
52 -  
53 - private static final long serialVersionUID = 1L;  
54 -  
55 - @Name("enabled")  
56 - private boolean enabled = true; 12 +public interface SecurityConfig {
57 13
58 /** 14 /**
59 * Tells whether or not the security is enabled for the current application. This value could be defined in the 15 * Tells whether or not the security is enabled for the current application. This value could be defined in the
@@ -62,7 +18,15 @@ public class SecurityConfig implements Serializable { @@ -62,7 +18,15 @@ public class SecurityConfig implements Serializable {
62 * @return the value defined for the key <i>frameworkdemoiselle.security.enabled</i> in the 18 * @return the value defined for the key <i>frameworkdemoiselle.security.enabled</i> in the
63 * <b>demoiselle.properties</b> file. If there is no value defined, returns the default value <tt>true</tt> 19 * <b>demoiselle.properties</b> file. If there is no value defined, returns the default value <tt>true</tt>
64 */ 20 */
65 - public boolean isEnabled() {  
66 - return enabled;  
67 - } 21 + boolean isEnabled();
  22 +
  23 + void setEnabled(boolean enabled);
  24 +
  25 + Class<? extends Authenticator> getAuthenticatorClass();
  26 +
  27 + void setAuthenticatorClass(Class<? extends Authenticator> authenticatorClass);
  28 +
  29 + Class<? extends Authorizer> getAuthorizerClass();
  30 +
  31 + void setAuthorizerClass(Class<? extends Authorizer> authorizerClass);
68 } 32 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/SecurityConfigImpl.java 0 → 100644
@@ -0,0 +1,109 @@ @@ -0,0 +1,109 @@
  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.configuration.Configuration;
  42 +import br.gov.frameworkdemoiselle.security.Authenticator;
  43 +import br.gov.frameworkdemoiselle.security.Authorizer;
  44 +
  45 +@Configuration(prefix = "frameworkdemoiselle.security")
  46 +public class SecurityConfigImpl implements Serializable, SecurityConfig {
  47 +
  48 + private static final long serialVersionUID = 1L;
  49 +
  50 + private boolean enabled = true;
  51 +
  52 + private Class<? extends Authenticator> authenticatorClass;
  53 +
  54 + private Class<? extends Authorizer> authorizerClass;
  55 +
  56 + /*
  57 + * (non-Javadoc)
  58 + * @see br.gov.frameworkdemoiselle.security.SecurityConfig#isEnabled()
  59 + */
  60 + @Override
  61 + public boolean isEnabled() {
  62 + return this.enabled;
  63 + }
  64 +
  65 + /*
  66 + * (non-Javadoc)
  67 + * @see br.gov.frameworkdemoiselle.security.SecurityConfig#setEnabled(boolean)
  68 + */
  69 + @Override
  70 + public void setEnabled(boolean enabled) {
  71 + this.enabled = enabled;
  72 + }
  73 +
  74 + /*
  75 + * (non-Javadoc)
  76 + * @see br.gov.frameworkdemoiselle.security.SecurityConfig#getAuthenticatorClass()
  77 + */
  78 + @Override
  79 + public Class<? extends Authenticator> getAuthenticatorClass() {
  80 + return this.authenticatorClass;
  81 + }
  82 +
  83 + /*
  84 + * (non-Javadoc)
  85 + * @see br.gov.frameworkdemoiselle.security.SecurityConfig#setAuthenticatorClass(java.lang.Class)
  86 + */
  87 + @Override
  88 + public void setAuthenticatorClass(Class<? extends Authenticator> authenticatorClass) {
  89 + this.authenticatorClass = authenticatorClass;
  90 + }
  91 +
  92 + /*
  93 + * (non-Javadoc)
  94 + * @see br.gov.frameworkdemoiselle.security.SecurityConfig#getAuthorizerClass()
  95 + */
  96 + @Override
  97 + public Class<? extends Authorizer> getAuthorizerClass() {
  98 + return this.authorizerClass;
  99 + }
  100 +
  101 + /*
  102 + * (non-Javadoc)
  103 + * @see br.gov.frameworkdemoiselle.security.SecurityConfig#setAuthorizerClass(java.lang.Class)
  104 + */
  105 + @Override
  106 + public void setAuthorizerClass(Class<? extends Authorizer> authorizerClass) {
  107 + this.authorizerClass = authorizerClass;
  108 + }
  109 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/TransactionConfig.java 0 → 100644
@@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
  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 +import br.gov.frameworkdemoiselle.transaction.Transaction;
  44 +
  45 +@Configuration(prefix = "frameworkdemoiselle.transaction")
  46 +public class TransactionConfig implements Serializable {
  47 +
  48 + private static final long serialVersionUID = 1L;
  49 +
  50 + @Name("class")
  51 + private Class<? extends Transaction> transactionClass;
  52 +
  53 + public Class<? extends Transaction> getTransactionClass() {
  54 + return transactionClass;
  55 + }
  56 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ContextStore.java
@@ -54,5 +54,4 @@ public class ContextStore { @@ -54,5 +54,4 @@ public class ContextStore {
54 public void put(final String name, final Object instance) { 54 public void put(final String name, final Object instance) {
55 this.map.put(name, instance); 55 this.map.put(name, instance);
56 } 56 }
57 -  
58 } 57 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/Contexts.java
@@ -39,25 +39,58 @@ package br.gov.frameworkdemoiselle.internal.context; @@ -39,25 +39,58 @@ package br.gov.frameworkdemoiselle.internal.context;
39 import java.lang.annotation.Annotation; 39 import java.lang.annotation.Annotation;
40 import java.util.ArrayList; 40 import java.util.ArrayList;
41 import java.util.Collections; 41 import java.util.Collections;
  42 +import java.util.Iterator;
42 import java.util.List; 43 import java.util.List;
43 44
44 import javax.enterprise.inject.spi.AfterBeanDiscovery; 45 import javax.enterprise.inject.spi.AfterBeanDiscovery;
45 46
  47 +import org.slf4j.Logger;
  48 +
  49 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  50 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
  51 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
  52 +
46 public class Contexts { 53 public class Contexts {
47 54
48 - private static List<CustomContext> activeContexts; 55 + private static List<CustomContext> activeContexts = Collections.synchronizedList(new ArrayList<CustomContext>());
  56 +
  57 + private static List<CustomContext> inactiveContexts = Collections.synchronizedList(new ArrayList<CustomContext>());
  58 +
  59 + private static Logger logger;
  60 +
  61 + private static ResourceBundle bundle;
  62 +
  63 + private static Logger getLogger() {
  64 + if (logger == null) {
  65 + logger = LoggerProducer.create(Contexts.class);
  66 + }
  67 +
  68 + return logger;
  69 + }
  70 +
  71 + private static ResourceBundle getBundle() {
  72 + if (bundle == null) {
  73 + bundle = ResourceBundleProducer.create("demoiselle-core-bundle");
  74 + }
49 75
50 - private static List<CustomContext> inactiveContexts; 76 + return bundle;
  77 + }
51 78
52 - public static void add(CustomContext context, AfterBeanDiscovery event) { 79 + private Contexts() {
  80 + }
  81 +
  82 + public static synchronized void add(CustomContext context, AfterBeanDiscovery event) {
53 Class<? extends Annotation> scope = context.getScope(); 83 Class<? extends Annotation> scope = context.getScope();
54 84
55 - if (get(scope, getActiveContexts()) != null) {  
56 - getInactiveContexts().add(context); 85 + getLogger()
  86 + .trace(getBundle().getString("custom-context-was-registered", context.getScope().getCanonicalName()));
  87 +
  88 + if (get(scope, activeContexts) != null) {
  89 + inactiveContexts.add(context);
57 context.setActive(false); 90 context.setActive(false);
58 91
59 } else { 92 } else {
60 - getActiveContexts().add(context); 93 + activeContexts.add(context);
61 context.setActive(true); 94 context.setActive(true);
62 } 95 }
63 96
@@ -79,45 +112,43 @@ public class Contexts { @@ -79,45 +112,43 @@ public class Contexts {
79 return result; 112 return result;
80 } 113 }
81 114
82 - public static void remove(CustomContext context) {  
83 - if (getActiveContexts().contains(context)) {  
84 - getActiveContexts().remove(context); 115 + public static synchronized void remove(CustomContext context) {
  116 + getLogger().trace(
  117 + getBundle().getString("custom-context-was-unregistered", context.getScope().getCanonicalName()));
  118 +
  119 + if (activeContexts.contains(context)) {
  120 + activeContexts.remove(context);
85 context.setActive(false); 121 context.setActive(false);
86 122
87 - CustomContext inactive = get(context.getScope(), getInactiveContexts()); 123 + CustomContext inactive = get(context.getScope(), inactiveContexts);
88 if (inactive != null) { 124 if (inactive != null) {
89 - getActiveContexts().add(inactive); 125 + activeContexts.add(inactive);
90 inactive.setActive(true); 126 inactive.setActive(true);
91 - getInactiveContexts().remove(inactive); 127 + inactiveContexts.remove(inactive);
92 } 128 }
93 129
94 - } else if (getInactiveContexts().contains(context)) {  
95 - getInactiveContexts().remove(context); 130 + } else if (inactiveContexts.contains(context)) {
  131 + inactiveContexts.remove(context);
96 } 132 }
97 } 133 }
98 134
99 - public static void clear() {  
100 - for (CustomContext context : getActiveContexts()) { 135 + public static synchronized void clear() {
  136 + CustomContext context;
  137 + for (Iterator<CustomContext> iter = activeContexts.iterator(); iter.hasNext();) {
  138 + context = iter.next();
101 context.setActive(false); 139 context.setActive(false);
  140 + iter.remove();
102 } 141 }
103 142
104 - activeContexts = null;  
105 - inactiveContexts = null; 143 + activeContexts.clear();
  144 + inactiveContexts.clear();
106 } 145 }
107 146
108 - public static List<CustomContext> getActiveContexts() {  
109 - if (activeContexts == null) {  
110 - activeContexts = Collections.synchronizedList(new ArrayList<CustomContext>());  
111 - }  
112 - 147 + public static synchronized List<CustomContext> getActiveContexts() {
113 return activeContexts; 148 return activeContexts;
114 } 149 }
115 150
116 - public static List<CustomContext> getInactiveContexts() {  
117 - if (inactiveContexts == null) {  
118 - inactiveContexts = Collections.synchronizedList(new ArrayList<CustomContext>());  
119 - }  
120 - 151 + public static synchronized List<CustomContext> getInactiveContexts() {
121 return inactiveContexts; 152 return inactiveContexts;
122 } 153 }
123 } 154 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AnnotatedMethodProcessor.java 0 → 100644
@@ -0,0 +1,152 @@ @@ -0,0 +1,152 @@
  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.implementation;
  38 +
  39 +import java.lang.reflect.InvocationTargetException;
  40 +import java.util.Locale;
  41 +
  42 +import javax.enterprise.inject.spi.AnnotatedMethod;
  43 +
  44 +import org.slf4j.Logger;
  45 +
  46 +import br.gov.frameworkdemoiselle.annotation.Priority;
  47 +import br.gov.frameworkdemoiselle.exception.ApplicationException;
  48 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  49 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
  50 +import br.gov.frameworkdemoiselle.message.SeverityType;
  51 +import br.gov.frameworkdemoiselle.util.Beans;
  52 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
  53 +
  54 +/**
  55 + * Represents an annotated method to be processed;
  56 + *
  57 + * @param <T>
  58 + * declaring class owner of the method
  59 + */
  60 +public class AnnotatedMethodProcessor<T> implements Comparable<AnnotatedMethodProcessor<T>> {
  61 +
  62 + private AnnotatedMethod<T> annotatedMethod;
  63 +
  64 + private ResourceBundle bundle;
  65 +
  66 + public AnnotatedMethodProcessor(final AnnotatedMethod<T> annotatedMethod) {
  67 + this.annotatedMethod = annotatedMethod;
  68 + }
  69 +
  70 + public AnnotatedMethod<T> getAnnotatedMethod() {
  71 + return this.annotatedMethod;
  72 + }
  73 +
  74 + @SuppressWarnings("unchecked")
  75 + protected T getReferencedBean() {
  76 + Class<T> classType = (Class<T>) getAnnotatedMethod().getJavaMember().getDeclaringClass();
  77 +
  78 + return Beans.getReference(classType);
  79 + }
  80 +
  81 + public int compareTo(final AnnotatedMethodProcessor<T> other) {
  82 + Integer orderThis = getPriority(getAnnotatedMethod());
  83 + Integer orderOther = getPriority(other.getAnnotatedMethod());
  84 +
  85 + return orderThis.compareTo(orderOther);
  86 + }
  87 +
  88 + public boolean process(Object... args) throws Throwable {
  89 + getLogger().info(getBundle().getString("processing", getAnnotatedMethod().getJavaMember().toGenericString()));
  90 +
  91 + try {
  92 + getAnnotatedMethod().getJavaMember().invoke(getReferencedBean(), args);
  93 +
  94 + } catch (InvocationTargetException cause) {
  95 + handleException(cause.getCause());
  96 + }
  97 +
  98 + return true;
  99 + }
  100 +
  101 + private void handleException(Throwable cause) throws Throwable {
  102 + ApplicationException ann = cause.getClass().getAnnotation(ApplicationException.class);
  103 +
  104 + if (ann == null || SeverityType.FATAL == ann.severity()) {
  105 + throw cause;
  106 +
  107 + } else {
  108 + switch (ann.severity()) {
  109 + case INFO:
  110 + getLogger().info(cause.getMessage());
  111 + break;
  112 +
  113 + case WARN:
  114 + getLogger().warn(cause.getMessage());
  115 + break;
  116 +
  117 + default:
  118 + getLogger().error(getBundle().getString("processing-fail"), cause);
  119 + break;
  120 + }
  121 + }
  122 + }
  123 +
  124 + private static <T> Integer getPriority(AnnotatedMethod<T> annotatedMethod) {
  125 + Integer priority = Priority.MIN_PRIORITY;
  126 +
  127 + Priority annotation = annotatedMethod.getAnnotation(Priority.class);
  128 + if (annotation != null) {
  129 + priority = annotation.value();
  130 + }
  131 +
  132 + return priority;
  133 + }
  134 +
  135 + // @Override
  136 + // public String toString() {
  137 + // return getBundle().getString("for", getClass().getSimpleName(),
  138 + // getAnnotatedMethod().getJavaMember().toGenericString());
  139 + // }
  140 +
  141 + protected ResourceBundle getBundle() {
  142 + if (this.bundle == null) {
  143 + this.bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault());
  144 + }
  145 +
  146 + return bundle;
  147 + }
  148 +
  149 + protected Logger getLogger() {
  150 + return LoggerProducer.create(this.getClass());
  151 + }
  152 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationImpl.java 0 → 100644
@@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
  1 +package br.gov.frameworkdemoiselle.internal.implementation;
  2 +
  3 +import br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader;
  4 +import br.gov.frameworkdemoiselle.util.Beans;
  5 +
  6 +public class ConfigurationImpl {
  7 +
  8 + private boolean loaded = false;
  9 +
  10 + @SuppressWarnings("unused")
  11 + private synchronized void load(Object instance) {
  12 + if (!loaded) {
  13 + Beans.getReference(ConfigurationLoader.class).load(instance);
  14 + loaded = true;
  15 + }
  16 + }
  17 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/CoreBundle.java
@@ -1,28 +0,0 @@ @@ -1,28 +0,0 @@
1 -package br.gov.frameworkdemoiselle.internal.implementation;  
2 -  
3 -import javax.inject.Inject;  
4 -  
5 -import br.gov.frameworkdemoiselle.annotation.Name;  
6 -import br.gov.frameworkdemoiselle.util.Beans;  
7 -import br.gov.frameworkdemoiselle.util.ResourceBundle;  
8 -  
9 -public class CoreBundle {  
10 -  
11 - @Inject  
12 - @Name("demoiselle-core-bundle")  
13 - private ResourceBundle bundle;  
14 -  
15 - private static CoreBundle instance;  
16 -  
17 - private static synchronized CoreBundle getInstance() {  
18 - if (instance == null) {  
19 - instance = Beans.getReference(CoreBundle.class);  
20 - }  
21 -  
22 - return instance;  
23 - }  
24 -  
25 - public static ResourceBundle get() {  
26 - return getInstance().bundle;  
27 - }  
28 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthenticator.java
@@ -36,10 +36,14 @@ @@ -36,10 +36,14 @@
36 */ 36 */
37 package br.gov.frameworkdemoiselle.internal.implementation; 37 package br.gov.frameworkdemoiselle.internal.implementation;
38 38
  39 +import static br.gov.frameworkdemoiselle.internal.implementation.StrategySelector.CORE_PRIORITY;
39 import br.gov.frameworkdemoiselle.DemoiselleException; 40 import br.gov.frameworkdemoiselle.DemoiselleException;
  41 +import br.gov.frameworkdemoiselle.annotation.Priority;
  42 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
40 import br.gov.frameworkdemoiselle.security.Authenticator; 43 import br.gov.frameworkdemoiselle.security.Authenticator;
41 import br.gov.frameworkdemoiselle.security.SecurityContext; 44 import br.gov.frameworkdemoiselle.security.SecurityContext;
42 import br.gov.frameworkdemoiselle.security.User; 45 import br.gov.frameworkdemoiselle.security.User;
  46 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
43 47
44 /** 48 /**
45 * Authenticator that actually does nothing but raise exceptions. 49 * Authenticator that actually does nothing but raise exceptions.
@@ -47,10 +51,13 @@ import br.gov.frameworkdemoiselle.security.User; @@ -47,10 +51,13 @@ import br.gov.frameworkdemoiselle.security.User;
47 * @author SERPRO 51 * @author SERPRO
48 * @see Authenticator 52 * @see Authenticator
49 */ 53 */
  54 +@Priority(CORE_PRIORITY)
50 public class DefaultAuthenticator implements Authenticator { 55 public class DefaultAuthenticator implements Authenticator {
51 56
52 private static final long serialVersionUID = 1L; 57 private static final long serialVersionUID = 1L;
53 58
  59 + private static ResourceBundle bundle;
  60 +
54 /** 61 /**
55 * @see br.gov.frameworkdemoiselle.security.Authenticator#authenticate() 62 * @see br.gov.frameworkdemoiselle.security.Authenticator#authenticate()
56 */ 63 */
@@ -76,8 +83,15 @@ public class DefaultAuthenticator implements Authenticator { @@ -76,8 +83,15 @@ public class DefaultAuthenticator implements Authenticator {
76 } 83 }
77 84
78 private DemoiselleException getException() { 85 private DemoiselleException getException() {
79 - return new DemoiselleException(CoreBundle.get().getString("authenticator-not-defined", 86 + return new DemoiselleException(getBundle().getString("authenticator-not-defined",
80 SecurityContext.class.getSimpleName())); 87 SecurityContext.class.getSimpleName()));
81 } 88 }
82 89
  90 + private static ResourceBundle getBundle() {
  91 + if (bundle == null) {
  92 + bundle = ResourceBundleProducer.create("demoiselle-core-bundle");
  93 + }
  94 +
  95 + return bundle;
  96 + }
83 } 97 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthorizer.java
@@ -36,10 +36,13 @@ @@ -36,10 +36,13 @@
36 */ 36 */
37 package br.gov.frameworkdemoiselle.internal.implementation; 37 package br.gov.frameworkdemoiselle.internal.implementation;
38 38
  39 +import static br.gov.frameworkdemoiselle.internal.implementation.StrategySelector.CORE_PRIORITY;
39 import br.gov.frameworkdemoiselle.DemoiselleException; 40 import br.gov.frameworkdemoiselle.DemoiselleException;
  41 +import br.gov.frameworkdemoiselle.annotation.Priority;
  42 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
40 import br.gov.frameworkdemoiselle.security.Authorizer; 43 import br.gov.frameworkdemoiselle.security.Authorizer;
41 -import br.gov.frameworkdemoiselle.security.RequiredPermission;  
42 -import br.gov.frameworkdemoiselle.security.RequiredRole; 44 +import br.gov.frameworkdemoiselle.security.SecurityContext;
  45 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
43 46
44 /** 47 /**
45 * Authorizator that actually does nothing but raise exceptions. 48 * Authorizator that actually does nothing but raise exceptions.
@@ -47,20 +50,33 @@ import br.gov.frameworkdemoiselle.security.RequiredRole; @@ -47,20 +50,33 @@ import br.gov.frameworkdemoiselle.security.RequiredRole;
47 * @author SERPRO 50 * @author SERPRO
48 * @see Authorizer 51 * @see Authorizer
49 */ 52 */
  53 +@Priority(CORE_PRIORITY)
50 public class DefaultAuthorizer implements Authorizer { 54 public class DefaultAuthorizer implements Authorizer {
51 55
52 private static final long serialVersionUID = 1L; 56 private static final long serialVersionUID = 1L;
53 57
  58 + private static ResourceBundle bundle;
  59 +
54 @Override 60 @Override
55 public boolean hasRole(String role) { 61 public boolean hasRole(String role) {
56 - throw new DemoiselleException(CoreBundle.get().getString("authorizer-not-defined",  
57 - RequiredRole.class.getSimpleName())); 62 + throw getException();
58 } 63 }
59 64
60 @Override 65 @Override
61 public boolean hasPermission(String resource, String operation) { 66 public boolean hasPermission(String resource, String operation) {
62 - throw new DemoiselleException(CoreBundle.get().getString("authorizer-not-defined",  
63 - RequiredPermission.class.getSimpleName())); 67 + throw getException();
  68 + }
  69 +
  70 + private DemoiselleException getException() {
  71 + return new DemoiselleException(getBundle().getString("authorizer-not-defined",
  72 + SecurityContext.class.getSimpleName()));
64 } 73 }
65 74
  75 + private static ResourceBundle getBundle() {
  76 + if (bundle == null) {
  77 + bundle = ResourceBundleProducer.create("demoiselle-core-bundle");
  78 + }
  79 +
  80 + return bundle;
  81 + }
66 } 82 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultTransaction.java
@@ -36,11 +36,13 @@ @@ -36,11 +36,13 @@
36 */ 36 */
37 package br.gov.frameworkdemoiselle.internal.implementation; 37 package br.gov.frameworkdemoiselle.internal.implementation;
38 38
39 -import javax.enterprise.context.RequestScoped;  
40 - 39 +import static br.gov.frameworkdemoiselle.internal.implementation.StrategySelector.CORE_PRIORITY;
41 import br.gov.frameworkdemoiselle.DemoiselleException; 40 import br.gov.frameworkdemoiselle.DemoiselleException;
  41 +import br.gov.frameworkdemoiselle.annotation.Priority;
  42 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
42 import br.gov.frameworkdemoiselle.transaction.Transaction; 43 import br.gov.frameworkdemoiselle.transaction.Transaction;
43 import br.gov.frameworkdemoiselle.transaction.Transactional; 44 import br.gov.frameworkdemoiselle.transaction.Transactional;
  45 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
44 46
45 /** 47 /**
46 * Transaction strategy that actually does nothing but raise exceptions. 48 * Transaction strategy that actually does nothing but raise exceptions.
@@ -48,11 +50,13 @@ import br.gov.frameworkdemoiselle.transaction.Transactional; @@ -48,11 +50,13 @@ import br.gov.frameworkdemoiselle.transaction.Transactional;
48 * @author SERPRO 50 * @author SERPRO
49 * @see Transaction 51 * @see Transaction
50 */ 52 */
51 -@RequestScoped 53 +@Priority(CORE_PRIORITY)
52 public class DefaultTransaction implements Transaction { 54 public class DefaultTransaction implements Transaction {
53 55
54 private static final long serialVersionUID = 1L; 56 private static final long serialVersionUID = 1L;
55 57
  58 + private static ResourceBundle bundle;
  59 +
56 @Override 60 @Override
57 public void begin() { 61 public void begin() {
58 throw getException(); 62 throw getException();
@@ -84,7 +88,15 @@ public class DefaultTransaction implements Transaction { @@ -84,7 +88,15 @@ public class DefaultTransaction implements Transaction {
84 } 88 }
85 89
86 private DemoiselleException getException() { 90 private DemoiselleException getException() {
87 - return new DemoiselleException(CoreBundle.get().getString("transaction-not-defined", 91 + return new DemoiselleException(getBundle().getString("transaction-not-defined",
88 Transactional.class.getSimpleName())); 92 Transactional.class.getSimpleName()));
89 } 93 }
  94 +
  95 + private static ResourceBundle getBundle() {
  96 + if (bundle == null) {
  97 + bundle = ResourceBundleProducer.create("demoiselle-core-bundle");
  98 + }
  99 +
  100 + return bundle;
  101 + }
90 } 102 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MessageContextImpl.java
@@ -41,14 +41,17 @@ import java.util.ArrayList; @@ -41,14 +41,17 @@ import java.util.ArrayList;
41 import java.util.List; 41 import java.util.List;
42 42
43 import javax.enterprise.context.RequestScoped; 43 import javax.enterprise.context.RequestScoped;
44 -import javax.inject.Inject;  
45 44
46 import org.slf4j.Logger; 45 import org.slf4j.Logger;
47 46
  47 +import br.gov.frameworkdemoiselle.internal.interceptor.ExceptionHandlerInterceptor;
  48 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  49 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
48 import br.gov.frameworkdemoiselle.message.DefaultMessage; 50 import br.gov.frameworkdemoiselle.message.DefaultMessage;
49 import br.gov.frameworkdemoiselle.message.Message; 51 import br.gov.frameworkdemoiselle.message.Message;
50 import br.gov.frameworkdemoiselle.message.MessageContext; 52 import br.gov.frameworkdemoiselle.message.MessageContext;
51 import br.gov.frameworkdemoiselle.message.SeverityType; 53 import br.gov.frameworkdemoiselle.message.SeverityType;
  54 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
52 55
53 /** 56 /**
54 * The message store is designed to provide access to messages. It is shared by every application layer. 57 * The message store is designed to provide access to messages. It is shared by every application layer.
@@ -60,11 +63,12 @@ public class MessageContextImpl implements Serializable, MessageContext { @@ -60,11 +63,12 @@ public class MessageContextImpl implements Serializable, MessageContext {
60 63
61 private static final long serialVersionUID = 1L; 64 private static final long serialVersionUID = 1L;
62 65
63 - @Inject  
64 - private Logger logger;  
65 -  
66 private final List<Message> messages = new ArrayList<Message>(); 66 private final List<Message> messages = new ArrayList<Message>();
67 67
  68 + private static ResourceBundle bundle;
  69 +
  70 + private static Logger logger;
  71 +
68 @Override 72 @Override
69 public void add(final Message message, Object... params) { 73 public void add(final Message message, Object... params) {
70 Message aux; 74 Message aux;
@@ -75,7 +79,7 @@ public class MessageContextImpl implements Serializable, MessageContext { @@ -75,7 +79,7 @@ public class MessageContextImpl implements Serializable, MessageContext {
75 aux = message; 79 aux = message;
76 } 80 }
77 81
78 - logger.debug(CoreBundle.get().getString("adding-message-to-context", message.toString())); 82 + getLogger().debug(getBundle().getString("adding-message-to-context", message.toString()));
79 messages.add(aux); 83 messages.add(aux);
80 } 84 }
81 85
@@ -96,7 +100,23 @@ public class MessageContextImpl implements Serializable, MessageContext { @@ -96,7 +100,23 @@ public class MessageContextImpl implements Serializable, MessageContext {
96 100
97 @Override 101 @Override
98 public void clear() { 102 public void clear() {
99 - logger.debug(CoreBundle.get().getString("cleaning-message-context")); 103 + getLogger().debug(getBundle().getString("cleaning-message-context"));
100 messages.clear(); 104 messages.clear();
101 } 105 }
  106 +
  107 + private static ResourceBundle getBundle() {
  108 + if (bundle == null) {
  109 + bundle = ResourceBundleProducer.create("demoiselle-core-bundle");
  110 + }
  111 +
  112 + return bundle;
  113 + }
  114 +
  115 + private static Logger getLogger() {
  116 + if (logger == null) {
  117 + logger = LoggerProducer.create(ExceptionHandlerInterceptor.class);
  118 + }
  119 +
  120 + return logger;
  121 + }
102 } 122 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/PaginationContextImpl.java
@@ -41,11 +41,11 @@ import java.util.HashMap; @@ -41,11 +41,11 @@ import java.util.HashMap;
41 import java.util.Map; 41 import java.util.Map;
42 42
43 import javax.enterprise.context.SessionScoped; 43 import javax.enterprise.context.SessionScoped;
44 -import javax.inject.Inject;  
45 44
46 import br.gov.frameworkdemoiselle.internal.configuration.PaginationConfig; 45 import br.gov.frameworkdemoiselle.internal.configuration.PaginationConfig;
47 import br.gov.frameworkdemoiselle.pagination.Pagination; 46 import br.gov.frameworkdemoiselle.pagination.Pagination;
48 import br.gov.frameworkdemoiselle.pagination.PaginationContext; 47 import br.gov.frameworkdemoiselle.pagination.PaginationContext;
  48 +import br.gov.frameworkdemoiselle.util.Beans;
49 49
50 /** 50 /**
51 * Context implementation reserved for pagination purposes. Internally a hash map is used to store pagination data for 51 * Context implementation reserved for pagination purposes. Internally a hash map is used to store pagination data for
@@ -59,7 +59,6 @@ public class PaginationContextImpl implements Serializable, PaginationContext { @@ -59,7 +59,6 @@ public class PaginationContextImpl implements Serializable, PaginationContext {
59 59
60 private static final long serialVersionUID = 1L; 60 private static final long serialVersionUID = 1L;
61 61
62 - @Inject  
63 private PaginationConfig config; 62 private PaginationConfig config;
64 63
65 private final Map<Class<?>, Pagination> cache = new HashMap<Class<?>, Pagination>(); 64 private final Map<Class<?>, Pagination> cache = new HashMap<Class<?>, Pagination>();
@@ -73,7 +72,7 @@ public class PaginationContextImpl implements Serializable, PaginationContext { @@ -73,7 +72,7 @@ public class PaginationContextImpl implements Serializable, PaginationContext {
73 72
74 if (pagination == null && create) { 73 if (pagination == null && create) {
75 pagination = new PaginationImpl(); 74 pagination = new PaginationImpl();
76 - pagination.setPageSize(config.getPageSize()); 75 + pagination.setPageSize(getConfig().getPageSize());
77 76
78 cache.put(clazz, pagination); 77 cache.put(clazz, pagination);
79 } 78 }
@@ -81,4 +80,11 @@ public class PaginationContextImpl implements Serializable, PaginationContext { @@ -81,4 +80,11 @@ public class PaginationContextImpl implements Serializable, PaginationContext {
81 return pagination; 80 return pagination;
82 } 81 }
83 82
  83 + private PaginationConfig getConfig() {
  84 + if (config == null) {
  85 + config = Beans.getReference(PaginationConfig.class);
  86 + }
  87 +
  88 + return config;
  89 + }
84 } 90 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/PaginationImpl.java
@@ -38,8 +38,6 @@ package br.gov.frameworkdemoiselle.internal.implementation; @@ -38,8 +38,6 @@ package br.gov.frameworkdemoiselle.internal.implementation;
38 38
39 import java.io.Serializable; 39 import java.io.Serializable;
40 40
41 -import javax.enterprise.inject.Alternative;  
42 -  
43 import br.gov.frameworkdemoiselle.pagination.Pagination; 41 import br.gov.frameworkdemoiselle.pagination.Pagination;
44 import br.gov.frameworkdemoiselle.util.Strings; 42 import br.gov.frameworkdemoiselle.util.Strings;
45 43
@@ -53,7 +51,6 @@ import br.gov.frameworkdemoiselle.util.Strings; @@ -53,7 +51,6 @@ import br.gov.frameworkdemoiselle.util.Strings;
53 * @author SERPRO 51 * @author SERPRO
54 * @see Pagination 52 * @see Pagination
55 */ 53 */
56 -@Alternative  
57 public class PaginationImpl implements Serializable, Pagination { 54 public class PaginationImpl implements Serializable, Pagination {
58 55
59 private static final long serialVersionUID = 1L; 56 private static final long serialVersionUID = 1L;
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java
@@ -36,12 +36,13 @@ @@ -36,12 +36,13 @@
36 */ 36 */
37 package br.gov.frameworkdemoiselle.internal.implementation; 37 package br.gov.frameworkdemoiselle.internal.implementation;
38 38
39 -import javax.enterprise.context.SessionScoped;  
40 -import javax.inject.Inject;  
41 import javax.inject.Named; 39 import javax.inject.Named;
42 40
43 -import br.gov.frameworkdemoiselle.annotation.Name; 41 +import br.gov.frameworkdemoiselle.internal.bootstrap.AuthenticatorBootstrap;
  42 +import br.gov.frameworkdemoiselle.internal.bootstrap.AuthorizerBootstrap;
44 import br.gov.frameworkdemoiselle.internal.configuration.SecurityConfig; 43 import br.gov.frameworkdemoiselle.internal.configuration.SecurityConfig;
  44 +import br.gov.frameworkdemoiselle.internal.configuration.SecurityConfigImpl;
  45 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
45 import br.gov.frameworkdemoiselle.security.AfterLoginSuccessful; 46 import br.gov.frameworkdemoiselle.security.AfterLoginSuccessful;
46 import br.gov.frameworkdemoiselle.security.AfterLogoutSuccessful; 47 import br.gov.frameworkdemoiselle.security.AfterLogoutSuccessful;
47 import br.gov.frameworkdemoiselle.security.Authenticator; 48 import br.gov.frameworkdemoiselle.security.Authenticator;
@@ -57,33 +58,53 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle; @@ -57,33 +58,53 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle;
57 * 58 *
58 * @author SERPRO 59 * @author SERPRO
59 */ 60 */
60 -@SessionScoped  
61 @Named("securityContext") 61 @Named("securityContext")
62 public class SecurityContextImpl implements SecurityContext { 62 public class SecurityContextImpl implements SecurityContext {
63 63
64 private static final long serialVersionUID = 1L; 64 private static final long serialVersionUID = 1L;
65 65
66 - @Inject  
67 - @Name("demoiselle-core-bundle")  
68 - private ResourceBundle bundle;  
69 -  
70 - @Inject  
71 private Authenticator authenticator; 66 private Authenticator authenticator;
72 67
73 - @Inject  
74 private Authorizer authorizer; 68 private Authorizer authorizer;
75 69
76 - @Inject  
77 - private SecurityConfig config; 70 + private Authenticator getAuthenticator() {
  71 + if (this.authenticator == null) {
  72 + AuthenticatorBootstrap bootstrap = Beans.getReference(AuthenticatorBootstrap.class);
  73 + Class<? extends Authenticator> clazz = getConfig().getAuthenticatorClass();
  74 +
  75 + if (clazz == null) {
  76 + clazz = StrategySelector.getClass(Authenticator.class, bootstrap.getCache());
  77 + }
  78 +
  79 + this.authenticator = Beans.getReference(clazz);
  80 + }
  81 +
  82 + return this.authenticator;
  83 + }
  84 +
  85 + private Authorizer getAuthorizer() {
  86 + if (this.authorizer == null) {
  87 + AuthorizerBootstrap bootstrap = Beans.getReference(AuthorizerBootstrap.class);
  88 + Class<? extends Authorizer> clazz = getConfig().getAuthorizerClass();
  89 +
  90 + if (clazz == null) {
  91 + clazz = StrategySelector.getClass(Authorizer.class, bootstrap.getCache());
  92 + }
  93 +
  94 + this.authorizer = Beans.getReference(clazz);
  95 + }
  96 +
  97 + return this.authorizer;
  98 + }
78 99
79 /** 100 /**
80 * @see br.gov.frameworkdemoiselle.security.SecurityContext#hasPermission(java.lang.String, java.lang.String) 101 * @see br.gov.frameworkdemoiselle.security.SecurityContext#hasPermission(java.lang.String, java.lang.String)
81 */ 102 */
82 @Override 103 @Override
83 public boolean hasPermission(String resource, String operation) throws NotLoggedInException { 104 public boolean hasPermission(String resource, String operation) throws NotLoggedInException {
84 - if (config.isEnabled()) { 105 + if (getConfig().isEnabled()) {
85 checkLoggedIn(); 106 checkLoggedIn();
86 - return authorizer.hasPermission(resource, operation); 107 + return getAuthorizer().hasPermission(resource, operation);
87 108
88 } else { 109 } else {
89 return true; 110 return true;
@@ -95,9 +116,9 @@ public class SecurityContextImpl implements SecurityContext { @@ -95,9 +116,9 @@ public class SecurityContextImpl implements SecurityContext {
95 */ 116 */
96 @Override 117 @Override
97 public boolean hasRole(String role) throws NotLoggedInException { 118 public boolean hasRole(String role) throws NotLoggedInException {
98 - if (config.isEnabled()) { 119 + if (getConfig().isEnabled()) {
99 checkLoggedIn(); 120 checkLoggedIn();
100 - return authorizer.hasRole(role); 121 + return getAuthorizer().hasRole(role);
101 122
102 } else { 123 } else {
103 return true; 124 return true;
@@ -109,7 +130,7 @@ public class SecurityContextImpl implements SecurityContext { @@ -109,7 +130,7 @@ public class SecurityContextImpl implements SecurityContext {
109 */ 130 */
110 @Override 131 @Override
111 public boolean isLoggedIn() { 132 public boolean isLoggedIn() {
112 - if (config.isEnabled()) { 133 + if (getConfig().isEnabled()) {
113 return getUser() != null; 134 return getUser() != null;
114 } else { 135 } else {
115 return true; 136 return true;
@@ -121,7 +142,7 @@ public class SecurityContextImpl implements SecurityContext { @@ -121,7 +142,7 @@ public class SecurityContextImpl implements SecurityContext {
121 */ 142 */
122 @Override 143 @Override
123 public void login() { 144 public void login() {
124 - if (config.isEnabled() && authenticator.authenticate()) { 145 + if (getConfig().isEnabled() && getAuthenticator().authenticate()) {
125 Beans.getBeanManager().fireEvent(new AfterLoginSuccessful() { 146 Beans.getBeanManager().fireEvent(new AfterLoginSuccessful() {
126 147
127 private static final long serialVersionUID = 1L; 148 private static final long serialVersionUID = 1L;
@@ -135,9 +156,9 @@ public class SecurityContextImpl implements SecurityContext { @@ -135,9 +156,9 @@ public class SecurityContextImpl implements SecurityContext {
135 */ 156 */
136 @Override 157 @Override
137 public void logout() throws NotLoggedInException { 158 public void logout() throws NotLoggedInException {
138 - if (config.isEnabled()) { 159 + if (getConfig().isEnabled()) {
139 checkLoggedIn(); 160 checkLoggedIn();
140 - authenticator.unAuthenticate(); 161 + getAuthenticator().unAuthenticate();
141 162
142 Beans.getBeanManager().fireEvent(new AfterLogoutSuccessful() { 163 Beans.getBeanManager().fireEvent(new AfterLogoutSuccessful() {
143 164
@@ -151,9 +172,9 @@ public class SecurityContextImpl implements SecurityContext { @@ -151,9 +172,9 @@ public class SecurityContextImpl implements SecurityContext {
151 */ 172 */
152 @Override 173 @Override
153 public User getUser() { 174 public User getUser() {
154 - User user = authenticator.getUser(); 175 + User user = getAuthenticator().getUser();
155 176
156 - if (!config.isEnabled() && user == null) { 177 + if (!getConfig().isEnabled() && user == null) {
157 user = new User() { 178 user = new User() {
158 179
159 private static final long serialVersionUID = 1L; 180 private static final long serialVersionUID = 1L;
@@ -177,8 +198,13 @@ public class SecurityContextImpl implements SecurityContext { @@ -177,8 +198,13 @@ public class SecurityContextImpl implements SecurityContext {
177 return user; 198 return user;
178 } 199 }
179 200
  201 + private SecurityConfig getConfig() {
  202 + return Beans.getReference(SecurityConfigImpl.class);
  203 + }
  204 +
180 private void checkLoggedIn() throws NotLoggedInException { 205 private void checkLoggedIn() throws NotLoggedInException {
181 if (!isLoggedIn()) { 206 if (!isLoggedIn()) {
  207 + ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-core-bundle");
182 throw new NotLoggedInException(bundle.getString("user-not-authenticated")); 208 throw new NotLoggedInException(bundle.getString("user-not-authenticated"));
183 } 209 }
184 } 210 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/StrategySelector.java 0 → 100644
@@ -0,0 +1,172 @@ @@ -0,0 +1,172 @@
  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.implementation;
  38 +
  39 +import static br.gov.frameworkdemoiselle.annotation.Priority.MIN_PRIORITY;
  40 +
  41 +import java.io.Serializable;
  42 +import java.util.ArrayList;
  43 +import java.util.List;
  44 +
  45 +import br.gov.frameworkdemoiselle.annotation.Priority;
  46 +import br.gov.frameworkdemoiselle.configuration.ConfigurationException;
  47 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
  48 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
  49 +
  50 +public final class StrategySelector implements Serializable {
  51 +
  52 + public static final int CORE_PRIORITY = MIN_PRIORITY;
  53 +
  54 + public static final int EXTENSIONS_L1_PRIORITY = CORE_PRIORITY - 100;
  55 +
  56 + public static final int EXTENSIONS_L2_PRIORITY = EXTENSIONS_L1_PRIORITY - 100;
  57 +
  58 + public static final int COMPONENTS_PRIORITY = EXTENSIONS_L2_PRIORITY - 100;
  59 +
  60 + private static final long serialVersionUID = 1L;
  61 +
  62 + private static ResourceBundle bundle;
  63 +
  64 + private StrategySelector() {
  65 + }
  66 +
  67 + private static ResourceBundle getBundle() {
  68 + if (bundle == null) {
  69 + bundle = ResourceBundleProducer.create("demoiselle-core-bundle");
  70 + }
  71 +
  72 + return bundle;
  73 + }
  74 +
  75 + public static <T> Class<? extends T> getClass(Class<T> type, List<Class<? extends T>> options)
  76 + throws ConfigurationException {
  77 + Class<? extends T> selected = null;
  78 +
  79 + for (Class<? extends T> option : options) {
  80 + if (selected == null || getPriority(option) < getPriority(selected)) {
  81 + selected = option;
  82 + }
  83 + }
  84 +
  85 + checkForAmbiguity(type, selected, options);
  86 +
  87 + return selected;
  88 + }
  89 +
  90 + private static <T> void checkForAmbiguity(Class<T> type, Class<? extends T> selected,
  91 + List<Class<? extends T>> options) throws ConfigurationException {
  92 + int selectedPriority = getPriority(selected);
  93 +
  94 + List<Class<? extends T>> ambiguous = new ArrayList<Class<? extends T>>();
  95 +
  96 + for (Class<? extends T> option : options) {
  97 + if (selected != option && selectedPriority == getPriority(option)) {
  98 + ambiguous.add(option);
  99 + }
  100 + }
  101 +
  102 + if (!ambiguous.isEmpty()) {
  103 + ambiguous.add(selected);
  104 +
  105 + String message = getExceptionMessage(type, ambiguous);
  106 + throw new ConfigurationException(message);
  107 + }
  108 + }
  109 +
  110 + private static <T> String getExceptionMessage(Class<T> type, List<Class<? extends T>> ambiguous) {
  111 + StringBuffer classes = new StringBuffer();
  112 +
  113 + int i = 0;
  114 + for (Class<? extends T> clazz : ambiguous) {
  115 + if (i++ != 0) {
  116 + classes.append(", ");
  117 + }
  118 +
  119 + classes.append(clazz.getCanonicalName());
  120 + }
  121 +
  122 + return getBundle().getString("ambiguous-strategy-resolution", type.getCanonicalName(), classes.toString());
  123 + }
  124 +
  125 + private static <T> int getPriority(Class<T> type) {
  126 + int result = Priority.MAX_PRIORITY;
  127 + Priority priority = type.getAnnotation(Priority.class);
  128 +
  129 + if (priority != null) {
  130 + result = priority.value();
  131 + }
  132 +
  133 + return result;
  134 + }
  135 +
  136 + // public static <T> T getExplicitReference(String configKey, Class<T> strategyType, Class<T> defaultType) {
  137 + // Class<T> selectedType = loadSelected(configKey, strategyType, defaultType);
  138 + // return Beans.getReference(selectedType);
  139 + // }
  140 + //
  141 + // @SuppressWarnings("unchecked")
  142 + // private static <T> Class<T> loadSelected(String configKey, Class<T> strategyType, Class<T> defaultType) {
  143 + // ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-core-bundle",
  144 + // Beans.getReference(Locale.class));
  145 + // Class<T> result = null;
  146 + // String canonicalName = null;
  147 + // String typeName = strategyType.getSimpleName().toLowerCase();
  148 + // String key = null;
  149 + // try {
  150 + // URL url = ConfigurationLoader.getResourceAsURL("demoiselle.properties");
  151 + // Configuration config = new PropertiesConfiguration(url);
  152 + // canonicalName = config.getString(configKey, defaultType.getCanonicalName());
  153 + // ClassLoader classLoader = ConfigurationLoader.getClassLoaderForClass(canonicalName);
  154 + // if (classLoader == null) {
  155 + // classLoader = Thread.currentThread().getContextClassLoader();
  156 + // }
  157 + // result = (Class<T>) Class.forName(canonicalName, false, classLoader);
  158 + // result.asSubclass(strategyType);
  159 + // } catch (org.apache.commons.configuration.ConfigurationException cause) {
  160 + // throw new ConfigurationException(bundle.getString("file-not-found", "demoiselle.properties"));
  161 + // } catch (ClassNotFoundException cause) {
  162 + // key = Strings.getString("{0}-class-not-found", typeName);
  163 + // throw new ConfigurationException(bundle.getString(key, canonicalName));
  164 + // } catch (FileNotFoundException e) {
  165 + // throw new ConfigurationException(bundle.getString("file-not-found", "demoiselle.properties"));
  166 + // } catch (ClassCastException cause) {
  167 + // key = Strings.getString("{0}-class-must-be-of-type", typeName);
  168 + // throw new ConfigurationException(bundle.getString(key, canonicalName, strategyType));
  169 + // }
  170 + // return result;
  171 + // }
  172 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionContextImpl.java 0 → 100644
@@ -0,0 +1,82 @@ @@ -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 +package br.gov.frameworkdemoiselle.internal.implementation;
  38 +
  39 +import javax.inject.Named;
  40 +
  41 +import br.gov.frameworkdemoiselle.internal.bootstrap.TransactionBootstrap;
  42 +import br.gov.frameworkdemoiselle.internal.configuration.TransactionConfig;
  43 +import br.gov.frameworkdemoiselle.transaction.Transaction;
  44 +import br.gov.frameworkdemoiselle.transaction.TransactionContext;
  45 +import br.gov.frameworkdemoiselle.util.Beans;
  46 +
  47 +/**
  48 + * This is the default implementation of {@link TransactionContext} interface.
  49 + *
  50 + * @author SERPRO
  51 + */
  52 +@Named("transactionContext")
  53 +public class TransactionContextImpl implements TransactionContext {
  54 +
  55 + private static final long serialVersionUID = 1L;
  56 +
  57 + private Transaction transaction;
  58 +
  59 + private Transaction getTransaction() {
  60 + if (this.transaction == null) {
  61 + TransactionBootstrap bootstrap = Beans.getReference(TransactionBootstrap.class);
  62 + Class<? extends Transaction> clazz = getConfig().getTransactionClass();
  63 +
  64 + if (clazz == null) {
  65 + clazz = StrategySelector.getClass(Transaction.class, bootstrap.getCache());
  66 + }
  67 +
  68 + this.transaction = Beans.getReference(clazz);
  69 + }
  70 +
  71 + return this.transaction;
  72 + }
  73 +
  74 + @Override
  75 + public Transaction getCurrentTransaction() {
  76 + return getTransaction();
  77 + }
  78 +
  79 + private TransactionConfig getConfig() {
  80 + return Beans.getReference(TransactionConfig.class);
  81 + }
  82 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionInfo.java
  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 + */
1 package br.gov.frameworkdemoiselle.internal.implementation; 37 package br.gov.frameworkdemoiselle.internal.implementation;
2 38
3 import java.io.Serializable; 39 import java.io.Serializable;
4 40
5 import javax.enterprise.context.RequestScoped; 41 import javax.enterprise.context.RequestScoped;
6 42
7 -//TODO Inter [NQ]: considerar a necessidade da criação de um contexto de transação para manter a coerência com as demais funcionalidades que possuem um contexto.  
8 -//Resposta: não foi feito porque só foi identificado uma funcionalidade (getCurrentTransaction). Aguardar novas ideias.  
9 @RequestScoped 43 @RequestScoped
10 public class TransactionInfo implements Serializable { 44 public class TransactionInfo implements Serializable {
11 45
@@ -13,7 +47,16 @@ public class TransactionInfo implements Serializable { @@ -13,7 +47,16 @@ public class TransactionInfo implements Serializable {
13 47
14 private int counter = 0; 48 private int counter = 0;
15 49
16 - private boolean owner = false; 50 + private boolean owner;
  51 +
  52 + public TransactionInfo() {
  53 + clear();
  54 + }
  55 +
  56 + public void clear() {
  57 + this.owner = false;
  58 + this.counter = 0;
  59 + }
17 60
18 public int getCounter() { 61 public int getCounter() {
19 return counter; 62 return counter;
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptor.java
@@ -42,7 +42,6 @@ import java.lang.reflect.Method; @@ -42,7 +42,6 @@ import java.lang.reflect.Method;
42 import java.util.HashMap; 42 import java.util.HashMap;
43 import java.util.Map; 43 import java.util.Map;
44 44
45 -import javax.inject.Inject;  
46 import javax.interceptor.AroundInvoke; 45 import javax.interceptor.AroundInvoke;
47 import javax.interceptor.Interceptor; 46 import javax.interceptor.Interceptor;
48 import javax.interceptor.InvocationContext; 47 import javax.interceptor.InvocationContext;
@@ -50,10 +49,12 @@ import javax.interceptor.InvocationContext; @@ -50,10 +49,12 @@ import javax.interceptor.InvocationContext;
50 import org.slf4j.Logger; 49 import org.slf4j.Logger;
51 50
52 import br.gov.frameworkdemoiselle.DemoiselleException; 51 import br.gov.frameworkdemoiselle.DemoiselleException;
53 -import br.gov.frameworkdemoiselle.annotation.Name;  
54 import br.gov.frameworkdemoiselle.exception.ExceptionHandler; 52 import br.gov.frameworkdemoiselle.exception.ExceptionHandler;
55 import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; 53 import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap;
  54 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  55 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
56 import br.gov.frameworkdemoiselle.stereotype.Controller; 56 import br.gov.frameworkdemoiselle.stereotype.Controller;
  57 +import br.gov.frameworkdemoiselle.util.Beans;
57 import br.gov.frameworkdemoiselle.util.ResourceBundle; 58 import br.gov.frameworkdemoiselle.util.ResourceBundle;
58 59
59 @Interceptor 60 @Interceptor
@@ -62,20 +63,14 @@ public class ExceptionHandlerInterceptor implements Serializable { @@ -62,20 +63,14 @@ public class ExceptionHandlerInterceptor implements Serializable {
62 63
63 private static final long serialVersionUID = 1L; 64 private static final long serialVersionUID = 1L;
64 65
65 - private final ResourceBundle bundle; 66 + private static ResourceBundle bundle;
66 67
67 - private final Logger logger;  
68 -  
69 - @Inject  
70 - public ExceptionHandlerInterceptor(Logger logger, @Name("demoiselle-core-bundle") ResourceBundle bundle) {  
71 - this.logger = logger;  
72 - this.bundle = bundle;  
73 - } 68 + private static Logger logger;
74 69
75 private final Map<Class<?>, Map<Class<?>, Method>> cache = new HashMap<Class<?>, Map<Class<?>, Method>>(); 70 private final Map<Class<?>, Map<Class<?>, Method>> cache = new HashMap<Class<?>, Map<Class<?>, Method>>();
76 71
77 private final boolean handleException(final Exception cause, final InvocationContext ic) throws Exception { 72 private final boolean handleException(final Exception cause, final InvocationContext ic) throws Exception {
78 - logger.info(bundle.getString("handling-exception", cause.getClass().getCanonicalName())); 73 + getLogger().info(getBundle().getString("handling-exception", cause.getClass().getCanonicalName()));
79 74
80 boolean handled = false; 75 boolean handled = false;
81 Class<?> type = getType(ic); 76 Class<?> type = getType(ic);
@@ -95,11 +90,13 @@ public class ExceptionHandlerInterceptor implements Serializable { @@ -95,11 +90,13 @@ public class ExceptionHandlerInterceptor implements Serializable {
95 90
96 private final Class<?> getType(final InvocationContext ic) { 91 private final Class<?> getType(final InvocationContext ic) {
97 Class<?> type = ic.getTarget().getClass(); 92 Class<?> type = ic.getTarget().getClass();
  93 + CoreBootstrap bootstrap = Beans.getReference(CoreBootstrap.class);
98 94
99 - if (!CoreBootstrap.isAnnotatedType(type)) { 95 + if (!bootstrap.isAnnotatedType(type)) {
100 type = type.getSuperclass(); 96 type = type.getSuperclass();
101 - logger.debug(bundle.getString("proxy-detected", ic.getTarget().getClass(), ic.getTarget().getClass()  
102 - .getSuperclass())); 97 + getLogger().debug(
  98 + getBundle().getString("proxy-detected", ic.getTarget().getClass(),
  99 + ic.getTarget().getClass().getSuperclass()));
103 } 100 }
104 101
105 return type; 102 return type;
@@ -149,7 +146,7 @@ public class ExceptionHandlerInterceptor implements Serializable { @@ -149,7 +146,7 @@ public class ExceptionHandlerInterceptor implements Serializable {
149 */ 146 */
150 private final void validateHandler(final Method method) { 147 private final void validateHandler(final Method method) {
151 if (method.getParameterTypes().length != 1) { 148 if (method.getParameterTypes().length != 1) {
152 - throw new DemoiselleException(bundle.getString("must-declare-one-single-parameter", 149 + throw new DemoiselleException(getBundle().getString("must-declare-one-single-parameter",
153 method.toGenericString())); 150 method.toGenericString()));
154 } 151 }
155 } 152 }
@@ -170,8 +167,10 @@ public class ExceptionHandlerInterceptor implements Serializable { @@ -170,8 +167,10 @@ public class ExceptionHandlerInterceptor implements Serializable {
170 167
171 try { 168 try {
172 method.invoke(object, param); 169 method.invoke(object, param);
  170 +
173 } catch (InvocationTargetException cause) { 171 } catch (InvocationTargetException cause) {
174 Throwable targetTrowable = cause.getTargetException(); 172 Throwable targetTrowable = cause.getTargetException();
  173 +
175 if (targetTrowable instanceof Exception) { 174 if (targetTrowable instanceof Exception) {
176 throw (Exception) targetTrowable; 175 throw (Exception) targetTrowable;
177 } else { 176 } else {
@@ -181,13 +180,14 @@ public class ExceptionHandlerInterceptor implements Serializable { @@ -181,13 +180,14 @@ public class ExceptionHandlerInterceptor implements Serializable {
181 180
182 method.setAccessible(accessible); 181 method.setAccessible(accessible);
183 } 182 }
184 - 183 +
185 @AroundInvoke 184 @AroundInvoke
186 public Object manage(final InvocationContext ic) throws Exception { 185 public Object manage(final InvocationContext ic) throws Exception {
187 Object result = null; 186 Object result = null;
188 187
189 try { 188 try {
190 result = ic.proceed(); 189 result = ic.proceed();
  190 +
191 } catch (Exception cause) { 191 } catch (Exception cause) {
192 if (!handleException(cause, ic)) { 192 if (!handleException(cause, ic)) {
193 throw cause; 193 throw cause;
@@ -197,4 +197,19 @@ public class ExceptionHandlerInterceptor implements Serializable { @@ -197,4 +197,19 @@ public class ExceptionHandlerInterceptor implements Serializable {
197 return result; 197 return result;
198 } 198 }
199 199
  200 + private static ResourceBundle getBundle() {
  201 + if (bundle == null) {
  202 + bundle = ResourceBundleProducer.create("demoiselle-core-bundle");
  203 + }
  204 +
  205 + return bundle;
  206 + }
  207 +
  208 + private static Logger getLogger() {
  209 + if (logger == null) {
  210 + logger = LoggerProducer.create(ExceptionHandlerInterceptor.class);
  211 + }
  212 +
  213 + return logger;
  214 + }
200 } 215 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredPermissionInterceptor.java
@@ -38,8 +38,6 @@ package br.gov.frameworkdemoiselle.internal.interceptor; @@ -38,8 +38,6 @@ package br.gov.frameworkdemoiselle.internal.interceptor;
38 38
39 import java.io.Serializable; 39 import java.io.Serializable;
40 40
41 -import javax.enterprise.inject.Instance;  
42 -import javax.inject.Inject;  
43 import javax.interceptor.AroundInvoke; 41 import javax.interceptor.AroundInvoke;
44 import javax.interceptor.Interceptor; 42 import javax.interceptor.Interceptor;
45 import javax.interceptor.InvocationContext; 43 import javax.interceptor.InvocationContext;
@@ -47,10 +45,13 @@ import javax.interceptor.InvocationContext; @@ -47,10 +45,13 @@ import javax.interceptor.InvocationContext;
47 import org.slf4j.Logger; 45 import org.slf4j.Logger;
48 46
49 import br.gov.frameworkdemoiselle.annotation.Name; 47 import br.gov.frameworkdemoiselle.annotation.Name;
  48 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  49 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
50 import br.gov.frameworkdemoiselle.security.AuthorizationException; 50 import br.gov.frameworkdemoiselle.security.AuthorizationException;
51 import br.gov.frameworkdemoiselle.security.RequiredPermission; 51 import br.gov.frameworkdemoiselle.security.RequiredPermission;
52 import br.gov.frameworkdemoiselle.security.SecurityContext; 52 import br.gov.frameworkdemoiselle.security.SecurityContext;
53 import br.gov.frameworkdemoiselle.security.User; 53 import br.gov.frameworkdemoiselle.security.User;
  54 +import br.gov.frameworkdemoiselle.util.Beans;
54 import br.gov.frameworkdemoiselle.util.ResourceBundle; 55 import br.gov.frameworkdemoiselle.util.ResourceBundle;
55 import br.gov.frameworkdemoiselle.util.Strings; 56 import br.gov.frameworkdemoiselle.util.Strings;
56 57
@@ -65,19 +66,11 @@ public class RequiredPermissionInterceptor implements Serializable { @@ -65,19 +66,11 @@ public class RequiredPermissionInterceptor implements Serializable {
65 66
66 private static final long serialVersionUID = 1L; 67 private static final long serialVersionUID = 1L;
67 68
68 - private final Instance<SecurityContext> securityContext; 69 + private SecurityContext securityContext;
69 70
70 - private final ResourceBundle bundle; 71 + private static ResourceBundle bundle;
71 72
72 - private final Logger logger;  
73 -  
74 - @Inject  
75 - public RequiredPermissionInterceptor(Instance<SecurityContext> securityContext,  
76 - @Name("demoiselle-core-bundle") ResourceBundle bundle, Logger logger) {  
77 - this.securityContext = securityContext;  
78 - this.bundle = bundle;  
79 - this.logger = logger;  
80 - } 73 + private static Logger logger;
81 74
82 /** 75 /**
83 * Gets the values for both resource and operation properties of {@code @RequiredPermission}. Delegates to 76 * Gets the values for both resource and operation properties of {@code @RequiredPermission}. Delegates to
@@ -98,17 +91,17 @@ public class RequiredPermissionInterceptor implements Serializable { @@ -98,17 +91,17 @@ public class RequiredPermissionInterceptor implements Serializable {
98 String operation = getOperation(ic); 91 String operation = getOperation(ic);
99 String username = null; 92 String username = null;
100 93
101 - if (securityContext.get().isLoggedIn()) { 94 + if (getSecurityContext().isLoggedIn()) {
102 username = getUsername(); 95 username = getUsername();
103 - logger.trace(bundle.getString("access-checking", username, operation, resource)); 96 + getLogger().trace(getBundle().getString("access-checking", username, operation, resource));
104 } 97 }
105 98
106 - if (!securityContext.get().hasPermission(resource, operation)) {  
107 - logger.error(bundle.getString("access-denied", username, operation, resource));  
108 - throw new AuthorizationException(bundle.getString("access-denied-ui", resource, operation)); 99 + if (!getSecurityContext().hasPermission(resource, operation)) {
  100 + getLogger().error(getBundle().getString("access-denied", username, operation, resource));
  101 + throw new AuthorizationException(getBundle().getString("access-denied-ui", resource, operation));
109 } 102 }
110 103
111 - logger.debug(bundle.getString("access-allowed", username, operation, resource)); 104 + getLogger().debug(getBundle().getString("access-allowed", username, operation, resource));
112 return ic.proceed(); 105 return ic.proceed();
113 } 106 }
114 107
@@ -119,7 +112,7 @@ public class RequiredPermissionInterceptor implements Serializable { @@ -119,7 +112,7 @@ public class RequiredPermissionInterceptor implements Serializable {
119 */ 112 */
120 private String getUsername() { 113 private String getUsername() {
121 String username = ""; 114 String username = "";
122 - User user = securityContext.get().getUser(); 115 + User user = getSecurityContext().getUser();
123 116
124 if (user != null && user.getId() != null) { 117 if (user != null && user.getId() != null) {
125 username = user.getId(); 118 username = user.getId();
@@ -173,4 +166,28 @@ public class RequiredPermissionInterceptor implements Serializable { @@ -173,4 +166,28 @@ public class RequiredPermissionInterceptor implements Serializable {
173 return requiredPermission.operation(); 166 return requiredPermission.operation();
174 } 167 }
175 } 168 }
  169 +
  170 + private SecurityContext getSecurityContext() {
  171 + if (securityContext == null) {
  172 + securityContext = Beans.getReference(SecurityContext.class);
  173 + }
  174 +
  175 + return securityContext;
  176 + }
  177 +
  178 + private static ResourceBundle getBundle() {
  179 + if (bundle == null) {
  180 + bundle = ResourceBundleProducer.create("demoiselle-core-bundle");
  181 + }
  182 +
  183 + return bundle;
  184 + }
  185 +
  186 + private static Logger getLogger() {
  187 + if (logger == null) {
  188 + logger = LoggerProducer.create(RequiredPermissionInterceptor.class);
  189 + }
  190 +
  191 + return logger;
  192 + }
176 } 193 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredRoleInterceptor.java
@@ -41,18 +41,18 @@ import java.util.ArrayList; @@ -41,18 +41,18 @@ import java.util.ArrayList;
41 import java.util.Arrays; 41 import java.util.Arrays;
42 import java.util.List; 42 import java.util.List;
43 43
44 -import javax.enterprise.inject.Instance;  
45 -import javax.inject.Inject;  
46 import javax.interceptor.AroundInvoke; 44 import javax.interceptor.AroundInvoke;
47 import javax.interceptor.Interceptor; 45 import javax.interceptor.Interceptor;
48 import javax.interceptor.InvocationContext; 46 import javax.interceptor.InvocationContext;
49 47
50 import org.slf4j.Logger; 48 import org.slf4j.Logger;
51 49
52 -import br.gov.frameworkdemoiselle.annotation.Name; 50 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  51 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
53 import br.gov.frameworkdemoiselle.security.AuthorizationException; 52 import br.gov.frameworkdemoiselle.security.AuthorizationException;
54 import br.gov.frameworkdemoiselle.security.RequiredRole; 53 import br.gov.frameworkdemoiselle.security.RequiredRole;
55 import br.gov.frameworkdemoiselle.security.SecurityContext; 54 import br.gov.frameworkdemoiselle.security.SecurityContext;
  55 +import br.gov.frameworkdemoiselle.util.Beans;
56 import br.gov.frameworkdemoiselle.util.ResourceBundle; 56 import br.gov.frameworkdemoiselle.util.ResourceBundle;
57 57
58 /** 58 /**
@@ -66,19 +66,11 @@ public class RequiredRoleInterceptor implements Serializable { @@ -66,19 +66,11 @@ public class RequiredRoleInterceptor implements Serializable {
66 66
67 private static final long serialVersionUID = 1L; 67 private static final long serialVersionUID = 1L;
68 68
69 - private final Instance<SecurityContext> securityContext; 69 + private SecurityContext securityContext;
70 70
71 - private final ResourceBundle bundle; 71 + private static ResourceBundle bundle;
72 72
73 - private final Logger logger;  
74 -  
75 - @Inject  
76 - public RequiredRoleInterceptor(Instance<SecurityContext> securityContext,  
77 - @Name("demoiselle-core-bundle") ResourceBundle bundle, Logger logger) {  
78 - this.securityContext = securityContext;  
79 - this.bundle = bundle;  
80 - this.logger = logger;  
81 - } 73 + private static Logger logger;
82 74
83 /** 75 /**
84 * Gets the value property of {@code @RequiredRole}. Delegates to {@code SecurityContext} check role. If the user 76 * Gets the value property of {@code @RequiredRole}. Delegates to {@code SecurityContext} check role. If the user
@@ -96,27 +88,29 @@ public class RequiredRoleInterceptor implements Serializable { @@ -96,27 +88,29 @@ public class RequiredRoleInterceptor implements Serializable {
96 public Object manage(final InvocationContext ic) throws Exception { 88 public Object manage(final InvocationContext ic) throws Exception {
97 List<String> roles = getRoles(ic); 89 List<String> roles = getRoles(ic);
98 90
99 - if (securityContext.get().isLoggedIn()) {  
100 - logger.info(bundle.getString("has-role-verification", securityContext.get().getUser().getId(), roles)); 91 + if (getSecurityContext().isLoggedIn()) {
  92 + getLogger().info(
  93 + getBundle().getString("has-role-verification", getSecurityContext().getUser().getId(), roles));
101 } 94 }
102 95
103 List<String> userRoles = new ArrayList<String>(); 96 List<String> userRoles = new ArrayList<String>();
104 97
105 for (String role : roles) { 98 for (String role : roles) {
106 - if (securityContext.get().hasRole(role)) { 99 + if (getSecurityContext().hasRole(role)) {
107 userRoles.add(role); 100 userRoles.add(role);
108 } 101 }
109 } 102 }
110 103
111 if (userRoles.isEmpty()) { 104 if (userRoles.isEmpty()) {
112 - logger.error(bundle.getString("does-not-have-role", securityContext.get().getUser().getId(), roles)); 105 + getLogger().error(
  106 + getBundle().getString("does-not-have-role", getSecurityContext().getUser().getId(), roles));
113 107
114 @SuppressWarnings("unused") 108 @SuppressWarnings("unused")
115 AuthorizationException a = new AuthorizationException(null); 109 AuthorizationException a = new AuthorizationException(null);
116 - throw new AuthorizationException(bundle.getString("does-not-have-role-ui", roles)); 110 + throw new AuthorizationException(getBundle().getString("does-not-have-role-ui", roles));
117 } 111 }
118 112
119 - logger.debug(bundle.getString("user-has-role", securityContext.get().getUser().getId(), userRoles)); 113 + getLogger().debug(getBundle().getString("user-has-role", getSecurityContext().getUser().getId(), userRoles));
120 114
121 return ic.proceed(); 115 return ic.proceed();
122 } 116 }
@@ -141,5 +135,28 @@ public class RequiredRoleInterceptor implements Serializable { @@ -141,5 +135,28 @@ public class RequiredRoleInterceptor implements Serializable {
141 135
142 return Arrays.asList(roles); 136 return Arrays.asList(roles);
143 } 137 }
144 - 138 +
  139 + private SecurityContext getSecurityContext() {
  140 + if (securityContext == null) {
  141 + securityContext = Beans.getReference(SecurityContext.class);
  142 + }
  143 +
  144 + return securityContext;
  145 + }
  146 +
  147 + private static ResourceBundle getBundle() {
  148 + if (bundle == null) {
  149 + bundle = ResourceBundleProducer.create("demoiselle-core-bundle");
  150 + }
  151 +
  152 + return bundle;
  153 + }
  154 +
  155 + private static Logger getLogger() {
  156 + if (logger == null) {
  157 + logger = LoggerProducer.create(RequiredRoleInterceptor.class);
  158 + }
  159 +
  160 + return logger;
  161 + }
145 } 162 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/TransactionalInterceptor.java
@@ -38,19 +38,21 @@ package br.gov.frameworkdemoiselle.internal.interceptor; @@ -38,19 +38,21 @@ package br.gov.frameworkdemoiselle.internal.interceptor;
38 38
39 import java.io.Serializable; 39 import java.io.Serializable;
40 40
41 -import javax.enterprise.inject.Instance;  
42 -import javax.inject.Inject; 41 +import javax.enterprise.context.ContextNotActiveException;
43 import javax.interceptor.AroundInvoke; 42 import javax.interceptor.AroundInvoke;
44 import javax.interceptor.Interceptor; 43 import javax.interceptor.Interceptor;
45 import javax.interceptor.InvocationContext; 44 import javax.interceptor.InvocationContext;
46 45
47 import org.slf4j.Logger; 46 import org.slf4j.Logger;
48 47
49 -import br.gov.frameworkdemoiselle.annotation.Name;  
50 import br.gov.frameworkdemoiselle.exception.ApplicationException; 48 import br.gov.frameworkdemoiselle.exception.ApplicationException;
51 import br.gov.frameworkdemoiselle.internal.implementation.TransactionInfo; 49 import br.gov.frameworkdemoiselle.internal.implementation.TransactionInfo;
  50 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  51 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
52 import br.gov.frameworkdemoiselle.transaction.Transaction; 52 import br.gov.frameworkdemoiselle.transaction.Transaction;
  53 +import br.gov.frameworkdemoiselle.transaction.TransactionContext;
53 import br.gov.frameworkdemoiselle.transaction.Transactional; 54 import br.gov.frameworkdemoiselle.transaction.Transactional;
  55 +import br.gov.frameworkdemoiselle.util.Beans;
54 import br.gov.frameworkdemoiselle.util.ResourceBundle; 56 import br.gov.frameworkdemoiselle.util.ResourceBundle;
55 57
56 @Interceptor 58 @Interceptor
@@ -59,22 +61,49 @@ public class TransactionalInterceptor implements Serializable { @@ -59,22 +61,49 @@ public class TransactionalInterceptor implements Serializable {
59 61
60 private static final long serialVersionUID = 1L; 62 private static final long serialVersionUID = 1L;
61 63
62 - private final Instance<Transaction> transaction; 64 + private TransactionContext transactionContext;
63 65
64 - private final Logger logger; 66 + private TransactionInfo transactionInfo;
65 67
66 - private final ResourceBundle bundle; 68 + private static ResourceBundle bundle;
67 69
68 - private final Instance<TransactionInfo> transactionInfo; 70 + private static Logger logger;
69 71
70 - @Inject  
71 - public TransactionalInterceptor(Instance<Transaction> transaction, Instance<TransactionInfo> transactionInfo,  
72 - Logger logger, @Name("demoiselle-core-bundle") ResourceBundle bundle) {  
73 - this.transaction = transaction;  
74 - this.transactionInfo = transactionInfo;  
75 - this.logger = logger;  
76 - this.bundle = bundle; 72 + private TransactionContext getTransactionContext() {
  73 + if (this.transactionContext == null) {
  74 + this.transactionContext = Beans.getReference(TransactionContext.class);
  75 + }
  76 +
  77 + return this.transactionContext;
  78 + }
  79 +
  80 + private TransactionInfo newTransactionInfo() {
  81 + TransactionInfo instance;
  82 +
  83 + try {
  84 + instance = Beans.getReference(TransactionInfo.class);
  85 +
  86 + } catch (ContextNotActiveException cause) {
  87 + instance = new TransactionInfo() {
  88 +
  89 + private static final long serialVersionUID = 1L;
  90 +
  91 + @Override
  92 + public boolean isOwner() {
  93 + return false;
  94 + }
  95 + };
  96 + }
  97 +
  98 + return instance;
  99 + }
  100 +
  101 + private TransactionInfo getTransactionInfo() {
  102 + if (this.transactionInfo == null) {
  103 + this.transactionInfo = newTransactionInfo();
  104 + }
77 105
  106 + return this.transactionInfo;
78 } 107 }
79 108
80 @AroundInvoke 109 @AroundInvoke
@@ -83,9 +112,7 @@ public class TransactionalInterceptor implements Serializable { @@ -83,9 +112,7 @@ public class TransactionalInterceptor implements Serializable {
83 112
84 Object result = null; 113 Object result = null;
85 try { 114 try {
86 - this.logger.debug(bundle.getString("transactional-execution", ic.getMethod().toGenericString()));  
87 - transactionInfo.get().incrementCounter();  
88 - 115 + getLogger().debug(getBundle().getString("transactional-execution", ic.getMethod().toGenericString()));
89 result = ic.proceed(); 116 result = ic.proceed();
90 117
91 } catch (Exception cause) { 118 } catch (Exception cause) {
@@ -93,7 +120,6 @@ public class TransactionalInterceptor implements Serializable { @@ -93,7 +120,6 @@ public class TransactionalInterceptor implements Serializable {
93 throw cause; 120 throw cause;
94 121
95 } finally { 122 } finally {
96 - transactionInfo.get().decrementCounter();  
97 complete(ic); 123 complete(ic);
98 } 124 }
99 125
@@ -101,20 +127,22 @@ public class TransactionalInterceptor implements Serializable { @@ -101,20 +127,22 @@ public class TransactionalInterceptor implements Serializable {
101 } 127 }
102 128
103 private void initiate(final InvocationContext ic) { 129 private void initiate(final InvocationContext ic) {
104 - Transaction tx = this.transaction.get();  
105 - TransactionInfo ctx = this.transactionInfo.get(); 130 + Transaction transaction = getTransactionContext().getCurrentTransaction();
  131 + TransactionInfo transactionInfo = getTransactionInfo();
106 132
107 - if (!tx.isActive()) {  
108 - tx.begin();  
109 - ctx.markAsOwner();  
110 - this.logger.info(bundle.getString("begin-transaction")); 133 + if (!transaction.isActive()) {
  134 + transaction.begin();
  135 + transactionInfo.markAsOwner();
  136 + getLogger().info(getBundle().getString("begin-transaction"));
111 } 137 }
  138 +
  139 + transactionInfo.incrementCounter();
112 } 140 }
113 141
114 private void handleException(final Exception cause) { 142 private void handleException(final Exception cause) {
115 - Transaction tx = this.transaction.get(); 143 + Transaction transaction = getTransactionContext().getCurrentTransaction();
116 144
117 - if (!tx.isMarkedRollback()) { 145 + if (!transaction.isMarkedRollback()) {
118 boolean rollback = false; 146 boolean rollback = false;
119 ApplicationException annotation = cause.getClass().getAnnotation(ApplicationException.class); 147 ApplicationException annotation = cause.getClass().getAnnotation(ApplicationException.class);
120 148
@@ -123,30 +151,52 @@ public class TransactionalInterceptor implements Serializable { @@ -123,30 +151,52 @@ public class TransactionalInterceptor implements Serializable {
123 } 151 }
124 152
125 if (rollback) { 153 if (rollback) {
126 - tx.setRollbackOnly();  
127 - this.logger.info(bundle.getString("transaction-marked-rollback", cause.getMessage())); 154 + transaction.setRollbackOnly();
  155 + getLogger().info(getBundle().getString("transaction-marked-rollback", cause.getMessage()));
128 } 156 }
129 } 157 }
130 } 158 }
131 159
132 private void complete(final InvocationContext ic) { 160 private void complete(final InvocationContext ic) {
133 - Transaction tx = this.transaction.get();  
134 - TransactionInfo ctx = this.transactionInfo.get(); 161 + Transaction transaction = getTransactionContext().getCurrentTransaction();
  162 + TransactionInfo transactionInfo = getTransactionInfo();
  163 + transactionInfo.decrementCounter();
  164 +
  165 + if (transactionInfo.getCounter() == 0 && transaction.isActive()) {
135 166
136 - if (ctx.getCounter() == 0 && tx.isActive()) { 167 + if (transactionInfo.isOwner()) {
  168 + if (transaction.isMarkedRollback()) {
  169 + transaction.rollback();
  170 + transactionInfo.clear();
  171 +
  172 + getLogger().info(getBundle().getString("transaction-rolledback"));
137 173
138 - if (ctx.isOwner()) {  
139 - if (tx.isMarkedRollback()) {  
140 - tx.rollback();  
141 - this.logger.info(bundle.getString("transaction-rolledback"));  
142 } else { 174 } else {
143 - tx.commit();  
144 - this.logger.info(bundle.getString("transaction-commited")); 175 + transaction.commit();
  176 + transactionInfo.clear();
  177 +
  178 + getLogger().info(getBundle().getString("transaction-commited"));
145 } 179 }
146 } 180 }
147 181
148 - } else if (ctx.getCounter() == 0 && !tx.isActive()) {  
149 - this.logger.info(bundle.getString("transaction-already-finalized")); 182 + } else if (transactionInfo.getCounter() == 0 && !transaction.isActive()) {
  183 + getLogger().info(getBundle().getString("transaction-already-finalized"));
  184 + }
  185 + }
  186 +
  187 + private static ResourceBundle getBundle() {
  188 + if (bundle == null) {
  189 + bundle = ResourceBundleProducer.create("demoiselle-core-bundle");
150 } 190 }
  191 +
  192 + return bundle;
  193 + }
  194 +
  195 + private static Logger getLogger() {
  196 + if (logger == null) {
  197 + logger = LoggerProducer.create(TransactionalInterceptor.class);
  198 + }
  199 +
  200 + return logger;
151 } 201 }
152 } 202 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/AbstractProcessor.java
@@ -1,121 +0,0 @@ @@ -1,121 +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.processor;  
38 -  
39 -import java.util.Locale;  
40 -  
41 -import javax.enterprise.inject.spi.AnnotatedCallable;  
42 -import javax.enterprise.inject.spi.Bean;  
43 -import javax.enterprise.inject.spi.BeanManager;  
44 -  
45 -import org.slf4j.Logger;  
46 -  
47 -import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;  
48 -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;  
49 -import br.gov.frameworkdemoiselle.util.ResourceBundle;  
50 -  
51 -/**  
52 - * It abstract the integration between Processor and the context;  
53 - *  
54 - * @param <DC>  
55 - * the declaring class  
56 - */  
57 -public abstract class AbstractProcessor<DC> implements Processor {  
58 -  
59 - private BeanManager beanManager;  
60 -  
61 - private AnnotatedCallable<DC> annotatedCallable;  
62 -  
63 - private ResourceBundleProducer bundleFactory = new ResourceBundleProducer();  
64 -  
65 - private ResourceBundle bundle;  
66 -  
67 - protected static final String BUNDLE_BASE_NAME = "demoiselle-core-bundle";  
68 -  
69 - public AbstractProcessor(final BeanManager beanManager) {  
70 - this.beanManager = beanManager;  
71 - }  
72 -  
73 - public AbstractProcessor(final AnnotatedCallable<DC> annotatedCallable, final BeanManager beanManager) {  
74 - this.annotatedCallable = annotatedCallable;  
75 - this.beanManager = beanManager;  
76 - }  
77 -  
78 - protected AnnotatedCallable<DC> getAnnotatedCallable() {  
79 - return this.annotatedCallable;  
80 - }  
81 -  
82 - protected BeanManager getBeanManager() {  
83 - return this.beanManager;  
84 - }  
85 -  
86 - /**  
87 - * Ask the bean manager for the firt instance of the declaring classe for this java member, then returns the current  
88 - * reference;  
89 - *  
90 - * @param <T>  
91 - * DeclaringClass  
92 - * @return  
93 - */  
94 - @SuppressWarnings("unchecked")  
95 - protected DC getReferencedBean() {  
96 - Class<DC> classType = (Class<DC>) getAnnotatedCallable().getJavaMember().getDeclaringClass();  
97 - return getReferencedBean(classType);  
98 - }  
99 -  
100 - @SuppressWarnings("unchecked")  
101 - protected DC getReferencedBean(final Class<DC> type) {  
102 - Bean<DC> bean = (Bean<DC>) beanManager.getBeans(type).iterator().next();  
103 - return (DC) beanManager.getReference(bean, type, beanManager.createCreationalContext(bean));  
104 - }  
105 -  
106 - protected ResourceBundle getBundle() {  
107 - return getBundle(BUNDLE_BASE_NAME);  
108 - }  
109 -  
110 - protected ResourceBundle getBundle(String baseName) {  
111 - if (bundle == null) {  
112 - bundle = bundleFactory.create(baseName, Locale.getDefault());  
113 - }  
114 -  
115 - return bundle;  
116 - }  
117 -  
118 - protected Logger getLogger() {  
119 - return LoggerProducer.create(this.getClass());  
120 - }  
121 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/AnnotatedMethodProcessor.java
@@ -1,105 +0,0 @@ @@ -1,105 +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.processor;  
38 -  
39 -import java.lang.reflect.InvocationTargetException;  
40 -  
41 -import javax.enterprise.inject.spi.AnnotatedMethod;  
42 -import javax.enterprise.inject.spi.BeanManager;  
43 -  
44 -import br.gov.frameworkdemoiselle.exception.ApplicationException;  
45 -import br.gov.frameworkdemoiselle.message.SeverityType;  
46 -  
47 -/**  
48 - * Represents an annotated method to be processed;  
49 - *  
50 - * @param <DC>  
51 - * declaring class owner of the method  
52 - */  
53 -public class AnnotatedMethodProcessor<DC> extends AbstractProcessor<DC> {  
54 -  
55 - public AnnotatedMethodProcessor(final AnnotatedMethod<DC> annotatedMethod, final BeanManager beanManager) {  
56 - super(annotatedMethod, beanManager);  
57 - }  
58 -  
59 - protected AnnotatedMethod<DC> getAnnotatedMethod() {  
60 - return (AnnotatedMethod<DC>) getAnnotatedCallable();  
61 - }  
62 -  
63 - public boolean process(Object... args) throws Throwable {  
64 - getLogger().info(getBundle().getString("processing", getAnnotatedMethod().getJavaMember().toGenericString()));  
65 -  
66 - try {  
67 - getAnnotatedMethod().getJavaMember().invoke(getReferencedBean(), args);  
68 -  
69 - } catch (InvocationTargetException cause) {  
70 - handleException(cause.getCause());  
71 - }  
72 -  
73 - return true;  
74 - }  
75 -  
76 - private void handleException(Throwable cause) throws Throwable {  
77 - ApplicationException ann = cause.getClass().getAnnotation(ApplicationException.class);  
78 -  
79 - if (ann == null || SeverityType.FATAL == ann.severity()) {  
80 - throw cause;  
81 -  
82 - } else {  
83 - switch (ann.severity()) {  
84 - case INFO:  
85 - getLogger().info(cause.getMessage());  
86 - break;  
87 -  
88 - case WARN:  
89 - getLogger().warn(cause.getMessage());  
90 - break;  
91 -  
92 - default:  
93 - getLogger().error(getBundle().getString("processing-fail"), cause);  
94 - break;  
95 - }  
96 - }  
97 - }  
98 -  
99 - @Override  
100 - public String toString() {  
101 - return getBundle().getString("for", getClass().getSimpleName(),  
102 - getAnnotatedMethod().getJavaMember().toGenericString());  
103 - }  
104 -  
105 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/Processor.java
@@ -1,45 +0,0 @@ @@ -1,45 +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.processor;  
38 -  
39 -/**  
40 - * Represents an classe that can be processed.  
41 - */  
42 -public interface Processor {  
43 -  
44 - public boolean process(Object... args) throws Throwable;  
45 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/ShutdownProcessor.java
@@ -1,63 +0,0 @@ @@ -1,63 +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.processor;  
38 -  
39 -import javax.enterprise.inject.spi.AnnotatedMethod;  
40 -import javax.enterprise.inject.spi.BeanManager;  
41 -  
42 -import br.gov.frameworkdemoiselle.annotation.Shutdown;  
43 -  
44 -public class ShutdownProcessor<T> extends AnnotatedMethodProcessor<T> implements Comparable<ShutdownProcessor<T>> {  
45 -  
46 - public ShutdownProcessor(AnnotatedMethod<T> annotatedMethod, BeanManager beanManager) {  
47 - super(annotatedMethod, beanManager);  
48 - }  
49 -  
50 - @Override  
51 - public int compareTo(final ShutdownProcessor<T> other) {  
52 - int result = 0;  
53 - Shutdown annotationThis = getAnnotatedMethod().getAnnotation(Shutdown.class);  
54 - Shutdown annotationOther = other.getAnnotatedMethod().getAnnotation(Shutdown.class);  
55 - if (annotationThis != null && annotationThis != null) {  
56 - Integer orderThis = annotationThis.priority();  
57 - Integer orderOther = annotationOther.priority();  
58 - result = orderThis.compareTo(orderOther);  
59 - }  
60 - return result;  
61 - }  
62 -  
63 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/StartupProcessor.java
@@ -1,68 +0,0 @@ @@ -1,68 +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.processor;  
38 -  
39 -import javax.enterprise.inject.spi.AnnotatedMethod;  
40 -import javax.enterprise.inject.spi.BeanManager;  
41 -  
42 -import br.gov.frameworkdemoiselle.annotation.Startup;  
43 -  
44 -/**  
45 - * Processor for a {@code @Startup} annotated method, making it comparable.  
46 - *  
47 - * @param <T>  
48 - */  
49 -public class StartupProcessor<T> extends AnnotatedMethodProcessor<T> implements Comparable<StartupProcessor<T>> {  
50 -  
51 - public StartupProcessor(final AnnotatedMethod<T> annotatedMethod, final BeanManager beanManager) {  
52 - super(annotatedMethod, beanManager);  
53 - }  
54 -  
55 - @Override  
56 - public int compareTo(final StartupProcessor<T> other) {  
57 - int result = 0;  
58 - Startup annotationThis = getAnnotatedMethod().getAnnotation(Startup.class);  
59 - Startup annotationOther = other.getAnnotatedMethod().getAnnotation(Startup.class);  
60 - if (annotationThis != null && annotationOther != null) {  
61 - Integer orderThis = annotationThis.priority();  
62 - Integer orderOther = annotationOther.priority();  
63 - result = orderThis.compareTo(orderOther);  
64 - }  
65 - return result;  
66 - }  
67 -  
68 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ContextProducer.java
@@ -1,84 +0,0 @@ @@ -1,84 +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 -/*  
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.io.Serializable;  
52 -  
53 -import javax.enterprise.inject.Default;  
54 -import javax.enterprise.inject.Produces;  
55 -import javax.naming.Context;  
56 -import javax.naming.InitialContext;  
57 -import javax.naming.NamingException;  
58 -  
59 -import br.gov.frameworkdemoiselle.DemoiselleException;  
60 -import br.gov.frameworkdemoiselle.internal.proxy.ContextProxy;  
61 -  
62 -public class ContextProducer implements Serializable {  
63 -  
64 - private static final long serialVersionUID = 1L;  
65 -  
66 - // @Inject  
67 - // @Name("demoiselle-core-bundle")  
68 - // private ResourceBundle bundle;  
69 -  
70 - @Produces  
71 - @Default  
72 - public static Context create() {  
73 - Context context = null;  
74 -  
75 - try {  
76 - context = new ContextProxy(new InitialContext());  
77 -  
78 - } catch (NamingException cause) {  
79 - throw new DemoiselleException("Erro ao criar InitialContext", cause);  
80 - }  
81 -  
82 - return context;  
83 - }  
84 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/LocaleProducer.java
@@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
1 -package br.gov.frameworkdemoiselle.internal.producer;  
2 -  
3 -import java.util.Locale;  
4 -  
5 -import javax.enterprise.inject.Default;  
6 -import javax.enterprise.inject.Produces;  
7 -  
8 -public class LocaleProducer {  
9 -  
10 - @Produces  
11 - @Default  
12 - public Locale create() {  
13 - return Locale.getDefault();  
14 - }  
15 -  
16 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/LoggerProducer.java
@@ -55,7 +55,6 @@ import javax.enterprise.inject.Produces; @@ -55,7 +55,6 @@ import javax.enterprise.inject.Produces;
55 import javax.enterprise.inject.spi.InjectionPoint; 55 import javax.enterprise.inject.spi.InjectionPoint;
56 56
57 import org.slf4j.Logger; 57 import org.slf4j.Logger;
58 -import org.slf4j.LoggerFactory;  
59 58
60 import br.gov.frameworkdemoiselle.internal.proxy.Slf4jLoggerProxy; 59 import br.gov.frameworkdemoiselle.internal.proxy.Slf4jLoggerProxy;
61 60
@@ -78,6 +77,6 @@ public class LoggerProducer implements Serializable { @@ -78,6 +77,6 @@ public class LoggerProducer implements Serializable {
78 } 77 }
79 78
80 public static <T> Logger create(Class<T> type) { 79 public static <T> Logger create(Class<T> type) {
81 - return new Slf4jLoggerProxy(LoggerFactory.getLogger(type)); 80 + return new Slf4jLoggerProxy(type);
82 } 81 }
83 } 82 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducer.java
@@ -38,14 +38,13 @@ package br.gov.frameworkdemoiselle.internal.producer; @@ -38,14 +38,13 @@ package br.gov.frameworkdemoiselle.internal.producer;
38 38
39 import java.io.Serializable; 39 import java.io.Serializable;
40 import java.util.Locale; 40 import java.util.Locale;
41 -import java.util.MissingResourceException;  
42 41
43 import javax.enterprise.inject.Default; 42 import javax.enterprise.inject.Default;
44 import javax.enterprise.inject.Produces; 43 import javax.enterprise.inject.Produces;
45 import javax.enterprise.inject.spi.InjectionPoint; 44 import javax.enterprise.inject.spi.InjectionPoint;
46 45
47 -import br.gov.frameworkdemoiselle.DemoiselleException;  
48 import br.gov.frameworkdemoiselle.annotation.Name; 46 import br.gov.frameworkdemoiselle.annotation.Name;
  47 +import br.gov.frameworkdemoiselle.util.Beans;
49 import br.gov.frameworkdemoiselle.util.ResourceBundle; 48 import br.gov.frameworkdemoiselle.util.ResourceBundle;
50 49
51 /** 50 /**
@@ -63,17 +62,19 @@ public class ResourceBundleProducer implements Serializable { @@ -63,17 +62,19 @@ public class ResourceBundleProducer implements Serializable {
63 * @param String 62 * @param String
64 * baseName 63 * baseName
65 */ 64 */
66 - public ResourceBundle create(String baseName, Locale locale) {  
67 - ResourceBundle bundle = null;  
68 -  
69 - try {  
70 - ClassLoader classLoader = Thread.currentThread().getContextClassLoader();  
71 - bundle = new ResourceBundle(ResourceBundle.getBundle(baseName, locale, classLoader));  
72 -  
73 - } catch (MissingResourceException e) {  
74 - throw new DemoiselleException("File " + baseName + " not found!");  
75 - } 65 + public static ResourceBundle create(String baseName) {
  66 + return create(baseName, Beans.getReference(Locale.class));
  67 + }
76 68
  69 + /**
  70 + * This method should be used by classes that can not inject ResourceBundle, to create the ResourceBundle.
  71 + *
  72 + * @param String
  73 + * baseName
  74 + */
  75 + public static ResourceBundle create(String baseName, Locale locale) {
  76 + ResourceBundle bundle = null;
  77 + bundle = new ResourceBundle(baseName, locale);
77 return bundle; 78 return bundle;
78 } 79 }
79 80
@@ -83,7 +84,7 @@ public class ResourceBundleProducer implements Serializable { @@ -83,7 +84,7 @@ public class ResourceBundleProducer implements Serializable {
83 */ 84 */
84 @Produces 85 @Produces
85 @Default 86 @Default
86 - public ResourceBundle create(InjectionPoint ip, Locale locale) { 87 + public ResourceBundle create(InjectionPoint ip) {
87 String baseName; 88 String baseName;
88 89
89 if (ip != null && ip.getAnnotated().isAnnotationPresent(Name.class)) { 90 if (ip != null && ip.getAnnotated().isAnnotationPresent(Name.class)) {
@@ -92,6 +93,6 @@ public class ResourceBundleProducer implements Serializable { @@ -92,6 +93,6 @@ public class ResourceBundleProducer implements Serializable {
92 baseName = "messages"; 93 baseName = "messages";
93 } 94 }
94 95
95 - return create(baseName, locale); 96 + return create(baseName, Beans.getReference(Locale.class));
96 } 97 }
97 } 98 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/ContextProxy.java
@@ -1,168 +0,0 @@ @@ -1,168 +0,0 @@
1 -package br.gov.frameworkdemoiselle.internal.proxy;  
2 -  
3 -import java.io.Serializable;  
4 -import java.util.Hashtable;  
5 -  
6 -import javax.naming.Binding;  
7 -import javax.naming.Context;  
8 -import javax.naming.Name;  
9 -import javax.naming.NameClassPair;  
10 -import javax.naming.NameParser;  
11 -import javax.naming.NamingEnumeration;  
12 -import javax.naming.NamingException;  
13 -  
14 -public class ContextProxy implements Context, Serializable {  
15 -  
16 - private static final long serialVersionUID = 1L;  
17 -  
18 - private final Context delegate;  
19 -  
20 - public ContextProxy(Context delegate) {  
21 - this.delegate = delegate;  
22 - }  
23 -  
24 - @Override  
25 - public Object addToEnvironment(String propName, Object propVal) throws NamingException {  
26 - return delegate.addToEnvironment(propName, propVal);  
27 - }  
28 -  
29 - @Override  
30 - public void bind(Name name, Object obj) throws NamingException {  
31 - delegate.bind(name, obj);  
32 - }  
33 -  
34 - @Override  
35 - public void bind(String name, Object obj) throws NamingException {  
36 - delegate.bind(name, obj);  
37 - }  
38 -  
39 - @Override  
40 - public void close() throws NamingException {  
41 - delegate.close();  
42 - }  
43 -  
44 - @Override  
45 - public Name composeName(Name name, Name prefix) throws NamingException {  
46 - return delegate.composeName(name, prefix);  
47 - }  
48 -  
49 - @Override  
50 - public String composeName(String name, String prefix) throws NamingException {  
51 - return delegate.composeName(name, prefix);  
52 - }  
53 -  
54 - @Override  
55 - public Context createSubcontext(Name name) throws NamingException {  
56 - return delegate.createSubcontext(name);  
57 - }  
58 -  
59 - @Override  
60 - public Context createSubcontext(String name) throws NamingException {  
61 - return delegate.createSubcontext(name);  
62 - }  
63 -  
64 - @Override  
65 - public void destroySubcontext(Name name) throws NamingException {  
66 - delegate.destroySubcontext(name);  
67 - }  
68 -  
69 - @Override  
70 - public void destroySubcontext(String name) throws NamingException {  
71 - delegate.destroySubcontext(name);  
72 - }  
73 -  
74 - @Override  
75 - public Hashtable<?, ?> getEnvironment() throws NamingException {  
76 - return delegate.getEnvironment();  
77 - }  
78 -  
79 - @Override  
80 - public String getNameInNamespace() throws NamingException {  
81 - return delegate.getNameInNamespace();  
82 - }  
83 -  
84 - @Override  
85 - public NameParser getNameParser(Name name) throws NamingException {  
86 - return delegate.getNameParser(name);  
87 - }  
88 -  
89 - @Override  
90 - public NameParser getNameParser(String name) throws NamingException {  
91 - return delegate.getNameParser(name);  
92 - }  
93 -  
94 - @Override  
95 - public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {  
96 - return delegate.list(name);  
97 - }  
98 -  
99 - @Override  
100 - public NamingEnumeration<NameClassPair> list(String name) throws NamingException {  
101 - return delegate.list(name);  
102 - }  
103 -  
104 - @Override  
105 - public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {  
106 - return delegate.listBindings(name);  
107 - }  
108 -  
109 - @Override  
110 - public NamingEnumeration<Binding> listBindings(String name) throws NamingException {  
111 - return delegate.listBindings(name);  
112 - }  
113 -  
114 - @Override  
115 - public Object lookup(Name name) throws NamingException {  
116 - return delegate.lookup(name);  
117 - }  
118 -  
119 - @Override  
120 - public Object lookup(String name) throws NamingException {  
121 - return delegate.lookup(name);  
122 - }  
123 -  
124 - @Override  
125 - public Object lookupLink(Name name) throws NamingException {  
126 - return delegate.lookupLink(name);  
127 - }  
128 -  
129 - @Override  
130 - public Object lookupLink(String name) throws NamingException {  
131 - return delegate.lookupLink(name);  
132 - }  
133 -  
134 - @Override  
135 - public void rebind(Name name, Object obj) throws NamingException {  
136 - delegate.rebind(name, obj);  
137 - }  
138 -  
139 - @Override  
140 - public void rebind(String name, Object obj) throws NamingException {  
141 - delegate.rebind(name, obj);  
142 - }  
143 -  
144 - @Override  
145 - public Object removeFromEnvironment(String propName) throws NamingException {  
146 - return delegate.removeFromEnvironment(propName);  
147 - }  
148 -  
149 - @Override  
150 - public void rename(Name oldName, Name newName) throws NamingException {  
151 - delegate.rename(oldName, newName);  
152 - }  
153 -  
154 - @Override  
155 - public void rename(String oldName, String newName) throws NamingException {  
156 - delegate.rename(oldName, newName);  
157 - }  
158 -  
159 - @Override  
160 - public void unbind(Name name) throws NamingException {  
161 - delegate.unbind(name);  
162 - }  
163 -  
164 - @Override  
165 - public void unbind(String name) throws NamingException {  
166 - delegate.unbind(name);  
167 - }  
168 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/Slf4jLoggerProxy.java
@@ -51,321 +51,332 @@ package br.gov.frameworkdemoiselle.internal.proxy; @@ -51,321 +51,332 @@ package br.gov.frameworkdemoiselle.internal.proxy;
51 import java.io.Serializable; 51 import java.io.Serializable;
52 52
53 import org.slf4j.Logger; 53 import org.slf4j.Logger;
  54 +import org.slf4j.LoggerFactory;
54 import org.slf4j.Marker; 55 import org.slf4j.Marker;
55 56
56 public class Slf4jLoggerProxy implements Logger, Serializable { 57 public class Slf4jLoggerProxy implements Logger, Serializable {
57 58
58 private static final long serialVersionUID = 1L; 59 private static final long serialVersionUID = 1L;
59 60
60 - private transient final Logger delegate; 61 + private transient Logger delegate;
61 62
62 - public Slf4jLoggerProxy(final Logger logger) {  
63 - this.delegate = logger; 63 + private final Class<?> type;
  64 +
  65 + private Logger getDelegate() {
  66 + if(delegate == null) {
  67 + delegate = LoggerFactory.getLogger(type);
  68 + }
  69 +
  70 + return delegate;
  71 + }
  72 +
  73 + public Slf4jLoggerProxy(final Class<?> type) {
  74 + this.type = type;
64 } 75 }
65 76
66 @Override 77 @Override
67 public void debug(final Marker marker, final String msg) { 78 public void debug(final Marker marker, final String msg) {
68 - this.delegate.debug(marker, msg); 79 + getDelegate().debug(marker, msg);
69 } 80 }
70 81
71 @Override 82 @Override
72 public void debug(final Marker marker, final String format, final Object arg) { 83 public void debug(final Marker marker, final String format, final Object arg) {
73 - this.delegate.debug(marker, format, arg); 84 + getDelegate().debug(marker, format, arg);
74 } 85 }
75 86
76 @Override 87 @Override
77 public void debug(final Marker marker, final String format, final Object arg1, final Object arg2) { 88 public void debug(final Marker marker, final String format, final Object arg1, final Object arg2) {
78 - this.delegate.debug(marker, format, arg1, arg2); 89 + getDelegate().debug(marker, format, arg1, arg2);
79 } 90 }
80 91
81 @Override 92 @Override
82 public void debug(final Marker marker, final String format, final Object[] argArray) { 93 public void debug(final Marker marker, final String format, final Object[] argArray) {
83 - this.delegate.debug(marker, format, argArray); 94 + getDelegate().debug(marker, format, argArray);
84 } 95 }
85 96
86 @Override 97 @Override
87 public void debug(final Marker marker, final String msg, final Throwable t) { 98 public void debug(final Marker marker, final String msg, final Throwable t) {
88 - this.delegate.debug(marker, msg, t); 99 + getDelegate().debug(marker, msg, t);
89 } 100 }
90 101
91 @Override 102 @Override
92 public void debug(final String msg) { 103 public void debug(final String msg) {
93 - this.delegate.debug(msg); 104 + getDelegate().debug(msg);
94 } 105 }
95 106
96 @Override 107 @Override
97 public void debug(final String format, final Object arg) { 108 public void debug(final String format, final Object arg) {
98 - this.delegate.debug(format, arg); 109 + getDelegate().debug(format, arg);
99 } 110 }
100 111
101 @Override 112 @Override
102 public void debug(final String format, final Object arg1, final Object arg2) { 113 public void debug(final String format, final Object arg1, final Object arg2) {
103 - this.delegate.debug(format, arg1, arg2); 114 + getDelegate().debug(format, arg1, arg2);
104 } 115 }
105 116
106 @Override 117 @Override
107 public void debug(final String format, final Object[] argArray) { 118 public void debug(final String format, final Object[] argArray) {
108 - this.delegate.debug(format, argArray); 119 + getDelegate().debug(format, argArray);
109 } 120 }
110 121
111 @Override 122 @Override
112 public void debug(final String msg, final Throwable t) { 123 public void debug(final String msg, final Throwable t) {
113 - this.delegate.debug(msg, t); 124 + getDelegate().debug(msg, t);
114 } 125 }
115 126
116 @Override 127 @Override
117 public void error(final Marker marker, final String msg) { 128 public void error(final Marker marker, final String msg) {
118 - this.delegate.error(marker, msg); 129 + getDelegate().error(marker, msg);
119 } 130 }
120 131
121 @Override 132 @Override
122 public void error(final Marker marker, final String format, final Object arg) { 133 public void error(final Marker marker, final String format, final Object arg) {
123 - this.delegate.error(marker, format, arg); 134 + getDelegate().error(marker, format, arg);
124 } 135 }
125 136
126 @Override 137 @Override
127 public void error(final Marker marker, final String format, final Object arg1, final Object arg2) { 138 public void error(final Marker marker, final String format, final Object arg1, final Object arg2) {
128 - this.delegate.error(marker, format, arg1, arg2); 139 + getDelegate().error(marker, format, arg1, arg2);
129 } 140 }
130 141
131 @Override 142 @Override
132 public void error(final Marker marker, final String format, final Object[] argArray) { 143 public void error(final Marker marker, final String format, final Object[] argArray) {
133 - this.delegate.error(marker, format, argArray); 144 + getDelegate().error(marker, format, argArray);
134 } 145 }
135 146
136 @Override 147 @Override
137 public void error(final Marker marker, final String msg, final Throwable t) { 148 public void error(final Marker marker, final String msg, final Throwable t) {
138 - this.delegate.error(marker, msg, t); 149 + getDelegate().error(marker, msg, t);
139 } 150 }
140 151
141 @Override 152 @Override
142 public void error(final String msg) { 153 public void error(final String msg) {
143 - this.delegate.error(msg); 154 + getDelegate().error(msg);
144 } 155 }
145 156
146 @Override 157 @Override
147 public void error(final String format, final Object arg) { 158 public void error(final String format, final Object arg) {
148 - this.delegate.error(format, arg); 159 + getDelegate().error(format, arg);
149 } 160 }
150 161
151 @Override 162 @Override
152 public void error(final String format, final Object arg1, final Object arg2) { 163 public void error(final String format, final Object arg1, final Object arg2) {
153 - this.delegate.error(format, arg1, arg2); 164 + getDelegate().error(format, arg1, arg2);
154 } 165 }
155 166
156 @Override 167 @Override
157 public void error(final String format, final Object[] argArray) { 168 public void error(final String format, final Object[] argArray) {
158 - this.delegate.error(format, argArray); 169 + getDelegate().error(format, argArray);
159 } 170 }
160 171
161 @Override 172 @Override
162 public void error(final String msg, final Throwable t) { 173 public void error(final String msg, final Throwable t) {
163 - this.delegate.error(msg, t); 174 + getDelegate().error(msg, t);
164 } 175 }
165 176
166 @Override 177 @Override
167 public String getName() { 178 public String getName() {
168 - return this.delegate.getName(); 179 + return getDelegate().getName();
169 } 180 }
170 181
171 @Override 182 @Override
172 public void info(final Marker marker, final String msg) { 183 public void info(final Marker marker, final String msg) {
173 - this.delegate.info(marker, msg); 184 + getDelegate().info(marker, msg);
174 } 185 }
175 186
176 @Override 187 @Override
177 public void info(final Marker marker, final String format, final Object arg) { 188 public void info(final Marker marker, final String format, final Object arg) {
178 - this.delegate.info(marker, format, arg); 189 + getDelegate().info(marker, format, arg);
179 } 190 }
180 191
181 @Override 192 @Override
182 public void info(final Marker marker, final String format, final Object arg1, final Object arg2) { 193 public void info(final Marker marker, final String format, final Object arg1, final Object arg2) {
183 - this.delegate.info(marker, format, arg1, arg2); 194 + getDelegate().info(marker, format, arg1, arg2);
184 } 195 }
185 196
186 @Override 197 @Override
187 public void info(final Marker marker, final String format, final Object[] argArray) { 198 public void info(final Marker marker, final String format, final Object[] argArray) {
188 - this.delegate.info(marker, format, argArray); 199 + getDelegate().info(marker, format, argArray);
189 } 200 }
190 201
191 @Override 202 @Override
192 public void info(final Marker marker, final String msg, final Throwable t) { 203 public void info(final Marker marker, final String msg, final Throwable t) {
193 - this.delegate.info(marker, msg, t); 204 + getDelegate().info(marker, msg, t);
194 } 205 }
195 206
196 @Override 207 @Override
197 public void info(final String msg) { 208 public void info(final String msg) {
198 - this.delegate.info(msg); 209 + getDelegate().info(msg);
199 } 210 }
200 211
201 @Override 212 @Override
202 public void info(final String format, final Object arg) { 213 public void info(final String format, final Object arg) {
203 - this.delegate.info(format, arg); 214 + getDelegate().info(format, arg);
204 } 215 }
205 216
206 @Override 217 @Override
207 public void info(final String format, final Object arg1, final Object arg2) { 218 public void info(final String format, final Object arg1, final Object arg2) {
208 - this.delegate.info(format, arg1, arg2); 219 + getDelegate().info(format, arg1, arg2);
209 } 220 }
210 221
211 @Override 222 @Override
212 public void info(final String format, final Object[] argArray) { 223 public void info(final String format, final Object[] argArray) {
213 - this.delegate.info(format, argArray); 224 + getDelegate().info(format, argArray);
214 } 225 }
215 226
216 @Override 227 @Override
217 public void info(final String msg, final Throwable t) { 228 public void info(final String msg, final Throwable t) {
218 - this.delegate.info(msg, t); 229 + getDelegate().info(msg, t);
219 } 230 }
220 231
221 @Override 232 @Override
222 public boolean isDebugEnabled() { 233 public boolean isDebugEnabled() {
223 - return this.delegate.isDebugEnabled(); 234 + return getDelegate().isDebugEnabled();
224 } 235 }
225 236
226 @Override 237 @Override
227 public boolean isDebugEnabled(final Marker marker) { 238 public boolean isDebugEnabled(final Marker marker) {
228 - return this.delegate.isDebugEnabled(marker); 239 + return getDelegate().isDebugEnabled(marker);
229 } 240 }
230 241
231 @Override 242 @Override
232 public boolean isErrorEnabled() { 243 public boolean isErrorEnabled() {
233 - return this.delegate.isErrorEnabled(); 244 + return getDelegate().isErrorEnabled();
234 } 245 }
235 246
236 @Override 247 @Override
237 public boolean isErrorEnabled(final Marker marker) { 248 public boolean isErrorEnabled(final Marker marker) {
238 - return this.delegate.isErrorEnabled(marker); 249 + return getDelegate().isErrorEnabled(marker);
239 } 250 }
240 251
241 @Override 252 @Override
242 public boolean isInfoEnabled() { 253 public boolean isInfoEnabled() {
243 - return this.delegate.isInfoEnabled(); 254 + return getDelegate().isInfoEnabled();
244 } 255 }
245 256
246 @Override 257 @Override
247 public boolean isInfoEnabled(final Marker marker) { 258 public boolean isInfoEnabled(final Marker marker) {
248 - return this.delegate.isInfoEnabled(marker); 259 + return getDelegate().isInfoEnabled(marker);
249 } 260 }
250 261
251 @Override 262 @Override
252 public boolean isTraceEnabled() { 263 public boolean isTraceEnabled() {
253 - return this.delegate.isTraceEnabled(); 264 + return getDelegate().isTraceEnabled();
254 } 265 }
255 266
256 @Override 267 @Override
257 public boolean isTraceEnabled(final Marker marker) { 268 public boolean isTraceEnabled(final Marker marker) {
258 - return this.delegate.isTraceEnabled(marker); 269 + return getDelegate().isTraceEnabled(marker);
259 } 270 }
260 271
261 @Override 272 @Override
262 public boolean isWarnEnabled() { 273 public boolean isWarnEnabled() {
263 - return this.delegate.isWarnEnabled(); 274 + return getDelegate().isWarnEnabled();
264 } 275 }
265 276
266 @Override 277 @Override
267 public boolean isWarnEnabled(final Marker marker) { 278 public boolean isWarnEnabled(final Marker marker) {
268 - return this.delegate.isWarnEnabled(marker); 279 + return getDelegate().isWarnEnabled(marker);
269 } 280 }
270 281
271 @Override 282 @Override
272 public void trace(final Marker marker, final String msg) { 283 public void trace(final Marker marker, final String msg) {
273 - this.delegate.trace(marker, msg); 284 + getDelegate().trace(marker, msg);
274 } 285 }
275 286
276 @Override 287 @Override
277 public void trace(final Marker marker, final String format, final Object arg) { 288 public void trace(final Marker marker, final String format, final Object arg) {
278 - this.delegate.trace(marker, format, arg); 289 + getDelegate().trace(marker, format, arg);
279 } 290 }
280 291
281 @Override 292 @Override
282 public void trace(final Marker marker, final String format, final Object arg1, final Object arg2) { 293 public void trace(final Marker marker, final String format, final Object arg1, final Object arg2) {
283 - this.delegate.trace(marker, format, arg1, arg2); 294 + getDelegate().trace(marker, format, arg1, arg2);
284 } 295 }
285 296
286 @Override 297 @Override
287 public void trace(final Marker marker, final String format, final Object[] argArray) { 298 public void trace(final Marker marker, final String format, final Object[] argArray) {
288 - this.delegate.trace(marker, format, argArray); 299 + getDelegate().trace(marker, format, argArray);
289 } 300 }
290 301
291 @Override 302 @Override
292 public void trace(final Marker marker, final String msg, final Throwable t) { 303 public void trace(final Marker marker, final String msg, final Throwable t) {
293 - this.delegate.trace(marker, msg, t); 304 + getDelegate().trace(marker, msg, t);
294 } 305 }
295 306
296 @Override 307 @Override
297 public void trace(final String msg) { 308 public void trace(final String msg) {
298 - this.delegate.trace(msg); 309 + getDelegate().trace(msg);
299 } 310 }
300 311
301 @Override 312 @Override
302 public void trace(final String format, final Object arg) { 313 public void trace(final String format, final Object arg) {
303 - this.delegate.trace(format, arg); 314 + getDelegate().trace(format, arg);
304 } 315 }
305 316
306 @Override 317 @Override
307 public void trace(final String format, final Object arg1, final Object arg2) { 318 public void trace(final String format, final Object arg1, final Object arg2) {
308 - this.delegate.trace(format, arg1, arg2); 319 + getDelegate().trace(format, arg1, arg2);
309 } 320 }
310 321
311 @Override 322 @Override
312 public void trace(final String format, final Object[] argArray) { 323 public void trace(final String format, final Object[] argArray) {
313 - this.delegate.trace(format, argArray); 324 + getDelegate().trace(format, argArray);
314 } 325 }
315 326
316 @Override 327 @Override
317 public void trace(final String msg, final Throwable t) { 328 public void trace(final String msg, final Throwable t) {
318 - this.delegate.trace(msg, t); 329 + getDelegate().trace(msg, t);
319 } 330 }
320 331
321 @Override 332 @Override
322 public void warn(final Marker marker, final String msg) { 333 public void warn(final Marker marker, final String msg) {
323 - this.delegate.warn(marker, msg); 334 + getDelegate().warn(marker, msg);
324 } 335 }
325 336
326 @Override 337 @Override
327 public void warn(final Marker marker, final String format, final Object arg) { 338 public void warn(final Marker marker, final String format, final Object arg) {
328 - this.delegate.warn(marker, format, arg); 339 + getDelegate().warn(marker, format, arg);
329 } 340 }
330 341
331 @Override 342 @Override
332 public void warn(final Marker marker, final String format, final Object arg1, final Object arg2) { 343 public void warn(final Marker marker, final String format, final Object arg1, final Object arg2) {
333 - this.delegate.warn(marker, format, arg1, arg2); 344 + getDelegate().warn(marker, format, arg1, arg2);
334 } 345 }
335 346
336 @Override 347 @Override
337 public void warn(final Marker marker, final String format, final Object[] argArray) { 348 public void warn(final Marker marker, final String format, final Object[] argArray) {
338 - this.delegate.warn(marker, format, argArray); 349 + getDelegate().warn(marker, format, argArray);
339 } 350 }
340 351
341 @Override 352 @Override
342 public void warn(final Marker marker, final String msg, final Throwable t) { 353 public void warn(final Marker marker, final String msg, final Throwable t) {
343 - this.delegate.warn(marker, msg, t); 354 + getDelegate().warn(marker, msg, t);
344 } 355 }
345 356
346 @Override 357 @Override
347 public void warn(final String msg) { 358 public void warn(final String msg) {
348 - this.delegate.warn(msg); 359 + getDelegate().warn(msg);
349 } 360 }
350 361
351 @Override 362 @Override
352 public void warn(final String format, final Object arg) { 363 public void warn(final String format, final Object arg) {
353 - this.delegate.warn(format, arg); 364 + getDelegate().warn(format, arg);
354 } 365 }
355 366
356 @Override 367 @Override
357 public void warn(final String format, final Object arg1, final Object arg2) { 368 public void warn(final String format, final Object arg1, final Object arg2) {
358 - this.delegate.warn(format, arg1, arg2); 369 + getDelegate().warn(format, arg1, arg2);
359 } 370 }
360 371
361 @Override 372 @Override
362 public void warn(final String format, final Object[] argArray) { 373 public void warn(final String format, final Object[] argArray) {
363 - this.delegate.warn(format, argArray); 374 + getDelegate().warn(format, argArray);
364 } 375 }
365 376
366 @Override 377 @Override
367 public void warn(final String msg, final Throwable t) { 378 public void warn(final String msg, final Throwable t) {
368 - this.delegate.warn(msg, t); 379 + getDelegate().warn(msg, t);
369 } 380 }
370 381
371 } 382 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/lifecycle/AfterShutdownProccess.java 0 → 100644
@@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
  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.lifecycle;
  38 +
  39 +public interface AfterShutdownProccess {
  40 +
  41 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/lifecycle/AfterStartupProccess.java 0 → 100644
@@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
  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.lifecycle;
  38 +
  39 +public interface AfterStartupProccess {
  40 +
  41 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/lifecycle/Shutdown.java 0 → 100644
@@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
  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.lifecycle;
  38 +
  39 +import static java.lang.annotation.ElementType.METHOD;
  40 +import static java.lang.annotation.RetentionPolicy.RUNTIME;
  41 +
  42 +import java.lang.annotation.Retention;
  43 +import java.lang.annotation.Target;
  44 +
  45 +/**
  46 + * Identifies a method eligible to be executed automatically during <b>application finalization</b>.
  47 + * <p>
  48 + * Take a look at the following usage sample:
  49 + * <p>
  50 + * <blockquote>
  51 + * <pre>
  52 + * public class Finalizer {
  53 + *
  54 + * &#064;Shutdown
  55 + * &#064;Priority(5)
  56 + * public void finalize() {
  57 + * ...
  58 + * }
  59 + * }
  60 + *
  61 + * </pre>
  62 + * </blockquote>
  63 + * <p>
  64 + *
  65 + * @author SERPRO
  66 + */
  67 +@Target(METHOD)
  68 +@Retention(RUNTIME)
  69 +public @interface Shutdown {
  70 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/lifecycle/Startup.java 0 → 100644
@@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
  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.lifecycle;
  38 +
  39 +import static java.lang.annotation.ElementType.METHOD;
  40 +import static java.lang.annotation.RetentionPolicy.RUNTIME;
  41 +
  42 +import java.lang.annotation.Retention;
  43 +import java.lang.annotation.Target;
  44 +
  45 +/**
  46 + * Identifies a method eligible to be executed automatically during <b>application initialization</b>.
  47 + * <p>
  48 + * Take a look at the following usage sample:
  49 + * <p>
  50 + * <blockquote>
  51 + * <pre>
  52 + * public class Finalizer {
  53 + *
  54 + * &#064;Startup
  55 + * &#064;Priority(1)
  56 + * public void init() {
  57 + * ...
  58 + * }
  59 + * }
  60 + *
  61 + * </pre>
  62 + * </blockquote>
  63 + * <p>
  64 + *
  65 + * @author SERPRO
  66 + */
  67 +@Target(METHOD)
  68 +@Retention(RUNTIME)
  69 +public @interface Startup {
  70 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/security/AuthorizationException.java
@@ -36,7 +36,8 @@ @@ -36,7 +36,8 @@
36 */ 36 */
37 package br.gov.frameworkdemoiselle.security; 37 package br.gov.frameworkdemoiselle.security;
38 38
39 -import br.gov.frameworkdemoiselle.internal.implementation.CoreBundle; 39 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
  40 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
40 41
41 /** 42 /**
42 * Thrown when trying to access some resource and/or execute an operation without the proper authorization. 43 * Thrown when trying to access some resource and/or execute an operation without the proper authorization.
@@ -47,6 +48,8 @@ public class AuthorizationException extends SecurityException { @@ -47,6 +48,8 @@ public class AuthorizationException extends SecurityException {
47 48
48 private static final long serialVersionUID = 1L; 49 private static final long serialVersionUID = 1L;
49 50
  51 + private static ResourceBundle bundle;
  52 +
50 /** 53 /**
51 * Constructor with message. 54 * Constructor with message.
52 * 55 *
@@ -58,8 +61,14 @@ public class AuthorizationException extends SecurityException { @@ -58,8 +61,14 @@ public class AuthorizationException extends SecurityException {
58 } 61 }
59 62
60 public AuthorizationException(String resource, String operation) { 63 public AuthorizationException(String resource, String operation) {
61 - // TODO: remove the CoreBundle call  
62 - super(CoreBundle.get().getString("access-denied-ui", resource, operation)); 64 + super(getBundle().getString("access-denied-ui", resource, operation));
63 } 65 }
64 66
  67 + private static ResourceBundle getBundle() {
  68 + if (bundle == null) {
  69 + bundle = ResourceBundleProducer.create("demoiselle-core-bundle");
  70 + }
  71 +
  72 + return bundle;
  73 + }
65 } 74 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/template/DelegateCrud.java
@@ -39,6 +39,8 @@ package br.gov.frameworkdemoiselle.template; @@ -39,6 +39,8 @@ package br.gov.frameworkdemoiselle.template;
39 import java.util.List; 39 import java.util.List;
40 import java.util.ListIterator; 40 import java.util.ListIterator;
41 41
  42 +import br.gov.frameworkdemoiselle.internal.implementation.DefaultTransaction;
  43 +import br.gov.frameworkdemoiselle.transaction.Transaction;
42 import br.gov.frameworkdemoiselle.transaction.Transactional; 44 import br.gov.frameworkdemoiselle.transaction.Transactional;
43 import br.gov.frameworkdemoiselle.util.Beans; 45 import br.gov.frameworkdemoiselle.util.Beans;
44 import br.gov.frameworkdemoiselle.util.Reflections; 46 import br.gov.frameworkdemoiselle.util.Reflections;
@@ -49,38 +51,62 @@ public class DelegateCrud&lt;T, I, C extends Crud&lt;T, I&gt;&gt; implements Crud&lt;T, I&gt; { @@ -49,38 +51,62 @@ public class DelegateCrud&lt;T, I, C extends Crud&lt;T, I&gt;&gt; implements Crud&lt;T, I&gt; {
49 51
50 private Class<C> delegateClass; 52 private Class<C> delegateClass;
51 53
52 - private C delegate; 54 + private transient C delegate;
53 55
54 /** 56 /**
55 - * Remove a persistent instance from the database. 57 + * Removes a instance from delegate.
56 * 58 *
57 * @param id 59 * @param id
58 - * entity class with the given identifier 60 + * Entity with the given identifier
59 */ 61 */
60 @Override 62 @Override
61 - @Transactional  
62 public void delete(final I id) { 63 public void delete(final I id) {
63 - this.getDelegate().delete(id); 64 + if (isRunningTransactionalOperations()) {
  65 + transactionalDelete(id);
  66 + } else {
  67 + nonTransactionalDelete(id);
  68 + }
  69 + }
  70 +
  71 + @Transactional
  72 + private void transactionalDelete(final I id) {
  73 + nonTransactionalDelete(id);
  74 + }
  75 +
  76 + private void nonTransactionalDelete(final I id) {
  77 + getDelegate().delete(id);
64 } 78 }
65 79
66 /** 80 /**
67 - * Remove a list of persistent instances from the database. 81 + * Removes a list of instances from delegate.
68 * 82 *
69 - * @param idList  
70 - * list of entity class with the given identifier 83 + * @param ids
  84 + * List of entities identifiers
71 */ 85 */
  86 + public void delete(final List<I> ids) {
  87 + if (isRunningTransactionalOperations()) {
  88 + transactionalDelete(ids);
  89 + } else {
  90 + nonTransactionalDelete(ids);
  91 + }
  92 + }
  93 +
72 @Transactional 94 @Transactional
73 - public void delete(final List<I> idList) {  
74 - ListIterator<I> iter = idList.listIterator(); 95 + private void transactionalDelete(final List<I> ids) {
  96 + nonTransactionalDelete(ids);
  97 + }
  98 +
  99 + private void nonTransactionalDelete(final List<I> ids) {
  100 + ListIterator<I> iter = ids.listIterator();
75 while (iter.hasNext()) { 101 while (iter.hasNext()) {
76 this.delete(iter.next()); 102 this.delete(iter.next());
77 } 103 }
78 } 104 }
79 105
80 /** 106 /**
81 - * Get the results. 107 + * Gets the results from delegate.
82 * 108 *
83 - * @return the list of matched query results. 109 + * @return The list of matched query results.
84 */ 110 */
85 @Override 111 @Override
86 public List<T> findAll() { 112 public List<T> findAll() {
@@ -91,34 +117,46 @@ public class DelegateCrud&lt;T, I, C extends Crud&lt;T, I&gt;&gt; implements Crud&lt;T, I&gt; { @@ -91,34 +117,46 @@ public class DelegateCrud&lt;T, I, C extends Crud&lt;T, I&gt;&gt; implements Crud&lt;T, I&gt; {
91 if (this.delegate == null) { 117 if (this.delegate == null) {
92 this.delegate = Beans.getReference(getDelegateClass()); 118 this.delegate = Beans.getReference(getDelegateClass());
93 } 119 }
  120 +
94 return this.delegate; 121 return this.delegate;
95 } 122 }
96 123
97 protected Class<C> getDelegateClass() { 124 protected Class<C> getDelegateClass() {
98 if (this.delegateClass == null) { 125 if (this.delegateClass == null) {
99 - this.delegateClass = Reflections.getGenericTypeArgument(  
100 - this.getClass(), 2); 126 + this.delegateClass = Reflections.getGenericTypeArgument(this.getClass(), 2);
101 } 127 }
  128 +
102 return this.delegateClass; 129 return this.delegateClass;
103 } 130 }
104 131
105 /** 132 /**
106 - * Persist the given transient instance. 133 + * Delegates the insert operation of the given instance.
107 * 134 *
108 * @param bean 135 * @param bean
109 - * a transient instance of a persistent class 136 + * A entity to be inserted by the delegate
110 */ 137 */
111 @Override 138 @Override
112 - @Transactional  
113 public void insert(final T bean) { 139 public void insert(final T bean) {
  140 + if (isRunningTransactionalOperations()) {
  141 + transactionalInsert(bean);
  142 + } else {
  143 + nonTransactionalInsert(bean);
  144 + }
  145 + }
  146 +
  147 + @Transactional
  148 + private void transactionalInsert(final T bean) {
  149 + nonTransactionalInsert(bean);
  150 + }
  151 +
  152 + private void nonTransactionalInsert(final T bean) {
114 getDelegate().insert(bean); 153 getDelegate().insert(bean);
115 } 154 }
116 155
117 /** 156 /**
118 - * Return the persistent instance of the given entity class with the given  
119 - * identifier 157 + * Returns the instance of the given entity with the given identifier
120 * 158 *
121 - * @return the persistent instance 159 + * @return The instance
122 */ 160 */
123 @Override 161 @Override
124 public T load(final I id) { 162 public T load(final I id) {
@@ -126,16 +164,30 @@ public class DelegateCrud&lt;T, I, C extends Crud&lt;T, I&gt;&gt; implements Crud&lt;T, I&gt; { @@ -126,16 +164,30 @@ public class DelegateCrud&lt;T, I, C extends Crud&lt;T, I&gt;&gt; implements Crud&lt;T, I&gt; {
126 } 164 }
127 165
128 /** 166 /**
129 - *  
130 - * Update the persistent instance with the identifier of the given detached  
131 - * instance. 167 + * Delegates the update operation of the given instance.
132 * 168 *
133 * @param bean 169 * @param bean
134 - * a detached instance containing updated state. 170 + * The instance containing the updated state.
135 */ 171 */
136 @Override 172 @Override
137 - @Transactional  
138 public void update(final T bean) { 173 public void update(final T bean) {
  174 + if (isRunningTransactionalOperations()) {
  175 + transactionalUpdate(bean);
  176 + } else {
  177 + nonTransactionalUpdate(bean);
  178 + }
  179 + }
  180 +
  181 + @Transactional
  182 + private void transactionalUpdate(final T bean) {
  183 + nonTransactionalUpdate(bean);
  184 + }
  185 +
  186 + private void nonTransactionalUpdate(final T bean) {
139 getDelegate().update(bean); 187 getDelegate().update(bean);
140 } 188 }
  189 +
  190 + private boolean isRunningTransactionalOperations() {
  191 + return !(Beans.getReference(Transaction.class) instanceof DefaultTransaction);
  192 + }
141 } 193 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/transaction/TransactionContext.java 0 → 100644
@@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
  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.transaction;
  38 +
  39 +import java.io.Serializable;
  40 +
  41 +/**
  42 + * Structure used to handle transaction mechanisms.
  43 + *
  44 + * @author SERPRO
  45 + */
  46 +public interface TransactionContext extends Serializable {
  47 +
  48 + Transaction getCurrentTransaction();
  49 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Beans.java
@@ -49,14 +49,23 @@ @@ -49,14 +49,23 @@
49 package br.gov.frameworkdemoiselle.util; 49 package br.gov.frameworkdemoiselle.util;
50 50
51 import java.lang.annotation.Annotation; 51 import java.lang.annotation.Annotation;
  52 +import java.util.Locale;
  53 +import java.util.NoSuchElementException;
  54 +import java.util.Set;
52 55
53 import javax.enterprise.inject.spi.Bean; 56 import javax.enterprise.inject.spi.Bean;
54 import javax.enterprise.inject.spi.BeanManager; 57 import javax.enterprise.inject.spi.BeanManager;
55 58
56 -public class Beans { 59 +import br.gov.frameworkdemoiselle.DemoiselleException;
  60 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
  61 +
  62 +public final class Beans {
57 63
58 private static BeanManager manager; 64 private static BeanManager manager;
59 65
  66 + private Beans() {
  67 + }
  68 +
60 public static void setBeanManager(BeanManager beanManager) { 69 public static void setBeanManager(BeanManager beanManager) {
61 manager = beanManager; 70 manager = beanManager;
62 } 71 }
@@ -65,24 +74,66 @@ public class Beans { @@ -65,24 +74,66 @@ public class Beans {
65 return manager; 74 return manager;
66 } 75 }
67 76
  77 + @SuppressWarnings("unchecked")
68 public static <T> T getReference(final Class<T> beanClass, Annotation... qualifiers) { 78 public static <T> T getReference(final Class<T> beanClass, Annotation... qualifiers) {
69 - Bean<?> bean = manager.getBeans(beanClass, qualifiers).iterator().next();  
70 - return (T) getReference(bean, beanClass); 79 + T instance;
  80 +
  81 + try {
  82 + instance = (T) getReference(manager.getBeans(beanClass, qualifiers));
  83 +
  84 + } catch (NoSuchElementException cause) {
  85 + StringBuffer buffer = new StringBuffer();
  86 + buffer.append(beanClass.getCanonicalName());
  87 +
  88 + for (Annotation qualifier : qualifiers) {
  89 + buffer.append(", ");
  90 + buffer.append(qualifier.getClass().getCanonicalName());
  91 + }
  92 +
  93 + String message = getBundle().getString("bean-not-found", buffer.toString());
  94 + throw new DemoiselleException(message, cause);
  95 + }
  96 +
  97 + return instance;
71 } 98 }
72 99
  100 + @SuppressWarnings("unchecked")
73 public static <T> T getReference(final Class<T> beanClass) { 101 public static <T> T getReference(final Class<T> beanClass) {
74 - Bean<?> bean = manager.getBeans(beanClass).iterator().next();  
75 - return (T) getReference(bean, beanClass); 102 + T instance;
  103 +
  104 + try {
  105 + instance = (T) getReference(manager.getBeans(beanClass));
  106 +
  107 + } catch (NoSuchElementException cause) {
  108 + String message = getBundle().getString("bean-not-found", beanClass.getCanonicalName());
  109 + throw new DemoiselleException(message, cause);
  110 + }
  111 +
  112 + return instance;
76 } 113 }
77 114
78 @SuppressWarnings("unchecked") 115 @SuppressWarnings("unchecked")
79 public static <T> T getReference(String beanName) { 116 public static <T> T getReference(String beanName) {
80 - Bean<?> bean = manager.getBeans(beanName).iterator().next();  
81 - return (T) getReference(bean, bean.getBeanClass()); 117 + T instance;
  118 +
  119 + try {
  120 + instance = (T) getReference(manager.getBeans(beanName));
  121 +
  122 + } catch (NoSuchElementException cause) {
  123 + String message = getBundle().getString("bean-not-found", beanName);
  124 + throw new DemoiselleException(message, cause);
  125 + }
  126 +
  127 + return instance;
82 } 128 }
83 129
84 @SuppressWarnings("unchecked") 130 @SuppressWarnings("unchecked")
85 - private static <T> T getReference(Bean<?> bean, final Class<T> beanClass) {  
86 - return (T) manager.getReference(bean, beanClass, manager.createCreationalContext(bean)); 131 + private static <T> T getReference(Set<Bean<?>> beans) {
  132 + Bean<?> bean = beans.iterator().next();
  133 + return (T) manager.getReference(bean, bean.getBeanClass(), manager.createCreationalContext(bean));
  134 + }
  135 +
  136 + private static ResourceBundle getBundle() {
  137 + return ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault());
87 } 138 }
88 } 139 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Exceptions.java
@@ -20,7 +20,10 @@ package br.gov.frameworkdemoiselle.util; @@ -20,7 +20,10 @@ package br.gov.frameworkdemoiselle.util;
20 20
21 import br.gov.frameworkdemoiselle.exception.ApplicationException; 21 import br.gov.frameworkdemoiselle.exception.ApplicationException;
22 22
23 -public class Exceptions { 23 +public final class Exceptions {
  24 +
  25 + private Exceptions() {
  26 + }
24 27
25 public static boolean isApplicationException(final Throwable throwable) { 28 public static boolean isApplicationException(final Throwable throwable) {
26 return throwable.getClass().isAnnotationPresent(ApplicationException.class); 29 return throwable.getClass().isAnnotationPresent(ApplicationException.class);
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Reflections.java
@@ -45,7 +45,10 @@ import java.lang.reflect.Type; @@ -45,7 +45,10 @@ import java.lang.reflect.Type;
45 import java.util.ArrayList; 45 import java.util.ArrayList;
46 import java.util.List; 46 import java.util.List;
47 47
48 -public class Reflections { 48 +public final class Reflections {
  49 +
  50 + private Reflections() {
  51 + }
49 52
50 @SuppressWarnings("unchecked") 53 @SuppressWarnings("unchecked")
51 public static <T> Class<T> getGenericTypeArgument(final Class<?> clazz, final int idx) { 54 public static <T> Class<T> getGenericTypeArgument(final Class<?> clazz, final int idx) {
@@ -127,11 +130,11 @@ public class Reflections { @@ -127,11 +130,11 @@ public class Reflections {
127 130
128 return fields.toArray(new Field[0]); 131 return fields.toArray(new Field[0]);
129 } 132 }
130 - 133 +
131 public static <T> T instantiate(Class<T> clasz) { 134 public static <T> T instantiate(Class<T> clasz) {
132 T object = null; 135 T object = null;
133 try { 136 try {
134 - object = clasz.newInstance(); 137 + object = clasz.newInstance();
135 } catch (InstantiationException e) { 138 } catch (InstantiationException e) {
136 Exceptions.handleToRuntimeException(e); 139 Exceptions.handleToRuntimeException(e);
137 } catch (IllegalAccessException e) { 140 } catch (IllegalAccessException e) {
@@ -140,4 +143,7 @@ public class Reflections { @@ -140,4 +143,7 @@ public class Reflections {
140 return object; 143 return object;
141 } 144 }
142 145
  146 + public static boolean isOfType(Class<?> clazz, Class<?> type) {
  147 + return type.isAssignableFrom(clazz) && clazz != type;
  148 + }
143 } 149 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/ResourceBundle.java
@@ -40,36 +40,56 @@ import java.io.Serializable; @@ -40,36 +40,56 @@ import java.io.Serializable;
40 import java.lang.reflect.Method; 40 import java.lang.reflect.Method;
41 import java.util.Enumeration; 41 import java.util.Enumeration;
42 import java.util.Locale; 42 import java.util.Locale;
  43 +import java.util.MissingResourceException;
43 import java.util.Set; 44 import java.util.Set;
44 45
45 public class ResourceBundle extends java.util.ResourceBundle implements Serializable { 46 public class ResourceBundle extends java.util.ResourceBundle implements Serializable {
46 47
47 private static final long serialVersionUID = 1L; 48 private static final long serialVersionUID = 1L;
48 49
  50 + private String baseName;
  51 +
49 private transient java.util.ResourceBundle delegate; 52 private transient java.util.ResourceBundle delegate;
50 53
51 - public ResourceBundle(java.util.ResourceBundle resourceBundle) {  
52 - this.delegate = resourceBundle; 54 + private final Locale locale;
  55 +
  56 + private java.util.ResourceBundle getDelegate() {
  57 + if (delegate == null) {
  58 + try {
  59 + ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  60 + delegate = ResourceBundle.getBundle(baseName, locale, classLoader);
  61 +
  62 + } catch (MissingResourceException mre) {
  63 + delegate = ResourceBundle.getBundle(baseName, locale);
  64 + }
  65 + }
  66 +
  67 + return delegate;
  68 + }
  69 +
  70 + public ResourceBundle(String baseName, Locale locale) {
  71 + this.baseName = baseName;
  72 + this.locale = locale;
53 } 73 }
54 74
55 @Override 75 @Override
56 public boolean containsKey(String key) { 76 public boolean containsKey(String key) {
57 - return delegate.containsKey(key); 77 + return getDelegate().containsKey(key);
58 } 78 }
59 79
60 @Override 80 @Override
61 public Enumeration<String> getKeys() { 81 public Enumeration<String> getKeys() {
62 - return delegate.getKeys(); 82 + return getDelegate().getKeys();
63 } 83 }
64 84
65 @Override 85 @Override
66 public Locale getLocale() { 86 public Locale getLocale() {
67 - return delegate.getLocale(); 87 + return getDelegate().getLocale();
68 } 88 }
69 89
70 @Override 90 @Override
71 public Set<String> keySet() { 91 public Set<String> keySet() {
72 - return delegate.keySet(); 92 + return getDelegate().keySet();
73 } 93 }
74 94
75 public String getString(String key, Object... params) { 95 public String getString(String key, Object... params) {
@@ -81,7 +101,7 @@ public class ResourceBundle extends java.util.ResourceBundle implements Serializ @@ -81,7 +101,7 @@ public class ResourceBundle extends java.util.ResourceBundle implements Serializ
81 Object result; 101 Object result;
82 102
83 try { 103 try {
84 - Method method = delegate.getClass().getMethod("handleGetObject", String.class); 104 + Method method = getDelegate().getClass().getMethod("handleGetObject", String.class);
85 105
86 method.setAccessible(true); 106 method.setAccessible(true);
87 result = method.invoke(delegate, key); 107 result = method.invoke(delegate, key);
@@ -90,6 +110,7 @@ public class ResourceBundle extends java.util.ResourceBundle implements Serializ @@ -90,6 +110,7 @@ public class ResourceBundle extends java.util.ResourceBundle implements Serializ
90 } catch (Exception cause) { 110 } catch (Exception cause) {
91 throw new RuntimeException(cause); 111 throw new RuntimeException(cause);
92 } 112 }
  113 +
93 return result; 114 return result;
94 } 115 }
95 } 116 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Strings.java
@@ -43,7 +43,10 @@ import java.util.regex.Pattern; @@ -43,7 +43,10 @@ import java.util.regex.Pattern;
43 43
44 import br.gov.frameworkdemoiselle.annotation.Ignore; 44 import br.gov.frameworkdemoiselle.annotation.Ignore;
45 45
46 -public class Strings { 46 +public final class Strings {
  47 +
  48 + private Strings() {
  49 + }
47 50
48 public static boolean isResourceBundleKeyFormat(final String key) { 51 public static boolean isResourceBundleKeyFormat(final String key) {
49 return Pattern.matches("^\\{(.+)\\}$", key == null ? "" : key); 52 return Pattern.matches("^\\{(.+)\\}$", key == null ? "" : key);
impl/core/src/main/resources/META-INF/beans.xml
@@ -37,11 +37,4 @@ @@ -37,11 +37,4 @@
37 <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"> 38 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
39 39
40 - <interceptors>  
41 - <class>br.gov.frameworkdemoiselle.internal.interceptor.ExceptionHandlerInterceptor</class>  
42 - <class>br.gov.frameworkdemoiselle.internal.interceptor.RequiredPermissionInterceptor</class>  
43 - <class>br.gov.frameworkdemoiselle.internal.interceptor.RequiredRoleInterceptor</class>  
44 - <class>br.gov.frameworkdemoiselle.internal.interceptor.TransactionalInterceptor</class>  
45 - </interceptors>  
46 -  
47 </beans> 40 </beans>
48 \ No newline at end of file 41 \ No newline at end of file
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 - 3 +br.gov.frameworkdemoiselle.internal.bootstrap.TransactionBootstrap
  4 +br.gov.frameworkdemoiselle.internal.bootstrap.AuthenticatorBootstrap
  5 +br.gov.frameworkdemoiselle.internal.bootstrap.AuthorizerBootstrap
4 br.gov.frameworkdemoiselle.internal.bootstrap.StartupBootstrap 6 br.gov.frameworkdemoiselle.internal.bootstrap.StartupBootstrap
5 br.gov.frameworkdemoiselle.internal.bootstrap.ShutdownBootstrap 7 br.gov.frameworkdemoiselle.internal.bootstrap.ShutdownBootstrap
impl/core/src/main/resources/demoiselle-core-bundle.properties
@@ -34,6 +34,8 @@ @@ -34,6 +34,8 @@
34 # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. 34 # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
35 35
36 engine-on=Ligando os motores do Demoiselle ${project.version} 36 engine-on=Ligando os motores do Demoiselle ${project.version}
  37 +ambiguous-strategy-resolution=Foi detectada ambiguidade da interface "{0}" com as seguintes implementa\u00E7\u00F5es\: "{1}". Para resolver o conflito, defina explicitamente a implementa\u00E7\u00E3o no demoiselle.properties.
  38 +bean-not-found=Voc\u00EA est\u00E1 tentando obter um objeto n\u00E3o reconhecido pelo CDI via Beans.getReference({0})
37 more-than-one-exceptionhandler-defined-for-same-class=Foi definido mais de um m\u00E9todo na classe {0} para tratar a exce\u00E7\u00E3o {1} 39 more-than-one-exceptionhandler-defined-for-same-class=Foi definido mais de um m\u00E9todo na classe {0} para tratar a exce\u00E7\u00E3o {1}
38 handling-exception=Tratando a exce\u00E7\u00E3o {0} 40 handling-exception=Tratando a exce\u00E7\u00E3o {0}
39 proxy-detected=Detectado o proxy {0} da classe {1} 41 proxy-detected=Detectado o proxy {0} da classe {1}
@@ -58,7 +60,7 @@ configuration-attribute-is-mandatory=A configura\u00E7\u00E3o {0} \u00E9 obrigat @@ -58,7 +60,7 @@ configuration-attribute-is-mandatory=A configura\u00E7\u00E3o {0} \u00E9 obrigat
58 configuration-name-attribute-cant-be-empty=A nota\u00E7\u00E3o Name n\u00E3o pode estar em branco 60 configuration-name-attribute-cant-be-empty=A nota\u00E7\u00E3o Name n\u00E3o pode estar em branco
59 configuration-key-not-found=Chave de configura\u00E7\u00E3o "{0}" n\u00E3o encontrada. Conven\u00E7\u00F5es verificadas\: "{1}" 61 configuration-key-not-found=Chave de configura\u00E7\u00E3o "{0}" n\u00E3o encontrada. Conven\u00E7\u00F5es verificadas\: "{1}"
60 62
61 -transaction-not-defined=Nenhuma transa\u00E7\u00E3o foi definida. Para utilizar @{0} \u00E9 preciso definir a estrat\u00E9gia de transa\u00E7\u00E3o desejada no arquivo beans.xml 63 +transaction-not-defined=Nenhuma transa\u00E7\u00E3o foi definida. Para utilizar @{0} \u00E9 preciso definir a propriedade frameworkdemoiselle.transaction.class com a estrat\u00E9gia de transa\u00E7\u00E3o desejada no arquivo demoiselle.properties
62 executing-all=Executando todos os \: {0} 64 executing-all=Executando todos os \: {0}
63 custom-context-was-registered=O contexto {0} foi registrado 65 custom-context-was-registered=O contexto {0} foi registrado
64 custom-context-was-unregistered=O contexto {0} foi removido 66 custom-context-was-unregistered=O contexto {0} foi removido
@@ -70,8 +72,6 @@ error-creating-new-instance-for=Error creating a new instance for &quot;{0}&quot; @@ -70,8 +72,6 @@ error-creating-new-instance-for=Error creating a new instance for &quot;{0}&quot;
70 executed-successfully=\ {0} execultado com sucesso 72 executed-successfully=\ {0} execultado com sucesso
71 must-declare-one-single-parameter=Voc\u00EA deve declarar um par\u00E2metro \u00FAnico em {0} 73 must-declare-one-single-parameter=Voc\u00EA deve declarar um par\u00E2metro \u00FAnico em {0}
72 loading-default-transaction-manager=Carregando o gerenciador de transa\u00E7\u00E3o padr\u00E3o {0} 74 loading-default-transaction-manager=Carregando o gerenciador de transa\u00E7\u00E3o padr\u00E3o {0}
73 -transaction-class-not-found=A classe de transa\u00E7\u00E3o "{0}" informada n\u00E3o foi encontrada.  
74 -transaction-class-must-be-of-type=A classe de transa\u00E7\u00E3o "{0}" informada deve ser do tipo {1}  
75 results-count-greater-page-size=Quantidade de resultados {0} \u00E9 maior que o tamanho da p\u00E1gina {1} 75 results-count-greater-page-size=Quantidade de resultados {0} \u00E9 maior que o tamanho da p\u00E1gina {1}
76 page-result=Resultado paginado [p\u00E1gina\={0}, total de resultados\={1}] 76 page-result=Resultado paginado [p\u00E1gina\={0}, total de resultados\={1}]
77 page=P\u00E1gina [n\u00FAmero\={0}, tamanho\={1}] 77 page=P\u00E1gina [n\u00FAmero\={0}, tamanho\={1}]
@@ -86,10 +86,11 @@ access-checking=Verificando permiss\u00E3o do usu\u00E1rio &quot;{0}&quot; para executar a @@ -86,10 +86,11 @@ access-checking=Verificando permiss\u00E3o do usu\u00E1rio &quot;{0}&quot; para executar a
86 access-allowed=O usu\u00E1rio "{0}" acessou o recurso "{2}" com a a\u00E7\u00E3o "{1}" 86 access-allowed=O usu\u00E1rio "{0}" acessou o recurso "{2}" com a a\u00E7\u00E3o "{1}"
87 access-denied=O usu\u00E1rio "{0}" n\u00E3o possui permiss\u00E3o para executar a a\u00E7\u00E3o "{1}" no recurso "{2}" 87 access-denied=O usu\u00E1rio "{0}" n\u00E3o possui permiss\u00E3o para executar a a\u00E7\u00E3o "{1}" no recurso "{2}"
88 access-denied-ui=Voc\u00EA n\u00E3o est\u00E1 autorizado a executar a a\u00E7\u00E3o {1} no recurso {0} 88 access-denied-ui=Voc\u00EA n\u00E3o est\u00E1 autorizado a executar a a\u00E7\u00E3o {1} no recurso {0}
89 -authorizer-not-defined=Nenhuma regra de resolu\u00E7\u00E3o de permiss\u00F5es foi definida. Para utilizar @{0} \u00E9 preciso definir a estrat\u00E9gia de resolu\u00E7\u00E3o de permiss\u00F5es desejada no arquivo beans.xml 89 +authorizer-not-defined=Nenhuma regra de resolu\u00E7\u00E3o de permiss\u00F5es foi definida. Para utilizar @{0} \u00E9 preciso definir a propriedade frameworkdemoiselle.security.authorizer.class como regra de resolu\u00E7\u00E3o de permiss\u00F5es desejada no arquivo demoiselle.properties.
90 user-not-authenticated=Usu\u00E1rio n\u00E3o autenticado 90 user-not-authenticated=Usu\u00E1rio n\u00E3o autenticado
91 has-role-verification=Verificando se o usu\u00E1rio {0} possui a(s) role(s)\: {1} 91 has-role-verification=Verificando se o usu\u00E1rio {0} possui a(s) role(s)\: {1}
92 does-not-have-role=Usu\u00E1rio {0} n\u00E3o possui a(s) role(s)\: {1} 92 does-not-have-role=Usu\u00E1rio {0} n\u00E3o possui a(s) role(s)\: {1}
93 does-not-have-role-ui=Para acessar este recurso \u00E9 necess\u00E1rio ser {0} 93 does-not-have-role-ui=Para acessar este recurso \u00E9 necess\u00E1rio ser {0}
94 user-has-role=Usu\u00E1rio {0} possui a(s) role(s)\: {1} 94 user-has-role=Usu\u00E1rio {0} possui a(s) role(s)\: {1}
95 -authenticator-not-defined=Nenhum mecanismo de autentica\u00E7\u00E3o foi definido. Para utilizar {0} \u00E9 preciso definir o mecanismo de autentica\u00E7\u00E3o desejado no arquivo beans.xml  
96 \ No newline at end of file 95 \ No newline at end of file
  96 +
  97 +authenticator-not-defined=Nenhum mecanismo de autentica\u00E7\u00E3o foi definido. Para utilizar {0} \u00E9 preciso definir a propriedade frameworkdemoiselle.security.authenticator.class como mecanismo de autentica\u00E7\u00E3o desejado no arquivo demoiselle.properties.
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractBootstrapTest.java
@@ -1,126 +0,0 @@ @@ -1,126 +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.bootstrap;  
38 -  
39 -import static org.easymock.EasyMock.expect;  
40 -import static org.powermock.api.easymock.PowerMock.mockStatic;  
41 -import static org.powermock.api.easymock.PowerMock.replayAll;  
42 -import static org.powermock.api.easymock.PowerMock.verifyAll;  
43 -  
44 -import java.util.Locale;  
45 -  
46 -import javax.enterprise.inject.spi.AfterBeanDiscovery;  
47 -import javax.inject.Scope;  
48 -  
49 -import org.easymock.EasyMock;  
50 -import org.junit.Test;  
51 -import org.junit.runner.RunWith;  
52 -import org.powermock.api.easymock.PowerMock;  
53 -import org.powermock.core.classloader.annotations.PrepareForTest;  
54 -import org.powermock.modules.junit4.PowerMockRunner;  
55 -import org.powermock.reflect.Whitebox;  
56 -import org.slf4j.Logger;  
57 -  
58 -import br.gov.frameworkdemoiselle.internal.context.Contexts;  
59 -import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext;  
60 -import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;  
61 -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;  
62 -import br.gov.frameworkdemoiselle.util.ResourceBundle;  
63 -  
64 -@RunWith(PowerMockRunner.class)  
65 -@PrepareForTest({ LoggerProducer.class, Contexts.class })  
66 -public class AbstractBootstrapTest {  
67 -  
68 - @Test  
69 - @SuppressWarnings("unchecked")  
70 - public void testAddContext() {  
71 - mockStatic(LoggerProducer.class);  
72 - mockStatic(Contexts.class);  
73 -  
74 - Logger logger = PowerMock.createMock(Logger.class);  
75 - logger.trace(EasyMock.anyObject(String.class));  
76 -  
77 - expect(LoggerProducer.create(EasyMock.anyObject(Class.class))).andReturn(logger);  
78 -  
79 - ResourceBundle bundle = PowerMock.createMock(ResourceBundle.class);  
80 - expect(bundle.getString(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn(null);  
81 -  
82 - ResourceBundleProducer bundleFactory = PowerMock.createMock(ResourceBundleProducer.class);  
83 - expect(bundleFactory.create(EasyMock.anyObject(String.class), EasyMock.anyObject(Locale.class))).andReturn(  
84 - bundle);  
85 -  
86 - Whitebox.setInternalState(AbstractBootstrap.class, "bundleFactory", bundleFactory);  
87 -  
88 - ThreadLocalContext context = new ThreadLocalContext(Scope.class);  
89 - Contexts.add(EasyMock.anyObject(ThreadLocalContext.class), EasyMock.anyObject(AfterBeanDiscovery.class));  
90 - replayAll(bundle, bundleFactory, logger, LoggerProducer.class, Contexts.class);  
91 -  
92 - AbstractBootstrap.addContext(context, null);  
93 -  
94 - verifyAll();  
95 - }  
96 -  
97 - @Test  
98 - @SuppressWarnings("unchecked")  
99 - public void testDisableContext() {  
100 - mockStatic(LoggerProducer.class);  
101 - mockStatic(Contexts.class);  
102 -  
103 - Logger logger = PowerMock.createMock(Logger.class);  
104 - logger.trace(EasyMock.anyObject(String.class));  
105 - expect(LoggerProducer.create(EasyMock.anyObject(Class.class))).andReturn(logger);  
106 -  
107 - ResourceBundle bundle = PowerMock.createMock(ResourceBundle.class);  
108 - expect(bundle.getString(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn(null);  
109 -  
110 - ResourceBundleProducer bundleFactory = PowerMock.createMock(ResourceBundleProducer.class);  
111 - expect(bundleFactory.create(EasyMock.anyObject(String.class), EasyMock.anyObject(Locale.class))).andReturn(  
112 - bundle);  
113 -  
114 - Whitebox.setInternalState(AbstractBootstrap.class, "bundleFactory", bundleFactory);  
115 -  
116 - ThreadLocalContext context = new ThreadLocalContext(Scope.class);  
117 -  
118 - Contexts.remove(context);  
119 - replayAll(bundle, bundleFactory, logger, LoggerProducer.class, Contexts.class);  
120 -  
121 - AbstractBootstrap.disableContext(context);  
122 -  
123 - verifyAll();  
124 - }  
125 -  
126 -}