Commit c5a3fe54fe229fb188fa292c06a135d2bd54cf73

Authored by Cleverson Sacramento
1 parent a55759ec
Exists in master

Migração do repositório para o GitHub

Showing 343 changed files with 32356 additions and 0 deletions   Show diff stats

Too many changes.

To preserve performance only 100 of 343 files displayed.

.gitignore 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +/target
  2 +/.project
  3 +/.classpath
  4 +/.settings
  5 +/.externalToolBuilders
... ...
archetype/.gitignore 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +/target
  2 +/.project
  3 +/.classpath
  4 +/.settings
  5 +/.externalToolBuilders
... ...
archetype/jsf-jpa/.gitignore 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +/target
  2 +/.project
  3 +/.classpath
  4 +/.settings
  5 +/.externalToolBuilders
... ...
archetype/jsf-jpa/pom.xml 0 → 100755
... ... @@ -0,0 +1,62 @@
  1 +<!--
  2 + Demoiselle Framework
  3 + Copyright (C) 2010 SERPRO
  4 + ============================================================================
  5 + This file is part of Demoiselle Framework.
  6 +
  7 + Demoiselle Framework is free software; you can redistribute it and/or
  8 + modify it under the terms of the GNU Lesser General Public License version 3
  9 + as published by the Free Software Foundation.
  10 +
  11 + This program is distributed in the hope that it will be useful,
  12 + but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + GNU General Public License for more details.
  15 +
  16 + You should have received a copy of the GNU Lesser General Public License version 3
  17 + along with this program; if not, see <http://www.gnu.org/licenses />
  18 + or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + Fifth Floor, Boston, MA 02110-1301, USA.
  20 + ============================================================================
  21 + Este arquivo é parte do Framework Demoiselle.
  22 +
  23 + O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + do Software Livre (FSF).
  26 +
  27 + Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + para maiores detalhes.
  31 +
  32 + Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses />
  34 + ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 +-->
  37 +<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.archetypes</groupId>
  42 + <artifactId>demoiselle-jsf-jpa</artifactId>
  43 + <packaging>jar</packaging>
  44 +
  45 + <parent>
  46 + <groupId>br.gov.frameworkdemoiselle</groupId>
  47 + <artifactId>demoiselle-archetype-parent</artifactId>
  48 + <version>2.2.1-SNAPSHOT</version>
  49 + <relativePath>../../parent/archetype/pom.xml</relativePath>
  50 + </parent>
  51 +
  52 + <name>JSF and JPA Archetype</name>
  53 + <description>Archetype for web applications (JSF/JPA)</description>
  54 +
  55 + <repositories>
  56 + <repository>
  57 + <id>demoiselle.sourceforge.net</id>
  58 + <name>Demoiselle Maven Repository</name>
  59 + <url>http://demoiselle.sourceforge.net/repository/release</url>
  60 + </repository>
  61 + </repositories>
  62 +</project>
... ...
archetype/jsf-jpa/src/main/resources/META-INF/maven/archetype-metadata.xml 0 → 100755
... ... @@ -0,0 +1,79 @@
  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 +<archetype-descriptor xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
  38 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  39 + xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
  40 + name="#{project.artifactId}">
  41 +
  42 + <fileSets>
  43 + <fileSet filtered="true" packaged="false">
  44 + <directory />
  45 + <includes>
  46 + <include>readme.txt</include>
  47 + </includes>
  48 + </fileSet>
  49 + <fileSet filtered="true" packaged="false">
  50 + <directory>src/main/webapp</directory>
  51 + <excludes>
  52 + <exclude>**/*.png</exclude>
  53 + <exclude>**/*.gif</exclude>
  54 + <exclude>**/*.jpg</exclude>
  55 + </excludes>
  56 + </fileSet>
  57 + <fileSet filtered="false" packaged="false">
  58 + <directory>src/main/webapp</directory>
  59 + <includes>
  60 + <include>**/*.png</include>
  61 + <include>**/*.gif</include>
  62 + <include>**/*.jpg</include>
  63 + </includes>
  64 + </fileSet>
  65 + <fileSet filtered="true" packaged="true">
  66 + <directory>src/main/java</directory>
  67 + </fileSet>
  68 + <fileSet filtered="true" packaged="false">
  69 + <directory>src/main/resources</directory>
  70 + </fileSet>
  71 + <fileSet filtered="true" packaged="true">
  72 + <directory>src/test/java</directory>
  73 + </fileSet>
  74 + <fileSet filtered="true" packaged="false">
  75 + <directory>src/test/resources</directory>
  76 + </fileSet>
  77 + </fileSets>
  78 +
  79 +</archetype-descriptor>
0 80 \ No newline at end of file
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/pom.xml 0 → 100755
... ... @@ -0,0 +1,52 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
  3 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  4 +
  5 + <modelVersion>4.0.0</modelVersion>
  6 +
  7 + <groupId>${groupId}</groupId>
  8 + <artifactId>${artifactId}</artifactId>
  9 + <version>${version}</version>
  10 + <packaging>war</packaging>
  11 +
  12 + <name></name>
  13 + <description></description>
  14 + <url></url>
  15 +
  16 + <parent>
  17 + <groupId>br.gov.frameworkdemoiselle</groupId>
  18 + <artifactId>demoiselle-jsf-parent</artifactId>
  19 + <version>#{parent.version}</version>
  20 + </parent>
  21 +
  22 + <dependencies>
  23 + <dependency>
  24 + <groupId>br.gov.frameworkdemoiselle</groupId>
  25 + <artifactId>demoiselle-jpa</artifactId>
  26 + <scope>compile</scope>
  27 + </dependency>
  28 + <dependency>
  29 + <groupId>br.gov.frameworkdemoiselle</groupId>
  30 + <artifactId>demoiselle-jta</artifactId>
  31 + <scope>compile</scope>
  32 + </dependency>
  33 + <dependency>
  34 + <groupId>org.primefaces</groupId>
  35 + <artifactId>primefaces</artifactId>
  36 + <scope>compile</scope>
  37 + </dependency>
  38 + <dependency>
  39 + <groupId>org.powermock</groupId>
  40 + <artifactId>powermock-api-easymock</artifactId>
  41 + <scope>test</scope>
  42 + </dependency>
  43 + </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>
0 53 \ No newline at end of file
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/business/BookmarkBC.java 0 → 100644
... ... @@ -0,0 +1,33 @@
  1 +package ${package}.business;
  2 +
  3 +import br.gov.frameworkdemoiselle.annotation.Startup;
  4 +import br.gov.frameworkdemoiselle.stereotype.BusinessController;
  5 +import br.gov.frameworkdemoiselle.template.DelegateCrud;
  6 +import br.gov.frameworkdemoiselle.transaction.Transactional;
  7 +
  8 +import ${package}.domain.Bookmark;
  9 +import ${package}.persistence.BookmarkDAO;
  10 +
  11 +@BusinessController
  12 +public class BookmarkBC extends DelegateCrud<Bookmark, Long, BookmarkDAO> {
  13 +
  14 + private static final long serialVersionUID = 1L;
  15 +
  16 + @Startup
  17 + @Transactional
  18 + public void load() {
  19 + if (findAll().isEmpty()) {
  20 + insert(new Bookmark("Demoiselle Portal", "http://www.frameworkdemoiselle.gov.br"));
  21 + insert(new Bookmark("Demoiselle SourceForge", "http://sf.net/projects/demoiselle"));
  22 + insert(new Bookmark("Twitter", "http://twitter.frameworkdemoiselle.gov.br"));
  23 + insert(new Bookmark("Blog", "http://blog.frameworkdemoiselle.gov.br"));
  24 + insert(new Bookmark("Wiki", "http://wiki.frameworkdemoiselle.gov.br"));
  25 + insert(new Bookmark("Bug Tracking", "http://tracker.frameworkdemoiselle.gov.br"));
  26 + insert(new Bookmark("Forum", "http://forum.frameworkdemoiselle.gov.br"));
  27 + insert(new Bookmark("SVN", "http://svn.frameworkdemoiselle.gov.br"));
  28 + insert(new Bookmark("Maven", "http://repository.frameworkdemoiselle.gov.br"));
  29 + insert(new Bookmark("Downloads", "http://download.frameworkdemoiselle.gov.br"));
  30 + }
  31 + }
  32 +
  33 +}
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/constant/readme.txt 0 → 100644
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/domain/Bookmark.java 0 → 100644
... ... @@ -0,0 +1,58 @@
  1 +package ${package}.domain;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +import javax.persistence.Column;
  6 +import javax.persistence.Entity;
  7 +import javax.persistence.GeneratedValue;
  8 +import javax.persistence.Id;
  9 +
  10 +@Entity
  11 +public class Bookmark implements Serializable {
  12 +
  13 + private static final long serialVersionUID = 1L;
  14 +
  15 + @Id
  16 + @GeneratedValue
  17 + private Long id;
  18 +
  19 + @Column
  20 + private String description;
  21 +
  22 + @Column
  23 + private String link;
  24 +
  25 + public Bookmark() {
  26 + super();
  27 + }
  28 +
  29 + public Bookmark(String description, String link) {
  30 + this.description = description;
  31 + this.link = link;
  32 + }
  33 +
  34 + public Long getId() {
  35 + return id;
  36 + }
  37 +
  38 + public void setId(Long id) {
  39 + this.id = id;
  40 + }
  41 +
  42 + public String getDescription() {
  43 + return description;
  44 + }
  45 +
  46 + public void setDescription(String description) {
  47 + this.description = description;
  48 + }
  49 +
  50 + public String getLink() {
  51 + return link;
  52 + }
  53 +
  54 + public void setLink(String link) {
  55 + this.link = link;
  56 + }
  57 +
  58 +}
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/exception/readme.txt 0 → 100644
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/message/readme.txt 0 → 100644
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/persistence/BookmarkDAO.java 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +package ${package}.persistence;
  2 +
  3 +import javax.inject.Inject;
  4 +
  5 +import org.slf4j.Logger;
  6 +
  7 +import br.gov.frameworkdemoiselle.stereotype.PersistenceController;
  8 +import br.gov.frameworkdemoiselle.template.JPACrud;
  9 +
  10 +import ${package}.domain.Bookmark;
  11 +
  12 +@PersistenceController
  13 +public class BookmarkDAO extends JPACrud<Bookmark, Long> {
  14 +
  15 + private static final long serialVersionUID = 1L;
  16 +
  17 + @Inject
  18 + @SuppressWarnings("unused")
  19 + private Logger logger;
  20 +
  21 +}
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/util/readme.txt 0 → 100644
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/view/BookmarkEditMB.java 0 → 100644
... ... @@ -0,0 +1,48 @@
  1 +package ${package}.view;
  2 +
  3 +import javax.inject.Inject;
  4 +
  5 +import br.gov.frameworkdemoiselle.annotation.PreviousView;
  6 +import br.gov.frameworkdemoiselle.stereotype.ViewController;
  7 +import br.gov.frameworkdemoiselle.template.AbstractEditPageBean;
  8 +import br.gov.frameworkdemoiselle.transaction.Transactional;
  9 +
  10 +import ${package}.business.BookmarkBC;
  11 +import ${package}.domain.Bookmark;
  12 +
  13 +@ViewController
  14 +@PreviousView("/bookmark_list.xhtml")
  15 +public class BookmarkEditMB extends AbstractEditPageBean<Bookmark, Long> {
  16 +
  17 + private static final long serialVersionUID = 1L;
  18 +
  19 + @Inject
  20 + private BookmarkBC bookmarkBC;
  21 +
  22 + @Override
  23 + @Transactional
  24 + public String delete() {
  25 + this.bookmarkBC.delete(getId());
  26 + return getPreviousView();
  27 + }
  28 +
  29 + @Override
  30 + @Transactional
  31 + public String insert() {
  32 + this.bookmarkBC.insert(getBean());
  33 + return getPreviousView();
  34 + }
  35 +
  36 + @Override
  37 + @Transactional
  38 + public String update() {
  39 + this.bookmarkBC.update(getBean());
  40 + return getPreviousView();
  41 + }
  42 +
  43 + @Override
  44 + protected void handleLoad() {
  45 + setBean(this.bookmarkBC.load(getId()));
  46 + }
  47 +
  48 +}
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/view/BookmarkListMB.java 0 → 100644
... ... @@ -0,0 +1,47 @@
  1 +package ${package}.view;
  2 +
  3 +import java.util.Iterator;
  4 +import java.util.List;
  5 +
  6 +import javax.inject.Inject;
  7 +
  8 +import br.gov.frameworkdemoiselle.annotation.NextView;
  9 +import br.gov.frameworkdemoiselle.annotation.PreviousView;
  10 +import br.gov.frameworkdemoiselle.stereotype.ViewController;
  11 +import br.gov.frameworkdemoiselle.template.AbstractListPageBean;
  12 +import br.gov.frameworkdemoiselle.transaction.Transactional;
  13 +
  14 +import ${package}.business.BookmarkBC;
  15 +import ${package}.domain.Bookmark;
  16 +
  17 +@ViewController
  18 +@NextView("/bookmark_edit.xhtml")
  19 +@PreviousView("/bookmark_list.xhtml")
  20 +public class BookmarkListMB extends AbstractListPageBean<Bookmark, Long> {
  21 +
  22 + private static final long serialVersionUID = 1L;
  23 +
  24 + @Inject
  25 + private BookmarkBC bc;
  26 +
  27 + @Override
  28 + protected List<Bookmark> handleResultList() {
  29 + return this.bc.findAll();
  30 + }
  31 +
  32 + @Transactional
  33 + public String deleteSelection() {
  34 + boolean delete;
  35 + for (Iterator<Long> iter = getSelection().keySet().iterator(); iter.hasNext();) {
  36 + Long id = iter.next();
  37 + delete = getSelection().get(id);
  38 +
  39 + if (delete) {
  40 + bc.delete(id);
  41 + iter.remove();
  42 + }
  43 + }
  44 + return getPreviousView();
  45 + }
  46 +
  47 +}
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/resources/META-INF/beans.xml 0 → 100644
... ... @@ -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 + <alternatives>
  5 + <class>br.gov.frameworkdemoiselle.transaction.JPATransaction</class>
  6 +
  7 + <!--
  8 + <class>br.gov.frameworkdemoiselle.transaction.JTATransaction</class>
  9 + -->
  10 + </alternatives>
  11 +</beans>
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/resources/META-INF/persistence.xml 0 → 100644
... ... @@ -0,0 +1,56 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  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">
  4 +
  5 + <!-- If you are using jboss6 with non JTA transaction then use this persistence-unit -->
  6 + <!--
  7 + -->
  8 + <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL">
  9 + <non-jta-data-source>java:/DefaultDS</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 + <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />
  18 + </properties>
  19 + </persistence-unit>
  20 +
  21 + <!-- If you are using jboss6 with JTA transaction then use this persistence-unit -->
  22 + <!--
  23 + <persistence-unit name="bookmark-ds" transaction-type="JTA">
  24 + <jta-data-source>java:/DefaultDS</jta-data-source>
  25 +
  26 + <class>${package}.domain.Bookmark</class>
  27 +
  28 + <properties>
  29 + <property name="hibernate.show_sql" value="true" />
  30 + <property name="hibernate.format_sql" value="false" />
  31 + <property name="hibernate.hbm2ddl.auto" value="update" />
  32 + <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />
  33 + </properties>
  34 + </persistence-unit>
  35 + -->
  36 +
  37 + <!-- If you are using tomcat6/tomcat7/junit then use this persistence-unit -->
  38 + <!--
  39 + <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL">
  40 +
  41 + <class>${package}.domain.Bookmark</class>
  42 +
  43 + <properties>
  44 + <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
  45 + <property name="javax.persistence.jdbc.user" value="sa" />
  46 + <property name="javax.persistence.jdbc.password" value="" />
  47 + <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:hsql:." />
  48 +
  49 + <property name="eclipselink.logging.level" value="FINE" />
  50 + <property name="eclipselink.ddl-generation" value="create-tables" />
  51 + <property name="eclipselink.ddl-generation.output-mode" value="database" />
  52 + </properties>
  53 + </persistence-unit>
  54 + -->
  55 +
  56 +</persistence>
0 57 \ No newline at end of file
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/resources/ValidationMessages.properties 0 → 100644
... ... @@ -0,0 +1,28 @@
  1 +br.gov.frameworkdemoiselle.pispasep=Informe um PIS/PASEP v\u00E1lido.
  2 +br.gov.frameworkdemoiselle.inscricaoestadual=Informe uma Inscri\u00E7\u00E3o Estadual v\u00E1lida.
  3 +br.gov.frameworkdemoiselle.cpf=Informe um CPF v\u00E1lido.
  4 +br.gov.frameworkdemoiselle.cnpj=Informe um CNPJ v\u00E1lido.
  5 +br.gov.frameworkdemoiselle.cep=Informe um CEP v\u00E1lido.
  6 +
  7 +javax.validation.constraints.AssertFalse.message=Este campo deve conter o valor falso.
  8 +javax.validation.constraints.AssertTrue.message=Este campo deve conter o valor verdadeiro.
  9 +javax.validation.constraints.DecimalMax.message=O valor deve ser menor ou igual a {value}.
  10 +javax.validation.constraints.DecimalMin.message=O valor deve ser maior ou igual a {value}.
  11 +javax.validation.constraints.Digits.message=Valor num\u00E9rico incorreto. (<{integer} d\u00EDgitos>.<{fraction} d\u00EDgitos> esperado).
  12 +javax.validation.constraints.Future.message=Deve ser uma data no futuro.
  13 +javax.validation.constraints.Max.message=O valor deve ser menor ou igual a {value}.
  14 +javax.validation.constraints.Min.message=O valor deve ser maior ou igual a {value}.
  15 +javax.validation.constraints.NotNull.message=N\u00E3o pode ser nulo.
  16 +javax.validation.constraints.Null.message=Deve ser nulo.
  17 +javax.validation.constraints.Past.message=Deve ser uma data no passado.
  18 +javax.validation.constraints.Pattern.message=O valor deve seguir o padr\u00E3o "{regexp}".
  19 +javax.validation.constraints.Size.message=O tamanho deve ser entre {min} e {max}.
  20 +
  21 +org.hibernate.validator.constraints.Email.message=E-mail inv\u00E1lido.
  22 +org.hibernate.validator.constraints.Length.message=O tamanho deve ser entre {min} e {max}.
  23 +org.hibernate.validator.constraints.NotBlank.message=N\u00E3o pode ser vazio.
  24 +org.hibernate.validator.constraints.NotEmpty.message=N\u00E3o pode ser vazio.
  25 +org.hibernate.validator.constraints.Range.message=Deve ser um valor entre {min} e {max}.
  26 +org.hibernate.validator.constraints.URL.message=Endere\u00E7o de Internet inv\u00E1lido.
  27 +org.hibernate.validator.constraints.CreditCardNumber.message=N\u00FAmero de cart\u00E3o de cr\u00E9dito inv\u00E1lido.
  28 +org.hibernate.validator.constraints.ScriptAssert.message=Express\u00E3o de script "{script}" n\u00E3o avaliada como verdadeira.
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/resources/demoiselle.properties 0 → 100755
... ... @@ -0,0 +1,35 @@
  1 +# Demoiselle Framework
  2 +# Copyright (C) 2010 SERPRO
  3 +# ----------------------------------------------------------------------------
  4 +# This file is part of Demoiselle Framework.
  5 +#
  6 +# Demoiselle Framework is free software; you can redistribute it and/or
  7 +# modify it under the terms of the GNU Lesser General Public License version 3
  8 +# as published by the Free Software Foundation.
  9 +#
  10 +# This program is distributed in the hope that it will be useful,
  11 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13 +# GNU General Public License for more details.
  14 +#
  15 +# You should have received a copy of the GNU Lesser General Public License version 3
  16 +# along with this program; if not, see <http://www.gnu.org/licenses/>
  17 +# or write to the Free Software Foundation, Inc., 51 Franklin Street,
  18 +# Fifth Floor, Boston, MA 02110-1301, USA.
  19 +# ----------------------------------------------------------------------------
  20 +# Este arquivo é parte do Framework Demoiselle.
  21 +#
  22 +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  23 +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  24 +# do Software Livre (FSF).
  25 +#
  26 +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  27 +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  28 +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  29 +# para maiores detalhes.
  30 +#
  31 +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  32 +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  33 +# ou escreva para a Fundação do Software Livre (FSF) Inc.,
  34 +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  35 +
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/resources/log4j.properties 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +# Set root logger level to DEBUG and its only appender to A1.
  2 +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
  7 +
  8 +# A1 uses PatternLayout.
  9 +log4j.appender.A1.layout=org.apache.log4j.PatternLayout
  10 +log4j.appender.A1.layout.ConversionPattern=%-4r %-5p %c - %m%n
0 11 \ No newline at end of file
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/resources/messages.properties 0 → 100644
... ... @@ -0,0 +1,45 @@
  1 +menu.bookmark=Bookmarks
  2 +bookmark.label=Bookmark
  3 +
  4 +bookmark-delete-ok=Bookmark exclu\u00EDdo\: {0}
  5 +bookmark-insert-ok=Bookmark inserido: {0}
  6 +bookmark-update-ok=Bookmark atualizado: {0}
  7 +
  8 +bookmark.list.table.title=Lista de Links
  9 +
  10 +bookmark.label.id=ID
  11 +bookmark.label.link=Link
  12 +bookmark.label.description=Descri\u00E7\u00E3o
  13 +
  14 +bookmark.alt.id=ID
  15 +bookmark.alt.link=Link
  16 +bookmark.alt.description=Descri\u00E7\u00E3o
  17 +
  18 +button.add.new=Incluir Novo
  19 +button.back=Voltar
  20 +button.delete=Excluir
  21 +button.dialog.no=N\u00E3o, desculpe\!
  22 +button.dialog.yes=Sim, claro!
  23 +button.edit=Editar
  24 +button.new=Novo
  25 +button.save=Salvar
  26 +
  27 +label.action=A\u00E7\u00E3o
  28 +label.dialog.alert=Alerta
  29 +label.dialog.delete=Excluir
  30 +label.confirm.delete=Confirma?
  31 +label.date.pattern=dd/MM/yyyy
  32 +
  33 +main.app.title=Bookmarks
  34 +main.app.welcome=Bem-vindo \u00E0 aplica\u00E7\u00E3o de exemplo Bookmark. Este \u00E9 o seu ponto de partida, portanto sinta-se \u00E0 vontade para modificar esta aplica\u00E7\u00E3o.
  35 +main.change.skin=Mudar Pele
  36 +main.skin=Pele
  37 +main.footer.text=Aplica\u00E7\u00E3o de exemplo do Demoiselle ${parent.version}
  38 +
  39 +menu.language=Idioma
  40 +menu.menuitem.language-portuguese=Portugu\u00EAs
  41 +menu.menuitem.language-english=Ingl\u00EAs
  42 +menu.menuitem.contents=Conte\u00FAdo
  43 +menu.menuitem.list=Listar
  44 +menu.menuitem.new=Novo
  45 +menu.menuitem.quit=Sair
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/faces-config.xml 0 → 100755
... ... @@ -0,0 +1,5 @@
  1 +<?xml version="1.0"?>
  2 +<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xi="http://www.w3.org/2001/XInclude"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
  4 +
  5 +</faces-config>
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml 0 → 100755
... ... @@ -0,0 +1,33 @@
  1 +<?xml version="1.0"?>
  2 +<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
  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">
  5 +
  6 + <!-- If you are using tomcat6/tomcat7 then uncomment this listener -->
  7 + <!--
  8 + <listener>
  9 + <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
  10 + </listener>
  11 + -->
  12 +
  13 + <servlet>
  14 + <servlet-name>Faces Servlet</servlet-name>
  15 + <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  16 + <load-on-startup>1</load-on-startup>
  17 + </servlet>
  18 +
  19 + <servlet-mapping>
  20 + <servlet-name>Faces Servlet</servlet-name>
  21 + <url-pattern>*.jsf</url-pattern>
  22 + </servlet-mapping>
  23 +
  24 + <security-constraint>
  25 + <display-name>Restrict raw XHTML Documents</display-name>
  26 + <web-resource-collection>
  27 + <web-resource-name>XHTML</web-resource-name>
  28 + <url-pattern>*.xhtml</url-pattern>
  29 + </web-resource-collection>
  30 + <auth-constraint />
  31 + </security-constraint>
  32 +
  33 +</web-app>
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/bookmark_edit.xhtml 0 → 100644
... ... @@ -0,0 +1,44 @@
  1 +<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
  2 + xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:h="http://java.sun.com/jsf/html"
  3 + xmlns:ui="http://java.sun.com/jsf/facelets" template="/template/main.xhtml">
  4 +
  5 + <ui:define name="body">
  6 + <h:form prependId="false">
  7 + <p:toolbar>
  8 + <p:toolbarGroup align="left">
  9 + <p:commandButton value="#{messages['button.save']}" action="#{bookmarkEditMB.insert}"
  10 + rendered="#{!bookmarkEditMB.updateMode}" ajax="false" />
  11 + <p:commandButton value="#{messages['button.save']}" action="#{bookmarkEditMB.update}"
  12 + rendered="#{bookmarkEditMB.updateMode}" ajax="false" />
  13 + <p:commandButton value="#{messages['button.delete']}" onclick="confirmation.show()"
  14 + rendered="#{bookmarkEditMB.updateMode}" type="button" immediate="true" ajax="false" />
  15 + <p:confirmDialog message="#{messages['label.confirm.delete']}" showEffect="bounce" hideEffect="explode"
  16 + header="#{messages['label.dialog.delete']}" severity="alert" widgetVar="confirmation">
  17 + <h:commandButton value="#{messages['button.dialog.yes']}" action="#{bookmarkEditMB.delete}" immediate="true"
  18 + ajax="false" />
  19 + <h:commandButton value="#{messages['button.dialog.no']}" onclick="confirmation.hide()" type="button" />
  20 + </p:confirmDialog>
  21 + </p:toolbarGroup>
  22 + </p:toolbar>
  23 +
  24 + <br />
  25 +
  26 + <p:fieldset legend="#{messages['bookmark.label']}" toggleable="true" toggleSpeed="500">
  27 + <h:panelGrid id="fields" columns="3">
  28 + <h:outputLabel value="#{messages['bookmark.label.id']}: " for="id" styleClass="text-input" />
  29 + <h:outputText id="id" value="#{bookmarkEditMB.bean.id}" />
  30 + <p:message for="id" />
  31 +
  32 + <h:outputLabel value="#{messages['bookmark.label.description']}: " for="description" styleClass="text-input" />
  33 + <h:inputText id="description" value="#{bookmarkEditMB.bean.description}"
  34 + title="#{messages['bookmark.alt.description']}" />
  35 + <p:message for="description" />
  36 +
  37 + <h:outputLabel value="#{messages['bookmark.label.link']}: " for="link" styleClass="text-input" />
  38 + <h:inputText id="link" value="#{bookmarkEditMB.bean.link}" title="#{messages['bookmark.alt.link']}" />
  39 + <p:message for="link" />
  40 + </h:panelGrid>
  41 + </p:fieldset>
  42 + </h:form>
  43 + </ui:define>
  44 +</ui:composition>
0 45 \ No newline at end of file
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/bookmark_list.xhtml 0 → 100644
... ... @@ -0,0 +1,51 @@
  1 +<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
  2 + xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:h="http://java.sun.com/jsf/html"
  3 + xmlns:ui="http://java.sun.com/jsf/facelets" template="/template/main.xhtml">
  4 +
  5 + <ui:define name="body">
  6 + <h:form>
  7 + <p:toolbar>
  8 + <p:toolbarGroup align="left">
  9 + <p:commandButton title="#{messages['button.new']}" image="ui-icon-document" action="#{bookmarkListMB.getNextView}"
  10 + actionListener="#{bookmarkListMB.clear}" ajax="false" />
  11 +
  12 + <p:commandButton title="#{messages['button.delete']}" image="ui-icon-trash" onclick="confirmation.show()"
  13 + type="button" immediate="true" ajax="false" />
  14 +
  15 + <p:confirmDialog message="#{messages['label.confirm.delete']}" showEffect="bounce" hideEffect="explode"
  16 + header="#{messages['label.dialog.alert']}!" severity="alert" widgetVar="confirmation">
  17 +
  18 + <h:commandButton value="#{messages['button.dialog.yes']}" action="#{bookmarkListMB.deleteSelection}"
  19 + actionListener="#{bookmarkListMB.clear}" />
  20 + <h:commandButton value="#{messages['button.dialog.no']}" onclick="confirmation.hide()" type="button" />
  21 + </p:confirmDialog>
  22 + </p:toolbarGroup>
  23 + </p:toolbar>
  24 +
  25 + <p:dataTable id="list" var="bean" value="#{bookmarkListMB.resultList}">
  26 + <f:facet name="header">#{messages['bookmark.list.table.title']}</f:facet>
  27 + <p:column style="width:5%;">
  28 + <h:selectBooleanCheckbox value="#{bookmarkListMB.selection[bean.id]}" />
  29 + </p:column>
  30 + <p:column style="width:5%;" sortBy="#{bean.id}">
  31 + <f:facet name="header">#{messages['bookmark.label.id']}</f:facet>
  32 + <h:outputText value="#{bean.id}" />
  33 + </p:column>
  34 + <p:column sortBy="#{bean.description}">
  35 + <f:facet name="header">#{messages['bookmark.label.description']}</f:facet>
  36 + <h:commandLink action="#{bookmarkListMB.getNextView}" actionListener="#{bookmarkListMB.clear}">
  37 + <h:outputText value="#{bean.description}" />
  38 + <f:param name="id" value="#{bean.id}" />
  39 + </h:commandLink>
  40 + </p:column>
  41 + <p:column sortBy="#{bean.link}">
  42 + <f:facet name="header">#{messages['bookmark.label.link']}</f:facet>
  43 + <h:commandLink action="#{bookmarkListMB.getNextView}" actionListener="#{bookmarkListMB.clear}">
  44 + <h:outputText value="#{bean.link}" />
  45 + <f:param name="id" value="#{bean.id}" />
  46 + </h:commandLink>
  47 + </p:column>
  48 + </p:dataTable>
  49 + </h:form>
  50 + </ui:define>
  51 +</ui:composition>
0 52 \ No newline at end of file
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/images/logo.png 0 → 100644

7.21 KB

archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/index.html 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +<html>
  2 +<head>
  3 +<meta http-equiv="Refresh" content="0; URL=index.jsf">
  4 +</head>
  5 +</html>
0 6 \ No newline at end of file
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/index.xhtml 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
  2 + xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:h="http://java.sun.com/jsf/html"
  3 + xmlns:ui="http://java.sun.com/jsf/facelets" template="/template/main.xhtml">
  4 +
  5 + <ui:define name="body">
  6 + <p:panel>
  7 + #{messages['main.app.welcome']}
  8 + </p:panel>
  9 + </ui:define>
  10 +
  11 +</ui:composition>
0 12 \ No newline at end of file
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/menu.xhtml 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
  2 + xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:h="http://java.sun.com/jsf/html"
  3 + xmlns:ui="http://java.sun.com/jsf/facelets">
  4 +
  5 + <h:form>
  6 + <p:menubar>
  7 + <p:submenu label="#{messages['menu.bookmark']}">
  8 + <p:menuitem value="#{messages['menu.menuitem.new']}" url="/bookmark_edit.jsf" />
  9 + <p:menuitem value="#{messages['menu.menuitem.list']}" url="/bookmark_list.jsf" />
  10 + </p:submenu>
  11 +
  12 + <p:menuitem value="#{messages['menu.menuitem.quit']}" url="http://www.frameworkdemoiselle.gov.br/"
  13 + action="#{securityContext.logout}" />
  14 + </p:menubar>
  15 + </h:form>
  16 +
  17 +</ui:composition>
0 18 \ No newline at end of file
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/template/main.xhtml 0 → 100644
... ... @@ -0,0 +1,40 @@
  1 +<html xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.prime.com.tr/ui"
  2 + xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets">
  3 +
  4 +<f:view contentType="text/html" locale="#{currentLocale}" />
  5 +
  6 +<h:head>
  7 + <title>#{messages['main.app.title']}</title>
  8 + <link type="text/css" rel="stylesheet" href="css/styles.css" />
  9 +</h:head>
  10 +
  11 +<h:body style="background-color:#f1f1f1">
  12 + <table style="width: 100%">
  13 + <tr>
  14 + <td height="70" width="5%" align="left"><a href="index.jsf"><img src="images/logo.png" border="0" /></a></td>
  15 + <td height="70" width="95%" align="left"><p:themeSwitcher initialText="Change Skin" buttonPreText="Skin: " /></td>
  16 + </tr>
  17 + <tr>
  18 + <td height="20" colspan="2"><ui:include src="/menu.xhtml" /></td>
  19 + </tr>
  20 + <tr valign="top">
  21 + <td height="400" colspan="2"><ui:insert name="body" /></td>
  22 + </tr>
  23 + <tr align="center">
  24 + <td height="20" colspan="2" align="center" class="text-input">#{messages['main.footer.text']}</td>
  25 + </tr>
  26 + </table>
  27 +
  28 + <p:growl id="messages" globalOnly="true" />
  29 +
  30 + <p:ajaxStatus style="width:16px;height:16px;">
  31 + <f:facet name="start">
  32 + </f:facet>
  33 +
  34 + <f:facet name="complete">
  35 + <h:outputText value="" />
  36 + </f:facet>
  37 + </p:ajaxStatus>
  38 + <link type="text/css" rel="stylesheet" href="css/aristo/skin.css" />
  39 +</h:body>
  40 +</html>
0 41 \ No newline at end of file
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/test/java/business/BookmarkBCTest.java 0 → 100644
... ... @@ -0,0 +1,77 @@
  1 +package ${package}.business;
  2 +
  3 +import static org.junit.Assert.assertEquals;
  4 +import static org.junit.Assert.assertNotNull;
  5 +
  6 +import java.util.List;
  7 +
  8 +import javax.inject.Inject;
  9 +
  10 +import org.junit.Before;
  11 +import org.junit.Test;
  12 +import org.junit.runner.RunWith;
  13 +
  14 +import br.gov.frameworkdemoiselle.junit.DemoiselleRunner;
  15 +import ${package}.domain.Bookmark;
  16 +
  17 +@RunWith(DemoiselleRunner.class)
  18 +public class BookmarkBCTest {
  19 +
  20 + @Inject
  21 + private BookmarkBC bookmarkBC;
  22 +
  23 + @Before
  24 + public void before() {
  25 + for (Bookmark bookmark : bookmarkBC.findAll()) {
  26 + bookmarkBC.delete(bookmark.getId());
  27 + }
  28 + }
  29 +
  30 + @Test
  31 + public void testLoad() {
  32 + bookmarkBC.load();
  33 + List<Bookmark> listaBookmarks = bookmarkBC.findAll();
  34 + assertNotNull(listaBookmarks);
  35 + assertEquals(10, listaBookmarks.size());
  36 + }
  37 +
  38 + @Test
  39 + public void testInsert() {
  40 + Bookmark bookmark = new Bookmark("Demoiselle Portal", "http://www.frameworkdemoiselle.gov.br");
  41 + bookmarkBC.insert(bookmark);
  42 + List<Bookmark> listaBookmarks = bookmarkBC.findAll();
  43 + assertNotNull(listaBookmarks);
  44 + assertEquals(1, listaBookmarks.size());
  45 + }
  46 +
  47 + @Test
  48 + public void testDelete() {
  49 + Bookmark bookmark = new Bookmark("Demoiselle Portal", "http://www.frameworkdemoiselle.gov.br");
  50 + bookmarkBC.insert(bookmark);
  51 +
  52 + List<Bookmark> listaBookmarks = bookmarkBC.findAll();
  53 + assertNotNull(listaBookmarks);
  54 + assertEquals(1, listaBookmarks.size());
  55 +
  56 + bookmarkBC.delete(bookmark.getId());
  57 + listaBookmarks = bookmarkBC.findAll();
  58 + assertEquals(0, listaBookmarks.size());
  59 + }
  60 + @Test
  61 + public void testUpdate() {
  62 + Bookmark bookmark = new Bookmark("Demoiselle Portal", "http://www.frameworkdemoiselle.gov.br");
  63 + bookmarkBC.insert(bookmark);
  64 +
  65 + List<Bookmark> listaBookmarks = bookmarkBC.findAll();
  66 + Bookmark bookmark2 = (Bookmark)listaBookmarks.get(0);
  67 + assertNotNull(listaBookmarks);
  68 + assertEquals("Demoiselle Portal", bookmark2.getDescription());
  69 +
  70 + bookmark2.setDescription("Demoiselle Portal alterado");
  71 + bookmarkBC.update(bookmark2);
  72 +
  73 + listaBookmarks = bookmarkBC.findAll();
  74 + Bookmark bookmark3 = (Bookmark)listaBookmarks.get(0);
  75 + assertEquals("Demoiselle Portal alterado", bookmark3.getDescription());
  76 + }
  77 +}
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/test/java/readme.txt 0 → 100755
... ... @@ -0,0 +1 @@
  1 +resource files to test
0 2 \ No newline at end of file
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/test/resources/META-INF/beans.xml 0 → 100644
... ... @@ -0,0 +1,4 @@
  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 +</beans>
... ...
archetype/jsf-jpa/src/main/resources/archetype-resources/src/test/resources/META-INF/persistence.xml 0 → 100644
... ... @@ -0,0 +1,60 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  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">
  4 +
  5 + <!-- If you are using tomcat6/tomcat7/junit then use this persistence-unit -->
  6 + <!--
  7 + -->
  8 + <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL">
  9 +
  10 + <class>${package}.domain.Bookmark</class>
  11 +
  12 + <properties>
  13 + <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
  14 + <property name="javax.persistence.jdbc.user" value="sa" />
  15 + <property name="javax.persistence.jdbc.password" value="" />
  16 + <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:hsql:." />
  17 +
  18 + <property name="hibernate.show_sql" value="true" />
  19 + <property name="hibernate.format_sql" value="false" />
  20 + <property name="hibernate.hbm2ddl.auto" value="create-drop" />
  21 +
  22 + <property name="eclipselink.logging.level" value="FINE" />
  23 + <property name="eclipselink.ddl-generation" value="create-tables" />
  24 + <property name="eclipselink.ddl-generation.output-mode" value="database" />
  25 + </properties>
  26 + </persistence-unit>
  27 +
  28 + <!-- If you are using jboss6 with non JTA transaction then use this persistence-unit -->
  29 + <!--
  30 + <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL">
  31 + <non-jta-data-source>java:/DefaultDS</non-jta-data-source>
  32 +
  33 + <class>${package}.domain.Bookmark</class>
  34 +
  35 + <properties>
  36 + <property name="hibernate.show_sql" value="true" />
  37 + <property name="hibernate.format_sql" value="false" />
  38 + <property name="hibernate.hbm2ddl.auto" value="update" />
  39 + <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />
  40 + </properties>
  41 + </persistence-unit>
  42 + -->
  43 +
  44 + <!-- If you are using jboss6 with JTA transaction then use this persistence-unit -->
  45 + <!--
  46 + <persistence-unit name="bookmark-ds" transaction-type="JTA">
  47 + <jta-data-source>java:/DefaultDS</jta-data-source>
  48 +
  49 + <class>${package}.domain.Bookmark</class>
  50 +
  51 + <properties>
  52 + <property name="hibernate.show_sql" value="true" />
  53 + <property name="hibernate.format_sql" value="false" />
  54 + <property name="hibernate.hbm2ddl.auto" value="update" />
  55 + <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />
  56 + </properties>
  57 + </persistence-unit>
  58 + -->
  59 +
  60 +</persistence>
0 61 \ No newline at end of file
... ...
archetype/minimal/.gitignore 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +/target
  2 +/.project
  3 +/.classpath
  4 +/.settings
  5 +/.externalToolBuilders
... ...
archetype/minimal/pom.xml 0 → 100755
... ... @@ -0,0 +1,62 @@
  1 +<!--
  2 + Demoiselle Framework
  3 + Copyright (C) 2010 SERPRO
  4 + ============================================================================
  5 + This file is part of Demoiselle Framework.
  6 +
  7 + Demoiselle Framework is free software; you can redistribute it and/or
  8 + modify it under the terms of the GNU Lesser General Public License version 3
  9 + as published by the Free Software Foundation.
  10 +
  11 + This program is distributed in the hope that it will be useful,
  12 + but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + GNU General Public License for more details.
  15 +
  16 + You should have received a copy of the GNU Lesser General Public License version 3
  17 + along with this program; if not, see <http://www.gnu.org/licenses />
  18 + or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + Fifth Floor, Boston, MA 02110-1301, USA.
  20 + ============================================================================
  21 + Este arquivo é parte do Framework Demoiselle.
  22 +
  23 + O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + do Software Livre (FSF).
  26 +
  27 + Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + para maiores detalhes.
  31 +
  32 + Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses />
  34 + ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 +-->
  37 +<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.archetypes</groupId>
  42 + <artifactId>demoiselle-minimal</artifactId>
  43 + <packaging>jar</packaging>
  44 +
  45 + <parent>
  46 + <groupId>br.gov.frameworkdemoiselle</groupId>
  47 + <artifactId>demoiselle-archetype-parent</artifactId>
  48 + <version>2.2.1-SNAPSHOT</version>
  49 + <relativePath>../../parent/archetype/pom.xml</relativePath>
  50 + </parent>
  51 +
  52 + <name>Minimal Archetype</name>
  53 + <description>Basic archetype for generic applications</description>
  54 +
  55 + <repositories>
  56 + <repository>
  57 + <id>demoiselle.sourceforge.net</id>
  58 + <name>Demoiselle Maven Repository</name>
  59 + <url>http://demoiselle.sourceforge.net/repository/release</url>
  60 + </repository>
  61 + </repositories>
  62 +</project>
... ...
archetype/minimal/src/main/resources/META-INF/maven/archetype-metadata.xml 0 → 100755
... ... @@ -0,0 +1,63 @@
  1 +<!--
  2 + Demoiselle Framework
  3 + Copyright (C) 2010 SERPRO
  4 + ============================================================================
  5 + This file is part of Demoiselle Framework.
  6 +
  7 + Demoiselle Framework is free software; you can redistribute it and/or
  8 + modify it under the terms of the GNU Lesser General Public License version 3
  9 + as published by the Free Software Foundation.
  10 +
  11 + This program is distributed in the hope that it will be useful,
  12 + but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + GNU General Public License for more details.
  15 +
  16 + You should have received a copy of the GNU Lesser General Public License version 3
  17 + along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + Fifth Floor, Boston, MA 02110-1301, USA.
  20 + ============================================================================
  21 + Este arquivo é parte do Framework Demoiselle.
  22 +
  23 + O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + do Software Livre (FSF).
  26 +
  27 + Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + para maiores detalhes.
  31 +
  32 + Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 +-->
  37 +<archetype-descriptor xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
  38 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  39 + xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
  40 + name="#{project.artifactId}">
  41 +
  42 + <fileSets>
  43 + <fileSet filtered="true" packaged="false">
  44 + <directory />
  45 + <includes>
  46 + <include>readme.txt</include>
  47 + </includes>
  48 + </fileSet>
  49 + <fileSet filtered="true" packaged="true">
  50 + <directory>src/main/java</directory>
  51 + </fileSet>
  52 + <fileSet filtered="true" packaged="false">
  53 + <directory>src/main/resources</directory>
  54 + </fileSet>
  55 + <fileSet filtered="true" packaged="true">
  56 + <directory>src/test/java</directory>
  57 + </fileSet>
  58 + <fileSet filtered="true" packaged="false">
  59 + <directory>src/test/resources</directory>
  60 + </fileSet>
  61 + </fileSets>
  62 +
  63 +</archetype-descriptor>
0 64 \ No newline at end of file
... ...
archetype/minimal/src/main/resources/archetype-resources/pom.xml 0 → 100755
... ... @@ -0,0 +1,36 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
  3 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  4 +
  5 + <modelVersion>4.0.0</modelVersion>
  6 +
  7 + <groupId>${groupId}</groupId>
  8 + <artifactId>${artifactId}</artifactId>
  9 + <version>${version}</version>
  10 + <packaging>jar</packaging>
  11 +
  12 + <name></name>
  13 + <description></description>
  14 + <url></url>
  15 +
  16 + <parent>
  17 + <groupId>br.gov.frameworkdemoiselle</groupId>
  18 + <artifactId>demoiselle-minimal-parent</artifactId>
  19 + <version>#{parent.version}</version>
  20 + </parent>
  21 +
  22 + <dependencies>
  23 + <dependency>
  24 + <groupId>org.slf4j</groupId>
  25 + <artifactId>slf4j-log4j12</artifactId>
  26 + <scope>test</scope>
  27 + </dependency>
  28 + </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>
0 37 \ No newline at end of file
... ...
archetype/minimal/src/main/resources/archetype-resources/src/main/java/HelloWorld.java 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +package ${package};
  2 +
  3 +import javax.inject.Inject;
  4 +
  5 +import org.slf4j.Logger;
  6 +
  7 +public class HelloWorld {
  8 +
  9 + @Inject
  10 + private Logger logger;
  11 +
  12 + public void say() {
  13 + logger.info("Saying hello on console");
  14 + }
  15 +}
... ...
archetype/minimal/src/main/resources/archetype-resources/src/main/resources/META-INF/beans.xml 0 → 100644
... ... @@ -0,0 +1,4 @@
  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 +</beans>
... ...
archetype/minimal/src/main/resources/archetype-resources/src/main/resources/demoiselle.properties 0 → 100644
archetype/minimal/src/main/resources/archetype-resources/src/test/java/HelloWorldTest.java 0 → 100644
... ... @@ -0,0 +1,23 @@
  1 +package ${package};
  2 +
  3 +import static junit.framework.Assert.assertNotNull;
  4 +
  5 +import javax.inject.Inject;
  6 +
  7 +import org.junit.Test;
  8 +import org.junit.runner.RunWith;
  9 +
  10 +import br.gov.frameworkdemoiselle.junit.DemoiselleRunner;
  11 +
  12 +@RunWith(DemoiselleRunner.class)
  13 +public class HelloWorldTest {
  14 +
  15 + @Inject
  16 + private HelloWorld helloWorld;
  17 +
  18 + @Test
  19 + public void say() {
  20 + assertNotNull(helloWorld);
  21 + helloWorld.say();
  22 + }
  23 +}
... ...
archetype/minimal/src/main/resources/archetype-resources/src/test/resources/META-INF/beans.xml 0 → 100644
... ... @@ -0,0 +1,4 @@
  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 +</beans>
... ...
archetype/minimal/src/main/resources/archetype-resources/src/test/resources/log4j.properties 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +# Set root logger level to DEBUG and its only appender to A1.
  2 +log4j.rootLogger=INFO, A1
  3 +
  4 +# A1 is set to be a ConsoleAppender.
  5 +log4j.appender.A1=org.apache.log4j.ConsoleAppender
  6 +
  7 +# A1 uses PatternLayout.
  8 +log4j.appender.A1.layout=org.apache.log4j.PatternLayout
  9 +log4j.appender.A1.layout.ConversionPattern=%-4r %-5p %c - %m%n
0 10 \ No newline at end of file
... ...
archetype/pom.xml 0 → 100644
... ... @@ -0,0 +1,86 @@
  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 + <artifactId>demoiselle-archetype-build-aggregator</artifactId>
  42 + <packaging>pom</packaging>
  43 +
  44 + <parent>
  45 + <groupId>br.gov.frameworkdemoiselle</groupId>
  46 + <artifactId>demoiselle-parent</artifactId>
  47 + <version>2.2.1-SNAPSHOT</version>
  48 + <relativePath>../parent/root/pom.xml</relativePath>
  49 + </parent>
  50 +
  51 + <name>Archetypes Build Aggregator</name>
  52 + <description>
  53 + </description>
  54 +
  55 + <modules>
  56 + <module>jsf-jpa</module>
  57 + <module>minimal</module>
  58 + </modules>
  59 +
  60 + <build>
  61 + <plugins>
  62 + <plugin>
  63 + <groupId>org.codehaus.mojo</groupId>
  64 + <artifactId>wagon-maven-plugin</artifactId>
  65 + <configuration>
  66 + <skip>true</skip>
  67 + </configuration>
  68 + </plugin>
  69 + <plugin>
  70 + <groupId>org.apache.maven.plugins</groupId>
  71 + <artifactId>maven-deploy-plugin</artifactId>
  72 + <configuration>
  73 + <skip>true</skip>
  74 + </configuration>
  75 + </plugin>
  76 + </plugins>
  77 + </build>
  78 +
  79 + <repositories>
  80 + <repository>
  81 + <id>demoiselle.sourceforge.net</id>
  82 + <name>Demoiselle Maven Repository</name>
  83 + <url>http://demoiselle.sourceforge.net/repository/release</url>
  84 + </repository>
  85 + </repositories>
  86 +</project>
... ...
core/.gitignore 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +/target
  2 +/.project
  3 +/.classpath
  4 +/.settings
  5 +/.externalToolBuilders
... ...
core/pom.xml 0 → 100644
... ... @@ -0,0 +1,167 @@
  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 + <artifactId>demoiselle-core</artifactId>
  42 + <packaging>jar</packaging>
  43 +
  44 + <parent>
  45 + <groupId>br.gov.frameworkdemoiselle</groupId>
  46 + <artifactId>demoiselle-parent</artifactId>
  47 + <version>2.2.1-SNAPSHOT</version>
  48 + <relativePath>../parent/root/pom.xml</relativePath>
  49 + </parent>
  50 +
  51 + <organization>
  52 + <name>Serpro</name>
  53 + <url>http://www.serpro.gov.br</url>
  54 + </organization>
  55 +
  56 + <name>Core</name>
  57 + <description>
  58 + 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.
  60 + </description>
  61 +
  62 + <build>
  63 + <plugins>
  64 + <plugin>
  65 + <groupId>org.apache.maven.plugins</groupId>
  66 + <artifactId>maven-compiler-plugin</artifactId>
  67 + </plugin>
  68 + <plugin>
  69 + <groupId>org.apache.maven.plugins</groupId>
  70 + <artifactId>maven-javadoc-plugin</artifactId>
  71 + </plugin>
  72 + <plugin>
  73 + <groupId>org.apache.maven.plugins</groupId>
  74 + <artifactId>maven-source-plugin</artifactId>
  75 + </plugin>
  76 + <plugin>
  77 + <groupId>org.apache.maven.plugins</groupId>
  78 + <artifactId>maven-site-plugin</artifactId>
  79 + </plugin>
  80 + <plugin>
  81 + <groupId>org.codehaus.mojo</groupId>
  82 + <artifactId>cobertura-maven-plugin</artifactId>
  83 + </plugin>
  84 + </plugins>
  85 + </build>
  86 +
  87 + <dependencies>
  88 + <dependency>
  89 + <groupId>javax.enterprise</groupId>
  90 + <artifactId>cdi-api</artifactId>
  91 + </dependency>
  92 + <dependency>
  93 + <artifactId>validation-api</artifactId>
  94 + <groupId>javax.validation</groupId>
  95 + </dependency>
  96 + <dependency>
  97 + <groupId>org.slf4j</groupId>
  98 + <artifactId>slf4j-api</artifactId>
  99 + </dependency>
  100 + <dependency>
  101 + <groupId>commons-configuration</groupId>
  102 + <artifactId>commons-configuration</artifactId>
  103 + <exclusions>
  104 + <exclusion>
  105 + <artifactId>commons-digester</artifactId>
  106 + <groupId>commons-digester</groupId>
  107 + </exclusion>
  108 + <exclusion>
  109 + <artifactId>log4j</artifactId>
  110 + <groupId>log4j</groupId>
  111 + </exclusion>
  112 + <exclusion>
  113 + <artifactId>servlet-api</artifactId>
  114 + <groupId>javax.servlet</groupId>
  115 + </exclusion>
  116 + <exclusion>
  117 + <artifactId>logkit</artifactId>
  118 + <groupId>logkit</groupId>
  119 + </exclusion>
  120 + <exclusion>
  121 + <artifactId>avalon-framework</artifactId>
  122 + <groupId>avalon-framework</groupId>
  123 + </exclusion>
  124 + </exclusions>
  125 + </dependency>
  126 +
  127 + <!-- for tests -->
  128 + <dependency>
  129 + <groupId>junit</groupId>
  130 + <artifactId>junit</artifactId>
  131 + <scope>test</scope>
  132 + </dependency>
  133 + <dependency>
  134 + <groupId>org.easymock</groupId>
  135 + <artifactId>easymock</artifactId>
  136 + <scope>test</scope>
  137 + </dependency>
  138 + <dependency>
  139 + <groupId>org.powermock</groupId>
  140 + <artifactId>powermock-module-junit4</artifactId>
  141 + <scope>test</scope>
  142 + </dependency>
  143 + <dependency>
  144 + <groupId>org.powermock</groupId>
  145 + <artifactId>powermock-api-easymock</artifactId>
  146 + <scope>test</scope>
  147 + </dependency>
  148 + <dependency>
  149 + <groupId>javax.el</groupId>
  150 + <artifactId>el-api</artifactId>
  151 + <scope>test</scope>
  152 + </dependency>
  153 + <dependency>
  154 + <groupId>org.slf4j</groupId>
  155 + <artifactId>slf4j-log4j12</artifactId>
  156 + <scope>test</scope>
  157 + </dependency>
  158 + </dependencies>
  159 +
  160 + <repositories>
  161 + <repository>
  162 + <id>demoiselle.sourceforge.net</id>
  163 + <name>Demoiselle Maven Repository</name>
  164 + <url>http://demoiselle.sourceforge.net/repository/release</url>
  165 + </repository>
  166 + </repositories>
  167 +</project>
... ...
core/src/main/java/br/gov/frameworkdemoiselle/DemoiselleException.java 0 → 100644
... ... @@ -0,0 +1,79 @@
  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;
  38 +
  39 +/**
  40 + * Exception class intended to be used by framework configuration and to be derived by other framework exceptions.
  41 + *
  42 + * @author SERPRO
  43 + */
  44 +public class DemoiselleException extends RuntimeException {
  45 +
  46 + private static final long serialVersionUID = 1L;
  47 +
  48 + /**
  49 + * Constructor with message.
  50 + *
  51 + * @param message
  52 + * exception message
  53 + */
  54 + public DemoiselleException(String message) {
  55 + super(message);
  56 + }
  57 +
  58 + /**
  59 + * Constructor with cause.
  60 + *
  61 + * @param cause
  62 + * exception cause
  63 + */
  64 + public DemoiselleException(Throwable cause) {
  65 + super(cause);
  66 + }
  67 +
  68 + /**
  69 + * Constructor with message and cause.
  70 + *
  71 + * @param message
  72 + * exception message
  73 + * @param cause
  74 + * exception cause
  75 + */
  76 + public DemoiselleException(String message, Throwable cause) {
  77 + super(message, cause);
  78 + }
  79 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/annotation/Ignore.java 0 → 100644
... ... @@ -0,0 +1,48 @@
  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.FIELD;
  40 +import static java.lang.annotation.RetentionPolicy.RUNTIME;
  41 +
  42 +import java.lang.annotation.Retention;
  43 +import java.lang.annotation.Target;
  44 +
  45 +@Target(FIELD)
  46 +@Retention(RUNTIME)
  47 +public @interface Ignore {
  48 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/annotation/Name.java 0 → 100644
... ... @@ -0,0 +1,59 @@
  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.FIELD;
  40 +import static java.lang.annotation.ElementType.METHOD;
  41 +import static java.lang.annotation.ElementType.PARAMETER;
  42 +import static java.lang.annotation.ElementType.TYPE;
  43 +import static java.lang.annotation.RetentionPolicy.RUNTIME;
  44 +
  45 +import java.lang.annotation.Inherited;
  46 +import java.lang.annotation.Retention;
  47 +import java.lang.annotation.Target;
  48 +
  49 +import javax.enterprise.util.Nonbinding;
  50 +
  51 +@Inherited
  52 +@Retention(RUNTIME)
  53 +@Target({ TYPE, FIELD, METHOD, PARAMETER })
  54 +public @interface Name {
  55 +
  56 + @Nonbinding
  57 + String value();
  58 +
  59 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/annotation/Shutdown.java 0 → 100644
... ... @@ -0,0 +1,91 @@
  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 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/annotation/Startup.java 0 → 100644
... ... @@ -0,0 +1,90 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.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 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/annotation/ViewScoped.java 0 → 100644
... ... @@ -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.annotation;
  38 +
  39 +import static java.lang.annotation.ElementType.FIELD;
  40 +import static java.lang.annotation.ElementType.METHOD;
  41 +import static java.lang.annotation.ElementType.TYPE;
  42 +import static java.lang.annotation.RetentionPolicy.RUNTIME;
  43 +
  44 +import java.lang.annotation.Inherited;
  45 +import java.lang.annotation.Retention;
  46 +import java.lang.annotation.Target;
  47 +
  48 +import javax.enterprise.context.NormalScope;
  49 +
  50 +@Inherited
  51 +@Target({ METHOD, TYPE, FIELD })
  52 +@Retention(RUNTIME)
  53 +@NormalScope
  54 +public @interface ViewScoped {
  55 +
  56 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/configuration/ConfigType.java 0 → 100644
... ... @@ -0,0 +1,61 @@
  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.configuration;
  38 +
  39 +/**
  40 + * Defines configuration types to be loaded.
  41 + *
  42 + * @author SERPRO
  43 + */
  44 +public enum ConfigType {
  45 +
  46 + /**
  47 + * Configuration loaded on {@link System#getProperties()} or {@link System#getenv()}.
  48 + */
  49 + SYSTEM,
  50 +
  51 + /**
  52 + * Configuration loaded on XML resources.
  53 + */
  54 + XML,
  55 +
  56 + /**
  57 + * Configuration loaded on properties resources.
  58 + */
  59 + PROPERTIES;
  60 +
  61 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/configuration/Configuration.java 0 → 100644
... ... @@ -0,0 +1,106 @@
  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.configuration;
  38 +
  39 +import static java.lang.annotation.ElementType.TYPE;
  40 +import static java.lang.annotation.RetentionPolicy.RUNTIME;
  41 +
  42 +import java.lang.annotation.Inherited;
  43 +import java.lang.annotation.Retention;
  44 +import java.lang.annotation.Target;
  45 +
  46 +import javax.enterprise.inject.Stereotype;
  47 +import javax.inject.Singleton;
  48 +
  49 +/**
  50 + * Identifies a <b>configuration class</b>, that is, a structure reserved to store configuration values retrieved from a
  51 + * given resource file or system variables.
  52 + * <p>
  53 + * This class is gonna have a single instance throughout the application, as stated by the <b>singleton</b> design
  54 + * pattern approach.
  55 + * <p>
  56 + * A <i>Configuration</i> is:
  57 + * <ul>
  58 + * <li>defined when annotated with {@code @Configuration}</li>
  59 + * <li>automatically injected whenever {@code @Inject} is used</li>
  60 + * </ul>
  61 + *
  62 + * @author SERPRO
  63 + */
  64 +@Singleton
  65 +@Stereotype
  66 +@Inherited
  67 +@Target(TYPE)
  68 +@Retention(RUNTIME)
  69 +public @interface Configuration {
  70 +
  71 + public static final String DEFAULT_RESOURCE = "demoiselle";
  72 +
  73 + /**
  74 + * Defines the resource type to be used: a properties file, an XML file, or system variables.
  75 + * <p>
  76 + * If not specified, a properties resource file is to be considered.
  77 + *
  78 + * @return ConfigType
  79 + */
  80 + ConfigType type() default ConfigType.PROPERTIES;
  81 +
  82 + /**
  83 + * Defines an optional prefix to be used on every parameter key.
  84 + * <p>
  85 + * For instance, if prefix is set to <code>"frameworkdemoiselle.pagination"</code> and an attribute named
  86 + * <code>defaultPageSize</code> is found in the class, the corresponding key
  87 + * <code>frameworkdemoiselle.pagination.defaultPageSize</code> is expected to be read in the resource file.
  88 + *
  89 + * @return String
  90 + */
  91 + String prefix() default "";
  92 +
  93 + /**
  94 + * Defines the resource file name to be read by this configuration class. There is no need to specify file extension
  95 + * in the case of properties or XML resources.
  96 + * <p>
  97 + * For instance, when resource is set to <code>"bookmark"</code> and the type set to properties, a corresponding
  98 + * file named <code>bookmark.properties</code> is considered.
  99 + * <p>
  100 + * If not specified, the default configuration file <code>demoiselle.properties</code> is rather considered.
  101 + *
  102 + * @return String
  103 + */
  104 + String resource() default DEFAULT_RESOURCE;
  105 +
  106 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/configuration/ConfigurationException.java 0 → 100644
... ... @@ -0,0 +1,72 @@
  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.configuration;
  38 +
  39 +import br.gov.frameworkdemoiselle.DemoiselleException;
  40 +
  41 +/**
  42 + * Exception class intended to be used by configuration components.
  43 + *
  44 + * @author SERPRO
  45 + */
  46 +public class ConfigurationException extends DemoiselleException {
  47 +
  48 + private static final long serialVersionUID = 1L;
  49 +
  50 + /**
  51 + * Constructor with message.
  52 + *
  53 + * @param message
  54 + * exception message
  55 + */
  56 + public ConfigurationException(String message) {
  57 + super(message);
  58 + }
  59 +
  60 + /**
  61 + * Constructor with message and cause.
  62 + *
  63 + * @param message
  64 + * exception message
  65 + * @param cause
  66 + * exception cause
  67 + */
  68 + public ConfigurationException(String message, Throwable cause) {
  69 + super(message, cause);
  70 + }
  71 +
  72 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/exception/ApplicationException.java 0 → 100644
... ... @@ -0,0 +1,75 @@
  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.exception;
  38 +
  39 +import static java.lang.annotation.ElementType.TYPE;
  40 +import static java.lang.annotation.RetentionPolicy.RUNTIME;
  41 +
  42 +import java.lang.annotation.Inherited;
  43 +import java.lang.annotation.Retention;
  44 +import java.lang.annotation.Target;
  45 +
  46 +import javax.enterprise.inject.Stereotype;
  47 +
  48 +import br.gov.frameworkdemoiselle.message.SeverityType;
  49 +
  50 +/**
  51 + * Annotation to be used in application exceptions. Exceptions marked with this annotation can receive special treatment
  52 + * like transaction management and special messages based on severity type attribute.
  53 + *
  54 + * @author CETEC
  55 + */
  56 +@Stereotype
  57 +@Inherited
  58 +@Target(TYPE)
  59 +@Retention(RUNTIME)
  60 +public @interface ApplicationException {
  61 +
  62 + /**
  63 + * When raised, the exception that uses this annotation must cause a rollback in the current transaction?
  64 + *
  65 + * @return True if current transaction must be rolledback
  66 + */
  67 + boolean rollback() default true;
  68 +
  69 + /**
  70 + * Exception Severity.
  71 + *
  72 + * @return
  73 + */
  74 + SeverityType severity() default SeverityType.INFO;
  75 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/exception/ExceptionHandler.java 0 → 100644
... ... @@ -0,0 +1,66 @@
  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.exception;
  38 +
  39 +import static java.lang.annotation.ElementType.METHOD;
  40 +import static java.lang.annotation.RetentionPolicy.RUNTIME;
  41 +
  42 +import java.lang.annotation.Inherited;
  43 +import java.lang.annotation.Retention;
  44 +import java.lang.annotation.Target;
  45 +
  46 +import br.gov.frameworkdemoiselle.stereotype.BusinessController;
  47 +import br.gov.frameworkdemoiselle.stereotype.PersistenceController;
  48 +import br.gov.frameworkdemoiselle.stereotype.ViewController;
  49 +
  50 +/**
  51 + * <p>
  52 + * Should be used exclusively with controller objects, i.e., classes annotated with {@link ViewController},
  53 + * {@link BusinessController}, or {@link PersistenceController}.
  54 + * </p>
  55 + * <p>
  56 + * Methods that use this annotation will automatically handle all exceptions of a specific type thrown by the method
  57 + * owner class.
  58 + * </p>
  59 + *
  60 + * @author SERPRO
  61 + */
  62 +@Inherited
  63 +@Target(METHOD)
  64 +@Retention(RUNTIME)
  65 +public @interface ExceptionHandler {
  66 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractBootstrap.java 0 → 100644
... ... @@ -0,0 +1,77 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.internal.bootstrap;
  38 +
  39 +import javax.enterprise.inject.spi.AfterBeanDiscovery;
  40 +import javax.enterprise.inject.spi.Extension;
  41 +
  42 +import org.slf4j.Logger;
  43 +
  44 +import br.gov.frameworkdemoiselle.internal.context.Contexts;
  45 +import br.gov.frameworkdemoiselle.internal.context.CustomContext;
  46 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  47 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
  48 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
  49 +
  50 +public class AbstractBootstrap implements Extension {
  51 +
  52 + private static ResourceBundleProducer bundleFactory = new ResourceBundleProducer();
  53 +
  54 + protected static ResourceBundle getBundle() {
  55 + return getBundle("demoiselle-core-bundle");
  56 + }
  57 +
  58 + protected static ResourceBundle getBundle(String baseName) {
  59 + return bundleFactory.create(baseName);
  60 + }
  61 +
  62 + protected static Logger getLogger() {
  63 + return LoggerProducer.create(AbstractBootstrap.class);
  64 + }
  65 +
  66 + protected static void addContext(final CustomContext context, final AfterBeanDiscovery event) {
  67 + Contexts.add(context, event);
  68 + getLogger()
  69 + .trace(getBundle().getString("custom-context-was-registered", context.getScope().getCanonicalName()));
  70 + }
  71 +
  72 + protected static void disableContext(final CustomContext context) {
  73 + Contexts.remove(context);
  74 + getLogger()
  75 + .trace(getBundle().getString("custom-context-was-registered", context.getScope().getCanonicalName()));
  76 + }
  77 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ConfigurationBootstrap.java 0 → 100644
... ... @@ -0,0 +1,95 @@
  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.ArrayList;
  40 +import java.util.Collections;
  41 +import java.util.List;
  42 +
  43 +import javax.enterprise.context.RequestScoped;
  44 +import javax.enterprise.context.SessionScoped;
  45 +import javax.enterprise.event.Observes;
  46 +import javax.enterprise.inject.spi.AfterBeanDiscovery;
  47 +import javax.enterprise.inject.spi.AfterDeploymentValidation;
  48 +import javax.enterprise.inject.spi.AnnotatedType;
  49 +import javax.enterprise.inject.spi.BeanManager;
  50 +import javax.enterprise.inject.spi.ProcessAnnotatedType;
  51 +
  52 +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 +
  58 +/**
  59 + * @author SERPRO
  60 + */
  61 +public class ConfigurationBootstrap extends AbstractBootstrap {
  62 +
  63 + private static List<AnnotatedType<?>> types = Collections.synchronizedList(new ArrayList<AnnotatedType<?>>());
  64 +
  65 + private static final String MSG_PROCESSING = "bootstrap.configuration.processing";
  66 +
  67 + private ThreadLocalContext c1;
  68 +
  69 + private ThreadLocalContext c2;
  70 +
  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());
  74 + }
  75 + }
  76 +
  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 + }
  83 +
  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()));
  90 + }
  91 + disableContext(c1);
  92 + disableContext(c2);
  93 + }
  94 +
  95 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CoreBootstrap.java 0 → 100644
... ... @@ -0,0 +1,94 @@
  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.HashMap;
  40 +import java.util.Map;
  41 +
  42 +import javax.enterprise.event.Observes;
  43 +import javax.enterprise.inject.spi.AfterDeploymentValidation;
  44 +import javax.enterprise.inject.spi.AnnotatedType;
  45 +import javax.enterprise.inject.spi.BeanManager;
  46 +import javax.enterprise.inject.spi.BeforeBeanDiscovery;
  47 +import javax.enterprise.inject.spi.BeforeShutdown;
  48 +import javax.enterprise.inject.spi.ProcessAnnotatedType;
  49 +
  50 +import org.slf4j.Logger;
  51 +
  52 +import br.gov.frameworkdemoiselle.util.Beans;
  53 +
  54 +//TODO Inter [NQ]: verificar o melhor nome para todas as classes desta natureza.
  55 +public class CoreBootstrap extends AbstractBootstrap {
  56 +
  57 + private static final Map<Class<?>, AnnotatedType<?>> beans = new HashMap<Class<?>, AnnotatedType<?>>();
  58 +
  59 + public static boolean isAnnotatedType(Class<?> type) {
  60 + return beans.containsKey(type);
  61 + }
  62 +
  63 + public void engineOn(@Observes final BeforeBeanDiscovery event, BeanManager beanManager) {
  64 + String description;
  65 + Logger log = getLogger();
  66 +
  67 + description = getBundle("demoiselle-core-bundle").getString("engine-on");
  68 + log.info(description);
  69 +
  70 + Beans.setBeanManager(beanManager);
  71 +
  72 + description = getBundle("demoiselle-core-bundle").getString("setting-up-bean-manager",
  73 + Beans.class.getCanonicalName());
  74 + log.info(description);
  75 + }
  76 +
  77 + protected <T> void detectAnnotation(@Observes final ProcessAnnotatedType<T> event) {
  78 + beans.put(event.getAnnotatedType().getJavaClass(), event.getAnnotatedType());
  79 + }
  80 +
  81 + public static void takeOff(@Observes final AfterDeploymentValidation event) {
  82 + String description = getBundle("demoiselle-core-bundle").getString("taking-off");
  83 +
  84 + Logger log = getLogger();
  85 + log.info(description);
  86 + }
  87 +
  88 + public static void engineOff(@Observes final BeforeShutdown event) {
  89 + String description = getBundle("demoiselle-core-bundle").getString("engine-off");
  90 +
  91 + Logger log = getLogger();
  92 + log.info(description);
  93 + }
  94 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ShutdownBootstrap.java 0 → 100644
... ... @@ -0,0 +1,138 @@
  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.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;
  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 +
  55 +import br.gov.frameworkdemoiselle.annotation.Shutdown;
  56 +import br.gov.frameworkdemoiselle.annotation.ViewScoped;
  57 +import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext;
  58 +import br.gov.frameworkdemoiselle.internal.context.CustomContext;
  59 +import br.gov.frameworkdemoiselle.internal.processor.ShutdownProcessor;
  60 +
  61 +/**
  62 + * This class run at application shutdown
  63 + */
  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>());
  73 +
  74 + private static AfterBeanDiscovery event;
  75 +
  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 + }
  91 + }
  92 + }
  93 +
  94 + public void saveEvent(@Observes final AfterBeanDiscovery event) {
  95 + ShutdownBootstrap.event = event;
  96 + }
  97 +
  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 + }
  137 + }
  138 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/StartupBootstrap.java 0 → 100644
... ... @@ -0,0 +1,128 @@
  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.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;
  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 +
  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;
  59 +
  60 +/**
  61 + * This class is the bootstrap to execute the processes at load time.
  62 + */
  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 + }
  90 +
  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));
  97 +
  98 + for (ThreadLocalContext tempContext : this.tempContexts) {
  99 + addContext(tempContext, event);
  100 + }
  101 + }
  102 +
  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();
  121 + }
  122 +
  123 + private void unloadTempContexts() {
  124 + for (ThreadLocalContext tempContext : this.tempContexts) {
  125 + disableContext(tempContext);
  126 + }
  127 + }
  128 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java 0 → 100644
... ... @@ -0,0 +1,301 @@
  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.lang.reflect.Field;
  40 +import java.lang.reflect.Method;
  41 +import java.util.HashSet;
  42 +import java.util.Iterator;
  43 +import java.util.Properties;
  44 +import java.util.Set;
  45 +
  46 +import javax.inject.Inject;
  47 +import javax.validation.constraints.NotNull;
  48 +
  49 +import org.apache.commons.configuration.PropertiesConfiguration;
  50 +import org.apache.commons.configuration.SystemConfiguration;
  51 +import org.apache.commons.configuration.XMLConfiguration;
  52 +import org.slf4j.Logger;
  53 +
  54 +import br.gov.frameworkdemoiselle.annotation.Ignore;
  55 +import br.gov.frameworkdemoiselle.annotation.Name;
  56 +import br.gov.frameworkdemoiselle.configuration.ConfigType;
  57 +import br.gov.frameworkdemoiselle.configuration.Configuration;
  58 +import br.gov.frameworkdemoiselle.configuration.ConfigurationException;
  59 +import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap;
  60 +import br.gov.frameworkdemoiselle.util.Reflections;
  61 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
  62 +import br.gov.frameworkdemoiselle.util.Strings;
  63 +
  64 +/**
  65 + * This component loads a config class annotated with {@link Configuration} by filling its attributes with {@link Param}
  66 + * according to a {@link ConfigType}.
  67 + *
  68 + * @author SERPRO
  69 + */
  70 +public class ConfigurationLoader {
  71 +
  72 + @Inject
  73 + @Name("demoiselle-core-bundle")
  74 + private ResourceBundle bundle;
  75 +
  76 + @Inject
  77 + private Logger logger;
  78 +
  79 + /**
  80 + * Loads a config class filling it with the corresponding values.
  81 + *
  82 + * @param object
  83 + * config object
  84 + * @throws ConfigurationException
  85 + */
  86 + public void load(Object object) throws ConfigurationException {
  87 + Class<?> config = object.getClass();
  88 +
  89 + if (!CoreBootstrap.isAnnotatedType(config)) {
  90 + config = config.getSuperclass();
  91 + logger.debug(bundle.getString("proxy-detected", config, config.getClass().getSuperclass()));
  92 + }
  93 +
  94 + logger.debug(bundle.getString("loading-configuration-class", config.getName()));
  95 +
  96 + for (Field field : Reflections.getNonStaticDeclaredFields(config)) {
  97 + loadField(field, object, config);
  98 + }
  99 + }
  100 +
  101 + private void loadField(Field field, Object object, Class<?> clazz) {
  102 + if (!field.isAnnotationPresent(Ignore.class) && clazz.isAnnotationPresent(Configuration.class)) {
  103 + String resource = clazz.getAnnotation(Configuration.class).resource();
  104 + ConfigType type = clazz.getAnnotation(Configuration.class).type();
  105 + org.apache.commons.configuration.Configuration config = getConfiguration(resource, type);
  106 +
  107 + String key = getKey(field, clazz, config);
  108 + Object value = getValue(key, field.getType(), config);
  109 +
  110 + validate(field, key, value, resource);
  111 + setValue(field, key, object, value);
  112 + }
  113 + }
  114 +
  115 + private void setValue(Field field, String key, Object object, Object value) {
  116 + if (value != null) {
  117 + Reflections.setFieldValue(field, object, value);
  118 + logger.debug(bundle.getString("configuration-field-loaded", key, field.getName(), value));
  119 + }
  120 + }
  121 +
  122 + private void validate(Field field, String key, Object value, String resource) {
  123 + if (field.isAnnotationPresent(NotNull.class) && value == null) {
  124 + throw new ConfigurationException(bundle.getString("configuration-attribute-is-mandatory", key, resource));
  125 + }
  126 + }
  127 +
  128 + private String getKey(final Field field, final Class<?> clazz,
  129 + final org.apache.commons.configuration.Configuration config) {
  130 +
  131 + final String prefix = getPrefix(field, clazz);
  132 + final StringBuffer key = new StringBuffer();
  133 +
  134 + key.append(prefix);
  135 +
  136 + if (field.isAnnotationPresent(Name.class)) {
  137 + key.append(getKeyByAnnotation(field));
  138 + } else {
  139 + key.append(getKeyByConvention(field, prefix, config));
  140 + }
  141 +
  142 + return key.toString();
  143 + }
  144 +
  145 + private String getPrefix(Field field, Class<?> type) {
  146 + String prefix = "";
  147 +
  148 + Configuration classAnnotation = type.getAnnotation(Configuration.class);
  149 + if (!Strings.isEmpty(classAnnotation.prefix())) {
  150 + prefix = classAnnotation.prefix() + ".";
  151 + }
  152 +
  153 + return prefix;
  154 + }
  155 +
  156 + private String getKeyByAnnotation(Field field) {
  157 + String key = null;
  158 +
  159 + Name nameAnnotation = field.getAnnotation(Name.class);
  160 + if (Strings.isEmpty(nameAnnotation.value())) {
  161 + throw new ConfigurationException(bundle.getString("configuration-name-attribute-cant-be-empty"));
  162 + } else {
  163 + key = nameAnnotation.value();
  164 + }
  165 +
  166 + return key;
  167 + }
  168 +
  169 + private String getKeyByConvention(Field field, String prefix, org.apache.commons.configuration.Configuration config) {
  170 +
  171 + Set<String> conventions = new HashSet<String>();
  172 + conventions.add(field.getName());
  173 + conventions.add(Strings.camelCaseToSymbolSeparated(field.getName(), "."));
  174 + conventions.add(Strings.camelCaseToSymbolSeparated(field.getName(), "_"));
  175 + conventions.add(field.getName().toLowerCase());
  176 + conventions.add(field.getName().toUpperCase());
  177 +
  178 + int matches = 0;
  179 + String key = field.getName();
  180 + for (String convention : conventions) {
  181 + if (config.containsKey(prefix + convention)) {
  182 + key = convention;
  183 + matches++;
  184 + }
  185 + }
  186 +
  187 + if (matches == 0) {
  188 + logger.debug(bundle.getString("configuration-key-not-found", key, conventions));
  189 + } else if (matches > 1) {
  190 + throw new ConfigurationException(bundle.getString("ambiguous-key", field.getName(),
  191 + field.getDeclaringClass()));
  192 + }
  193 +
  194 + return key;
  195 + }
  196 +
  197 + /**
  198 + * Returns the configuration class according to specified resource name and configuration type.
  199 + *
  200 + * @param resource
  201 + * @param type
  202 + * @return a configuration
  203 + */
  204 + private org.apache.commons.configuration.Configuration getConfiguration(String resource, ConfigType type) {
  205 + org.apache.commons.configuration.Configuration config = null;
  206 +
  207 + try {
  208 + switch (type) {
  209 + case SYSTEM:
  210 + config = new SystemConfiguration();
  211 + break;
  212 +
  213 + case PROPERTIES:
  214 + config = new PropertiesConfiguration(resource + ".properties");
  215 + break;
  216 +
  217 + case XML:
  218 + config = new XMLConfiguration(resource + ".xml");
  219 + break;
  220 +
  221 + default:
  222 + throw new ConfigurationException(bundle.getString("configuration-type-not-implemented-yet",
  223 + type.name()));
  224 + }
  225 +
  226 + } catch (Exception cause) {
  227 + throw new ConfigurationException(bundle.getString("error-creating-configuration-from-resource", resource),
  228 + cause);
  229 + }
  230 +
  231 + return config;
  232 + }
  233 +
  234 + /**
  235 + * Returns the value associated with the given configuration class and field type.
  236 + *
  237 + * @param name
  238 + * @param config
  239 + * @param fieldClass
  240 + * @return the value
  241 + */
  242 + @SuppressWarnings("unchecked")
  243 + private <T> T getValue(String key, Class<T> fieldClass, org.apache.commons.configuration.Configuration config) {
  244 + Object value;
  245 +
  246 + if (fieldClass.isArray() && fieldClass.getComponentType().equals(String.class)) {
  247 + value = config.getStringArray(key);
  248 +
  249 + } else if (fieldClass.equals(Properties.class)) {
  250 + value = getProperty(key, config);
  251 +
  252 + } else {
  253 + value = getBasic(key, fieldClass, config);
  254 + }
  255 +
  256 + return (T) value;
  257 + }
  258 +
  259 + private <T> Object getBasic(String key, Class<T> fieldClass, org.apache.commons.configuration.Configuration config) {
  260 + Object value = null;
  261 +
  262 + try {
  263 + Method method;
  264 + String methodName = "get" + Strings.firstToUpper(fieldClass.getSimpleName());
  265 +
  266 + if (!fieldClass.isPrimitive()) {
  267 + method = config.getClass().getMethod(methodName, String.class, fieldClass);
  268 + value = method.invoke(config, key, null);
  269 + } else if (config.containsKey(key)) {
  270 + method = config.getClass().getMethod(methodName, String.class);
  271 + value = method.invoke(config, key);
  272 + }
  273 +
  274 + } catch (Throwable cause) {
  275 + throw new ConfigurationException(bundle.getString("error-converting-to-type", fieldClass.getName()), cause);
  276 + }
  277 +
  278 + return value;
  279 + }
  280 +
  281 + private Object getProperty(String key, org.apache.commons.configuration.Configuration config) {
  282 + Object value = null;
  283 +
  284 + @SuppressWarnings("unchecked")
  285 + Iterator<String> iterator = config.getKeys(key);
  286 + if (iterator.hasNext()) {
  287 + Properties props = new Properties();
  288 +
  289 + while (iterator.hasNext()) {
  290 + String fullKey = iterator.next();
  291 + String prefix = key + ".";
  292 + String unprefixedKey = fullKey.substring(prefix.length());
  293 + props.put(unprefixedKey, config.getString(fullKey));
  294 + }
  295 +
  296 + value = props;
  297 + }
  298 +
  299 + return value;
  300 + }
  301 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/PaginationConfig.java 0 → 100644
... ... @@ -0,0 +1,81 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.internal.configuration;
  38 +
  39 +import java.io.Serializable;
  40 +
  41 +import br.gov.frameworkdemoiselle.annotation.Name;
  42 +import br.gov.frameworkdemoiselle.configuration.Configuration;
  43 +
  44 +/**
  45 + * The <code>PaginationConfig</code> class provides a pagination context to be used where this type of control is
  46 + * needed. For example: in a UI as a data grid or on a search to the database.
  47 + *
  48 + * @author SERPRO
  49 + */
  50 +@Configuration(prefix = "frameworkdemoiselle.pagination")
  51 +public class PaginationConfig implements Serializable {
  52 +
  53 + private static final long serialVersionUID = 1L;
  54 +
  55 + @Name("page.size")
  56 + private int pageSize = 10;
  57 +
  58 + @Name("max.page.links")
  59 + private int maxPageLinks = 5;
  60 +
  61 + /**
  62 + * Returns the number of rows that will be shown in a data grid.
  63 + *
  64 + * @return the value defined for the key <i>frameworkdemoiselle.pagination.page.size</i> in the
  65 + * <b>demoiselle.properties</b> file. If there is no value defined, returns the default value 10
  66 + */
  67 + public int getPageSize() {
  68 + return pageSize;
  69 + }
  70 +
  71 + /**
  72 + * Returns the maximum number of pages that will be shown in a data grid footer
  73 + *
  74 + * @return the value defined for the key <i>frameworkdemoiselle.pagination.max.page.links</i> in the
  75 + * <b>demoiselle.properties</b> file. If there is no value defined, returns the default value 5
  76 + */
  77 + public int getMaxPageLinks() {
  78 + return maxPageLinks;
  79 + }
  80 +
  81 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/SecurityConfig.java 0 → 100644
... ... @@ -0,0 +1,68 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.internal.configuration;
  38 +
  39 +import java.io.Serializable;
  40 +
  41 +import br.gov.frameworkdemoiselle.annotation.Name;
  42 +import br.gov.frameworkdemoiselle.configuration.Configuration;
  43 +
  44 +/**
  45 + * A <code>SecurityConfig</code> object is responsible for specifying which security configurations should be used for a
  46 + * particular application.
  47 + *
  48 + * @author SERPRO
  49 + */
  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;
  57 +
  58 + /**
  59 + * Tells whether or not the security is enabled for the current application. This value could be defined in the
  60 + * <b>demoiselle.properties</b> file, using the key <i>frameworkdemoiselle.security.enabled</i>.
  61 + *
  62 + * @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>
  64 + */
  65 + public boolean isEnabled() {
  66 + return enabled;
  67 + }
  68 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ContextStore.java 0 → 100644
... ... @@ -0,0 +1,58 @@
  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.context;
  38 +
  39 +import java.util.Map;
  40 +import java.util.TreeMap;
  41 +
  42 +public class ContextStore {
  43 +
  44 + private Map<String, Object> map = new TreeMap<String, Object>();
  45 +
  46 + public boolean contains(final String name) {
  47 + return this.map.containsKey(name);
  48 + }
  49 +
  50 + public Object get(final String name) {
  51 + return this.map.get(name);
  52 + }
  53 +
  54 + public void put(final String name, final Object instance) {
  55 + this.map.put(name, instance);
  56 + }
  57 +
  58 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/context/Contexts.java 0 → 100644
... ... @@ -0,0 +1,123 @@
  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.context;
  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.inject.spi.AfterBeanDiscovery;
  45 +
  46 +public class Contexts {
  47 +
  48 + private static List<CustomContext> activeContexts;
  49 +
  50 + private static List<CustomContext> inactiveContexts;
  51 +
  52 + public static void add(CustomContext context, AfterBeanDiscovery event) {
  53 + Class<? extends Annotation> scope = context.getScope();
  54 +
  55 + if (get(scope, getActiveContexts()) != null) {
  56 + getInactiveContexts().add(context);
  57 + context.setActive(false);
  58 +
  59 + } else {
  60 + getActiveContexts().add(context);
  61 + context.setActive(true);
  62 + }
  63 +
  64 + if (event != null) {
  65 + event.addContext(context);
  66 + }
  67 + }
  68 +
  69 + private static CustomContext get(Class<? extends Annotation> scope, List<CustomContext> contexts) {
  70 + CustomContext result = null;
  71 +
  72 + for (CustomContext context : contexts) {
  73 + if (scope.equals(context.getScope())) {
  74 + result = context;
  75 + break;
  76 + }
  77 + }
  78 +
  79 + return result;
  80 + }
  81 +
  82 + public static void remove(CustomContext context) {
  83 + if (getActiveContexts().contains(context)) {
  84 + getActiveContexts().remove(context);
  85 + context.setActive(false);
  86 +
  87 + CustomContext inactive = get(context.getScope(), getInactiveContexts());
  88 + if (inactive != null) {
  89 + getActiveContexts().add(inactive);
  90 + inactive.setActive(true);
  91 + getInactiveContexts().remove(inactive);
  92 + }
  93 +
  94 + } else if (getInactiveContexts().contains(context)) {
  95 + getInactiveContexts().remove(context);
  96 + }
  97 + }
  98 +
  99 + public static void clear() {
  100 + for (CustomContext context : getActiveContexts()) {
  101 + context.setActive(false);
  102 + }
  103 +
  104 + activeContexts = null;
  105 + inactiveContexts = null;
  106 + }
  107 +
  108 + public static List<CustomContext> getActiveContexts() {
  109 + if (activeContexts == null) {
  110 + activeContexts = Collections.synchronizedList(new ArrayList<CustomContext>());
  111 + }
  112 +
  113 + return activeContexts;
  114 + }
  115 +
  116 + public static List<CustomContext> getInactiveContexts() {
  117 + if (inactiveContexts == null) {
  118 + inactiveContexts = Collections.synchronizedList(new ArrayList<CustomContext>());
  119 + }
  120 +
  121 + return inactiveContexts;
  122 + }
  123 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContext.java 0 → 100644
... ... @@ -0,0 +1,45 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.internal.context;
  38 +
  39 +import javax.enterprise.context.spi.Context;
  40 +
  41 +public interface CustomContext extends Context {
  42 +
  43 + void setActive(boolean b);
  44 +
  45 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ThreadLocalContext.java 0 → 100644
... ... @@ -0,0 +1,130 @@
  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.context;
  50 +
  51 +import java.lang.annotation.Annotation;
  52 +
  53 +import javax.enterprise.context.ContextNotActiveException;
  54 +import javax.enterprise.context.spi.Contextual;
  55 +import javax.enterprise.context.spi.CreationalContext;
  56 +import javax.enterprise.inject.spi.Bean;
  57 +
  58 +public class ThreadLocalContext implements CustomContext {
  59 +
  60 + private final ThreadLocal<ContextStore> threadLocal = new ThreadLocal<ContextStore>();
  61 +
  62 + private boolean active;
  63 +
  64 + private final Class<? extends Annotation> scope;
  65 +
  66 + public ThreadLocalContext(final Class<? extends Annotation> scope) {
  67 + this(scope, true);
  68 + }
  69 +
  70 + public ThreadLocalContext(final Class<? extends Annotation> scope,
  71 + boolean active) {
  72 + this.scope = scope;
  73 + this.active = active;
  74 + }
  75 +
  76 + @Override
  77 + public <T> T get(final Contextual<T> contextual) {
  78 + return get(contextual, null);
  79 + }
  80 +
  81 + @Override
  82 + @SuppressWarnings("unchecked")
  83 + public <T> T get(final Contextual<T> contextual,
  84 + final CreationalContext<T> creationalContext) {
  85 + T instance = null;
  86 +
  87 + if (!isActive()) {
  88 + throw new ContextNotActiveException();
  89 + }
  90 +
  91 + String id = getId(contextual);
  92 + if (getStore().contains(id)) {
  93 + instance = (T) getStore().get(id);
  94 +
  95 + } else if (creationalContext != null) {
  96 + instance = contextual.create(creationalContext);
  97 + getStore().put(id, instance);
  98 + }
  99 +
  100 + return instance;
  101 + }
  102 +
  103 + private <T> String getId(final Contextual<T> contextual) {
  104 + Bean<T> bean = (Bean<T>) contextual;
  105 + return bean.getBeanClass().getCanonicalName();
  106 + }
  107 +
  108 + @Override
  109 + public Class<? extends Annotation> getScope() {
  110 + return this.scope;
  111 + }
  112 +
  113 + private ContextStore getStore() {
  114 + if (this.threadLocal.get() == null) {
  115 + this.threadLocal.set(new ContextStore());
  116 + }
  117 +
  118 + return this.threadLocal.get();
  119 + }
  120 +
  121 + @Override
  122 + public boolean isActive() {
  123 + return this.active;
  124 + }
  125 +
  126 + public void setActive(final boolean active) {
  127 + this.active = active;
  128 + }
  129 +
  130 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/CoreBundle.java 0 → 100644
... ... @@ -0,0 +1,28 @@
  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 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthenticator.java 0 → 100644
... ... @@ -0,0 +1,83 @@
  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 br.gov.frameworkdemoiselle.DemoiselleException;
  40 +import br.gov.frameworkdemoiselle.security.Authenticator;
  41 +import br.gov.frameworkdemoiselle.security.SecurityContext;
  42 +import br.gov.frameworkdemoiselle.security.User;
  43 +
  44 +/**
  45 + * Authenticator that actually does nothing but raise exceptions.
  46 + *
  47 + * @author SERPRO
  48 + * @see Authenticator
  49 + */
  50 +public class DefaultAuthenticator implements Authenticator {
  51 +
  52 + private static final long serialVersionUID = 1L;
  53 +
  54 + /**
  55 + * @see br.gov.frameworkdemoiselle.security.Authenticator#authenticate()
  56 + */
  57 + @Override
  58 + public boolean authenticate() {
  59 + throw getException();
  60 + }
  61 +
  62 + /**
  63 + * @see br.gov.frameworkdemoiselle.security.Authenticator#unAuthenticate()
  64 + */
  65 + @Override
  66 + public void unAuthenticate() {
  67 + throw getException();
  68 + }
  69 +
  70 + /**
  71 + * @see br.gov.frameworkdemoiselle.security.Authenticator#getUser()
  72 + */
  73 + @Override
  74 + public User getUser() {
  75 + throw getException();
  76 + }
  77 +
  78 + private DemoiselleException getException() {
  79 + return new DemoiselleException(CoreBundle.get().getString("authenticator-not-defined",
  80 + SecurityContext.class.getSimpleName()));
  81 + }
  82 +
  83 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthorizer.java 0 → 100644
... ... @@ -0,0 +1,66 @@
  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 br.gov.frameworkdemoiselle.DemoiselleException;
  40 +import br.gov.frameworkdemoiselle.security.Authorizer;
  41 +import br.gov.frameworkdemoiselle.security.RequiredPermission;
  42 +import br.gov.frameworkdemoiselle.security.RequiredRole;
  43 +
  44 +/**
  45 + * Authorizator that actually does nothing but raise exceptions.
  46 + *
  47 + * @author SERPRO
  48 + * @see Authorizer
  49 + */
  50 +public class DefaultAuthorizer implements Authorizer {
  51 +
  52 + private static final long serialVersionUID = 1L;
  53 +
  54 + @Override
  55 + public boolean hasRole(String role) {
  56 + throw new DemoiselleException(CoreBundle.get().getString("authorizer-not-defined",
  57 + RequiredRole.class.getSimpleName()));
  58 + }
  59 +
  60 + @Override
  61 + public boolean hasPermission(String resource, String operation) {
  62 + throw new DemoiselleException(CoreBundle.get().getString("authorizer-not-defined",
  63 + RequiredPermission.class.getSimpleName()));
  64 + }
  65 +
  66 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultTransaction.java 0 → 100644
... ... @@ -0,0 +1,90 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.internal.implementation;
  38 +
  39 +import javax.enterprise.context.SessionScoped;
  40 +
  41 +import br.gov.frameworkdemoiselle.DemoiselleException;
  42 +import br.gov.frameworkdemoiselle.transaction.Transaction;
  43 +import br.gov.frameworkdemoiselle.transaction.Transactional;
  44 +
  45 +/**
  46 + * Transaction strategy that actually does nothing but raise exceptions.
  47 + *
  48 + * @author SERPRO
  49 + * @see Transaction
  50 + */
  51 +@SessionScoped
  52 +public class DefaultTransaction implements Transaction {
  53 +
  54 + private static final long serialVersionUID = 1L;
  55 +
  56 + @Override
  57 + public void begin() {
  58 + throw getException();
  59 + }
  60 +
  61 + @Override
  62 + public void commit() {
  63 + throw getException();
  64 + }
  65 +
  66 + @Override
  67 + public boolean isActive() {
  68 + throw getException();
  69 + }
  70 +
  71 + @Override
  72 + public boolean isMarkedRollback() {
  73 + throw getException();
  74 + }
  75 +
  76 + @Override
  77 + public void rollback() {
  78 + throw getException();
  79 + }
  80 +
  81 + @Override
  82 + public void setRollbackOnly() {
  83 + throw getException();
  84 + }
  85 +
  86 + private DemoiselleException getException() {
  87 + return new DemoiselleException(CoreBundle.get().getString("transaction-not-defined",
  88 + Transactional.class.getSimpleName()));
  89 + }
  90 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MessageContextImpl.java 0 → 100644
... ... @@ -0,0 +1,105 @@
  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.io.Serializable;
  40 +import java.util.ArrayList;
  41 +import java.util.List;
  42 +
  43 +import javax.enterprise.context.SessionScoped;
  44 +import javax.inject.Inject;
  45 +
  46 +import org.slf4j.Logger;
  47 +
  48 +import br.gov.frameworkdemoiselle.message.DefaultMessage;
  49 +import br.gov.frameworkdemoiselle.message.Message;
  50 +import br.gov.frameworkdemoiselle.message.MessageContext;
  51 +import br.gov.frameworkdemoiselle.message.SeverityType;
  52 +
  53 +/**
  54 + * The message store is designed to provide access to messages. It is shared by every application layer.
  55 + *
  56 + * @see MessageContext
  57 + */
  58 +@SessionScoped
  59 +//@ConversationScoped
  60 +// FIXME colocar o escopo de conversação, para não ter que limpar o contexto manualmente. Ou seria melhor colocar no
  61 +// escopo de request para não precisar se preocupar com isso?
  62 +public class MessageContextImpl implements Serializable, MessageContext {
  63 +
  64 + private static final long serialVersionUID = 1L;
  65 +
  66 + @Inject
  67 + private Logger logger;
  68 +
  69 + private final List<Message> messages = new ArrayList<Message>();
  70 +
  71 + @Override
  72 + public void add(final Message message, Object... params) {
  73 + Message aux;
  74 +
  75 + if (params != null) {
  76 + aux = new DefaultMessage(message.getText(), message.getSeverity(), params);
  77 + } else {
  78 + aux = message;
  79 + }
  80 +
  81 + logger.debug(CoreBundle.get().getString("adding-message-to-context", message.toString()));
  82 + messages.add(aux);
  83 + }
  84 +
  85 + @Override
  86 + public void add(String text, Object... params) {
  87 + add(text, null, params);
  88 + }
  89 +
  90 + @Override
  91 + public void add(String text, SeverityType severity, Object... params) {
  92 + add(new DefaultMessage(text, severity, params));
  93 + }
  94 +
  95 + @Override
  96 + public List<Message> getMessages() {
  97 + return messages;
  98 + }
  99 +
  100 + @Override
  101 + public void clear() {
  102 + logger.debug(CoreBundle.get().getString("cleaning-message-context"));
  103 + messages.clear();
  104 + }
  105 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/PaginationContextImpl.java 0 → 100644
... ... @@ -0,0 +1,84 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.internal.implementation;
  38 +
  39 +import java.io.Serializable;
  40 +import java.util.HashMap;
  41 +import java.util.Map;
  42 +
  43 +import javax.enterprise.context.SessionScoped;
  44 +import javax.inject.Inject;
  45 +
  46 +import br.gov.frameworkdemoiselle.internal.configuration.PaginationConfig;
  47 +import br.gov.frameworkdemoiselle.pagination.Pagination;
  48 +import br.gov.frameworkdemoiselle.pagination.PaginationContext;
  49 +
  50 +/**
  51 + * Context implementation reserved for pagination purposes. Internally a hash map is used to store pagination data for
  52 + * each class type.
  53 + *
  54 + * @author SERPRO
  55 + * @see PaginationContext
  56 + */
  57 +@SessionScoped
  58 +public class PaginationContextImpl implements Serializable, PaginationContext {
  59 +
  60 + private static final long serialVersionUID = 1L;
  61 +
  62 + @Inject
  63 + private PaginationConfig config;
  64 +
  65 + private final Map<Class<?>, Pagination> cache = new HashMap<Class<?>, Pagination>();
  66 +
  67 + public Pagination getPagination(final Class<?> clazz) {
  68 + return this.getPagination(clazz, false);
  69 + }
  70 +
  71 + public Pagination getPagination(final Class<?> clazz, final boolean create) {
  72 + Pagination pagination = cache.get(clazz);
  73 +
  74 + if (pagination == null && create) {
  75 + pagination = new PaginationImpl();
  76 + pagination.setPageSize(config.getPageSize());
  77 +
  78 + cache.put(clazz, pagination);
  79 + }
  80 +
  81 + return pagination;
  82 + }
  83 +
  84 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/PaginationImpl.java 0 → 100644
... ... @@ -0,0 +1,184 @@
  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.io.Serializable;
  40 +
  41 +import javax.enterprise.inject.Alternative;
  42 +
  43 +import br.gov.frameworkdemoiselle.pagination.Pagination;
  44 +import br.gov.frameworkdemoiselle.util.Strings;
  45 +
  46 +/**
  47 + * Structure used to handle pagination of data results on both <i>backend</i> (i.e., persistence) and <i>frontend</i>
  48 + * (i.e., presentation) layers in the application.
  49 + * <p>
  50 + * Internally, it stores the current page index on {@code currentPage} variable, the amount of records in a single page
  51 + * on {@code pageSize}, and the total number of pages in {@code totalPages}.
  52 + *
  53 + * @author SERPRO
  54 + * @see Pagination
  55 + */
  56 +@Alternative
  57 +public class PaginationImpl implements Serializable, Pagination {
  58 +
  59 + private static final long serialVersionUID = 1L;
  60 +
  61 + private int currentPage;
  62 +
  63 + private int pageSize;
  64 +
  65 + private int totalResults;
  66 +
  67 + private int totalPages;
  68 +
  69 + public PaginationImpl() {
  70 + pageSize = 0;
  71 + totalResults = 0;
  72 + reset();
  73 + }
  74 +
  75 + private void reset() {
  76 + currentPage = 0;
  77 + totalPages = 0;
  78 + }
  79 +
  80 + public int getCurrentPage() {
  81 + return currentPage;
  82 + }
  83 +
  84 + private void setTotalPages(int totalPages) {
  85 + validateNegativeValue(totalPages);
  86 + this.totalPages = totalPages;
  87 +
  88 + if (totalPages == 0) {
  89 + reset();
  90 + } else if (getCurrentPage() >= totalPages) {
  91 + setCurrentPage(totalPages - 1);
  92 + }
  93 + }
  94 +
  95 + private void validateNegativeValue(int input) throws IndexOutOfBoundsException {
  96 + if (input < 0) {
  97 + throw new IndexOutOfBoundsException("colocar mensagem");
  98 + }
  99 + }
  100 +
  101 + private void validateCurrentPage(int currentPage) throws IndexOutOfBoundsException {
  102 + if (currentPage >= this.totalPages) {
  103 + if (this.totalPages > 0) {
  104 + throw new IndexOutOfBoundsException("colocar mensagem");
  105 + }
  106 + }
  107 + }
  108 +
  109 + public void setCurrentPage(int currentPage) {
  110 + validateNegativeValue(currentPage);
  111 + validateCurrentPage(currentPage);
  112 + this.currentPage = currentPage;
  113 + }
  114 +
  115 + public int getPageSize() {
  116 + return pageSize;
  117 + }
  118 +
  119 + public int getTotalResults() {
  120 + return totalResults;
  121 + }
  122 +
  123 + public void setTotalResults(int totalResults) {
  124 + validateNegativeValue(totalResults);
  125 + this.totalResults = totalResults;
  126 +
  127 + if (totalResults > 0) {
  128 + setTotalPages();
  129 + } else {
  130 + reset();
  131 + }
  132 + }
  133 +
  134 + private void setTotalPages() {
  135 + if (totalResults > 0) {
  136 + setTotalPages((int) Math.ceil(totalResults * 1d / getPageSize()));
  137 + } else {
  138 + setTotalPages(0);
  139 + }
  140 + }
  141 +
  142 + public int getTotalPages() {
  143 + return totalPages;
  144 + }
  145 +
  146 + public int getFirstResult() {
  147 + return getCurrentPage() * getPageSize();
  148 + }
  149 +
  150 + public void setPageSize(int pageSize) {
  151 + validateNegativeValue(pageSize);
  152 + this.pageSize = pageSize;
  153 +
  154 + if (pageSize > 0) {
  155 + setTotalPages();
  156 + } else {
  157 + reset();
  158 + }
  159 + }
  160 +
  161 + private void validateFirstResult(int firstResult) throws IndexOutOfBoundsException {
  162 + if (firstResult >= this.totalResults) {
  163 + if (this.totalResults > 0) {
  164 + throw new IndexOutOfBoundsException("colocar mensagem");
  165 + }
  166 + }
  167 + }
  168 +
  169 + public void setFirstResult(int firstResult) {
  170 + validateNegativeValue(firstResult);
  171 + validateFirstResult(firstResult);
  172 +
  173 + if (firstResult > 0) {
  174 + setCurrentPage(firstResult / pageSize);
  175 + } else {
  176 + setCurrentPage(0);
  177 + }
  178 + }
  179 +
  180 + @Override
  181 + public String toString() {
  182 + return Strings.toString(this);
  183 + }
  184 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java 0 → 100644
... ... @@ -0,0 +1,185 @@
  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.enterprise.context.SessionScoped;
  40 +import javax.inject.Inject;
  41 +import javax.inject.Named;
  42 +
  43 +import br.gov.frameworkdemoiselle.annotation.Name;
  44 +import br.gov.frameworkdemoiselle.internal.configuration.SecurityConfig;
  45 +import br.gov.frameworkdemoiselle.security.AfterLoginSuccessful;
  46 +import br.gov.frameworkdemoiselle.security.AfterLogoutSuccessful;
  47 +import br.gov.frameworkdemoiselle.security.Authenticator;
  48 +import br.gov.frameworkdemoiselle.security.Authorizer;
  49 +import br.gov.frameworkdemoiselle.security.NotLoggedInException;
  50 +import br.gov.frameworkdemoiselle.security.SecurityContext;
  51 +import br.gov.frameworkdemoiselle.security.User;
  52 +import br.gov.frameworkdemoiselle.util.Beans;
  53 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
  54 +
  55 +/**
  56 + * This is the default implementation of {@link SecurityContext} interface.
  57 + *
  58 + * @author SERPRO
  59 + */
  60 +@SessionScoped
  61 +@Named("securityContext")
  62 +public class SecurityContextImpl implements SecurityContext {
  63 +
  64 + private static final long serialVersionUID = 1L;
  65 +
  66 + @Inject
  67 + @Name("demoiselle-core-bundle")
  68 + private ResourceBundle bundle;
  69 +
  70 + @Inject
  71 + private Authenticator authenticator;
  72 +
  73 + @Inject
  74 + private Authorizer authorizer;
  75 +
  76 + @Inject
  77 + private SecurityConfig config;
  78 +
  79 + /**
  80 + * @see br.gov.frameworkdemoiselle.security.SecurityContext#hasPermission(java.lang.String, java.lang.String)
  81 + */
  82 + @Override
  83 + public boolean hasPermission(String resource, String operation) throws NotLoggedInException {
  84 + if (config.isEnabled()) {
  85 + checkLoggedIn();
  86 + return authorizer.hasPermission(resource, operation);
  87 +
  88 + } else {
  89 + return true;
  90 + }
  91 + }
  92 +
  93 + /**
  94 + * @see br.gov.frameworkdemoiselle.security.SecurityContext#hasRole(java.lang.String)
  95 + */
  96 + @Override
  97 + public boolean hasRole(String role) throws NotLoggedInException {
  98 + if (config.isEnabled()) {
  99 + checkLoggedIn();
  100 + return authorizer.hasRole(role);
  101 +
  102 + } else {
  103 + return true;
  104 + }
  105 + }
  106 +
  107 + /**
  108 + * @see br.gov.frameworkdemoiselle.security.SecurityContext#isLoggedIn()
  109 + */
  110 + @Override
  111 + public boolean isLoggedIn() {
  112 + if (config.isEnabled()) {
  113 + return getUser() != null;
  114 + } else {
  115 + return true;
  116 + }
  117 + }
  118 +
  119 + /**
  120 + * @see br.gov.frameworkdemoiselle.security.SecurityContext#login()
  121 + */
  122 + @Override
  123 + public void login() {
  124 + if (config.isEnabled() && authenticator.authenticate()) {
  125 + Beans.getBeanManager().fireEvent(new AfterLoginSuccessful() {
  126 +
  127 + private static final long serialVersionUID = 1L;
  128 +
  129 + });
  130 + }
  131 + }
  132 +
  133 + /**
  134 + * @see br.gov.frameworkdemoiselle.security.SecurityContext#logout()
  135 + */
  136 + @Override
  137 + public void logout() throws NotLoggedInException {
  138 + if (config.isEnabled()) {
  139 + checkLoggedIn();
  140 + authenticator.unAuthenticate();
  141 +
  142 + Beans.getBeanManager().fireEvent(new AfterLogoutSuccessful() {
  143 +
  144 + private static final long serialVersionUID = 1L;
  145 + });
  146 + }
  147 + }
  148 +
  149 + /**
  150 + * @see br.gov.frameworkdemoiselle.security.SecurityContext#getUser()
  151 + */
  152 + @Override
  153 + public User getUser() {
  154 + User user = authenticator.getUser();
  155 +
  156 + if (!config.isEnabled() && user == null) {
  157 + user = new User() {
  158 +
  159 + private static final long serialVersionUID = 1L;
  160 +
  161 + @Override
  162 + public void setAttribute(Object key, Object value) {
  163 + }
  164 +
  165 + @Override
  166 + public String getId() {
  167 + return "demoiselle";
  168 + }
  169 +
  170 + @Override
  171 + public Object getAttribute(Object key) {
  172 + return null;
  173 + }
  174 + };
  175 + }
  176 +
  177 + return user;
  178 + }
  179 +
  180 + private void checkLoggedIn() throws NotLoggedInException {
  181 + if (!isLoggedIn()) {
  182 + throw new NotLoggedInException(bundle.getString("user-not-authenticated"));
  183 + }
  184 + }
  185 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionInfo.java 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +package br.gov.frameworkdemoiselle.internal.implementation;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +import javax.enterprise.context.RequestScoped;
  6 +
  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
  10 +public class TransactionInfo implements Serializable {
  11 +
  12 + private static final long serialVersionUID = 1L;
  13 +
  14 + private int counter = 0;
  15 +
  16 + private boolean owner = false;
  17 +
  18 + public int getCounter() {
  19 + return counter;
  20 + }
  21 +
  22 + public void incrementCounter() {
  23 + this.counter++;
  24 + }
  25 +
  26 + public void decrementCounter() {
  27 + this.counter--;
  28 + }
  29 +
  30 + public void markAsOwner() {
  31 + this.owner = true;
  32 + }
  33 +
  34 + public boolean isOwner() {
  35 + return owner;
  36 + }
  37 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptor.java 0 → 100644
... ... @@ -0,0 +1,177 @@
  1 +/*
  2 + * Demoiselle Framework Copyright (C) 2010 SERPRO
  3 + * ---------------------------------------------------------------------------- This file is part of Demoiselle
  4 + * Framework. Demoiselle Framework is free software; you can redistribute it and/or modify it under the terms of the GNU
  5 + * Lesser General Public License version 3 as published by the Free Software Foundation. This program is distributed in
  6 + * the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  7 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a
  8 + * copy of the GNU Lesser General Public License version 3 along with this program; if not, see
  9 + * <http://www.gnu.org/licenses/> or write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  10 + * Boston, MA 02110-1301, USA. ---------------------------------------------------------------------------- Este arquivo
  11 + * é parte do Framework Demoiselle. O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  12 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação do Software Livre (FSF). Este
  13 + * programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA GARANTIA; sem uma garantia implícita de
  14 + * ADEQUAÇÃO a qualquer MERCADO ou APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português para
  15 + * maiores detalhes. Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título "LICENCA.txt", junto com esse
  16 + * programa. Se não, acesse <http://www.gnu.org/licenses/> ou escreva para a Fundação do Software Livre (FSF) Inc., 51
  17 + * Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  18 + */
  19 +package br.gov.frameworkdemoiselle.internal.interceptor;
  20 +
  21 +import java.io.Serializable;
  22 +import java.lang.reflect.InvocationTargetException;
  23 +import java.lang.reflect.Method;
  24 +import java.util.HashMap;
  25 +import java.util.Map;
  26 +
  27 +import javax.inject.Inject;
  28 +import javax.interceptor.AroundInvoke;
  29 +import javax.interceptor.Interceptor;
  30 +import javax.interceptor.InvocationContext;
  31 +
  32 +import org.slf4j.Logger;
  33 +
  34 +import br.gov.frameworkdemoiselle.DemoiselleException;
  35 +import br.gov.frameworkdemoiselle.annotation.Name;
  36 +import br.gov.frameworkdemoiselle.exception.ExceptionHandler;
  37 +import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap;
  38 +import br.gov.frameworkdemoiselle.stereotype.Controller;
  39 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
  40 +
  41 +@Interceptor
  42 +@Controller
  43 +public class ExceptionHandlerInterceptor implements Serializable {
  44 +
  45 + private static final long serialVersionUID = 1L;
  46 +
  47 + private final ResourceBundle bundle;
  48 +
  49 + private final Logger logger;
  50 +
  51 + @Inject
  52 + public ExceptionHandlerInterceptor(Logger logger, @Name("demoiselle-core-bundle") ResourceBundle bundle) {
  53 + this.logger = logger;
  54 + this.bundle = bundle;
  55 + }
  56 +
  57 + private final Map<Class<?>, Map<Class<?>, Method>> cache = new HashMap<Class<?>, Map<Class<?>, Method>>();
  58 +
  59 + private final boolean handleException(final Exception cause, final InvocationContext ic) throws Throwable {
  60 + logger.info(bundle.getString("handling-exception", cause.getClass().getCanonicalName()));
  61 +
  62 + boolean handled = false;
  63 + Class<?> type = getType(ic);
  64 +
  65 + if (!isLoaded(type)) {
  66 + loadHandlers(type);
  67 + }
  68 +
  69 + Method handler = getMethod(type, cause);
  70 + if (handler != null) {
  71 + invoke(handler, ic.getTarget(), cause);
  72 + handled = true;
  73 + }
  74 +
  75 + return handled;
  76 + }
  77 +
  78 + private final Class<?> getType(final InvocationContext ic) {
  79 + Class<?> type = ic.getTarget().getClass();
  80 +
  81 + if (!CoreBootstrap.isAnnotatedType(type)) {
  82 + type = type.getSuperclass();
  83 + logger.debug(bundle.getString("proxy-detected", ic.getTarget().getClass(), ic.getTarget().getClass()
  84 + .getSuperclass()));
  85 + }
  86 +
  87 + return type;
  88 + }
  89 +
  90 + /**
  91 + * If there is an handler in the current class for the expected exception, then this method will be returned; Else
  92 + * returns null;
  93 + *
  94 + * @param type
  95 + * @param cause
  96 + * @return
  97 + */
  98 + private final Method getMethod(final Class<?> type, final Exception cause) {
  99 + Method handler = null;
  100 +
  101 + if (cache.containsKey(type) && cache.get(type).containsKey(cause.getClass())) {
  102 + handler = cache.get(type).get(cause.getClass());
  103 + }
  104 +
  105 + return handler;
  106 + }
  107 +
  108 + /**
  109 + * Create an map of Exception Handler for this class and put it on the cache.
  110 + *
  111 + * @param type
  112 + */
  113 + private final void loadHandlers(final Class<?> type) {
  114 + Map<Class<?>, Method> mapHandlers = new HashMap<Class<?>, Method>();
  115 + Method[] methods = type.getMethods();
  116 +
  117 + for (Method method : methods) {
  118 + if (method.isAnnotationPresent(ExceptionHandler.class)) {
  119 + validateHandler(method);
  120 + mapHandlers.put(method.getParameterTypes()[0], method);
  121 + }
  122 + }
  123 + cache.put(type, mapHandlers);
  124 + }
  125 +
  126 + /**
  127 + * Verify the method for compliance with an handler. It must be: public, single parameter, parameter type must be
  128 + * assigned from Exception
  129 + *
  130 + * @param method
  131 + */
  132 + private final void validateHandler(final Method method) {
  133 + if (method.getParameterTypes().length != 1) {
  134 + throw new DemoiselleException(bundle.getString("must-declare-one-single-parameter",
  135 + method.toGenericString()));
  136 + }
  137 + }
  138 +
  139 + /**
  140 + * Indicates if this class is already loaded in cache control.
  141 + *
  142 + * @param type
  143 + * @return
  144 + */
  145 + private final boolean isLoaded(final Class<?> type) {
  146 + return cache.containsKey(type);
  147 + }
  148 +
  149 + private final void invoke(final Method method, final Object object, final Exception param) throws Throwable {
  150 + boolean accessible = method.isAccessible();
  151 + method.setAccessible(true);
  152 +
  153 + try {
  154 + method.invoke(object, param);
  155 + } catch (InvocationTargetException cause) {
  156 + throw cause.getTargetException();
  157 + }
  158 +
  159 + method.setAccessible(accessible);
  160 + }
  161 +
  162 + @AroundInvoke
  163 + public Object manage(final InvocationContext ic) throws Throwable {
  164 + Object result = null;
  165 +
  166 + try {
  167 + result = ic.proceed();
  168 + } catch (Exception cause) {
  169 + if (!handleException(cause, ic)) {
  170 + throw cause;
  171 + }
  172 + }
  173 +
  174 + return result;
  175 + }
  176 +
  177 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredPermissionInterceptor.java 0 → 100644
... ... @@ -0,0 +1,176 @@
  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.interceptor;
  38 +
  39 +import java.io.Serializable;
  40 +
  41 +import javax.enterprise.inject.Instance;
  42 +import javax.inject.Inject;
  43 +import javax.interceptor.AroundInvoke;
  44 +import javax.interceptor.Interceptor;
  45 +import javax.interceptor.InvocationContext;
  46 +
  47 +import org.slf4j.Logger;
  48 +
  49 +import br.gov.frameworkdemoiselle.annotation.Name;
  50 +import br.gov.frameworkdemoiselle.security.AuthorizationException;
  51 +import br.gov.frameworkdemoiselle.security.RequiredPermission;
  52 +import br.gov.frameworkdemoiselle.security.SecurityContext;
  53 +import br.gov.frameworkdemoiselle.security.User;
  54 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
  55 +import br.gov.frameworkdemoiselle.util.Strings;
  56 +
  57 +/**
  58 + * Intercepts calls with {@code @RequiredPermission} annotations.
  59 + *
  60 + * @author SERPRO
  61 + */
  62 +@Interceptor
  63 +@RequiredPermission
  64 +public class RequiredPermissionInterceptor implements Serializable {
  65 +
  66 + private static final long serialVersionUID = 1L;
  67 +
  68 + private final Instance<SecurityContext> securityContext;
  69 +
  70 + private final ResourceBundle bundle;
  71 +
  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 + }
  81 +
  82 + /**
  83 + * Gets the values for both resource and operation properties of {@code @RequiredPermission}. Delegates to
  84 + * {@code SecurityContext} check permissions. If the user has the required permission it executes the mehtod,
  85 + * otherwise throws an exception. Returns what is returned from the intercepted method. If the method's return type
  86 + * is {@code void} returns {@code null}.
  87 + *
  88 + * @param ic
  89 + * the {@code InvocationContext} in which the method is being called
  90 + * @return what is returned from the intercepted method. If the method's return type is {@code void} returns
  91 + * {@code null}
  92 + * @throws Exception
  93 + * if there is an error during the permission check or during the method's processing
  94 + */
  95 + @AroundInvoke
  96 + public Object manage(final InvocationContext ic) throws Exception {
  97 + String resource = getResource(ic);
  98 + String operation = getOperation(ic);
  99 + String username = null;
  100 +
  101 + if (securityContext.get().isLoggedIn()) {
  102 + username = getUsername();
  103 + logger.trace(bundle.getString("access-checking", username, operation, resource));
  104 + }
  105 +
  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));
  109 + }
  110 +
  111 + logger.debug(bundle.getString("access-allowed", username, operation, resource));
  112 + return ic.proceed();
  113 + }
  114 +
  115 + /**
  116 + * Returns the id of the currently logged in user.
  117 + *
  118 + * @return the id of the currently logged in user
  119 + */
  120 + private String getUsername() {
  121 + String username = "";
  122 + User user = securityContext.get().getUser();
  123 +
  124 + if (user != null && user.getId() != null) {
  125 + username = user.getId();
  126 + }
  127 +
  128 + return username;
  129 + }
  130 +
  131 + /**
  132 + * Returns the resource defined in {@code @RequiredPermission} annotation, the name defined in {@code @Name}
  133 + * annotation or the class name itself
  134 + *
  135 + * @param ic
  136 + * the {@code InvocationContext} in which the method is being called
  137 + * @return the resource defined in {@code @RequiredPermission} annotation, the name defined in {@code @Name}
  138 + * annotation or the class name itself
  139 + */
  140 + private String getResource(InvocationContext ic) {
  141 + RequiredPermission requiredPermission = ic.getMethod().getAnnotation(RequiredPermission.class);
  142 +
  143 + if (requiredPermission == null || Strings.isEmpty(requiredPermission.resource())) {
  144 + if (ic.getTarget().getClass().getAnnotation(Name.class) == null) {
  145 + return ic.getTarget().getClass().getSimpleName();
  146 + } else {
  147 + return ic.getTarget().getClass().getAnnotation(Name.class).value();
  148 + }
  149 + } else {
  150 + return requiredPermission.resource();
  151 + }
  152 + }
  153 +
  154 + /**
  155 + * Returns the operation defined in {@code @RequiredPermission} annotation, the name defined in {@code @Name}
  156 + * annotation or the method's name itself
  157 + *
  158 + * @param ic
  159 + * the {@code InvocationContext} in which the method is being called
  160 + * @return the operation defined in {@code @RequiredPermission} annotation, the name defined in {@code @Name}
  161 + * annotation or the method's name itself
  162 + */
  163 + private String getOperation(InvocationContext ic) {
  164 + RequiredPermission requiredPermission = ic.getMethod().getAnnotation(RequiredPermission.class);
  165 +
  166 + if (requiredPermission == null || Strings.isEmpty(requiredPermission.operation())) {
  167 + if (ic.getMethod().getAnnotation(Name.class) == null) {
  168 + return ic.getMethod().getName();
  169 + } else {
  170 + return ic.getMethod().getAnnotation(Name.class).value();
  171 + }
  172 + } else {
  173 + return requiredPermission.operation();
  174 + }
  175 + }
  176 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredRoleInterceptor.java 0 → 100644
... ... @@ -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.interceptor;
  38 +
  39 +import java.io.Serializable;
  40 +import java.util.ArrayList;
  41 +import java.util.Arrays;
  42 +import java.util.List;
  43 +
  44 +import javax.enterprise.inject.Instance;
  45 +import javax.inject.Inject;
  46 +import javax.interceptor.AroundInvoke;
  47 +import javax.interceptor.Interceptor;
  48 +import javax.interceptor.InvocationContext;
  49 +
  50 +import org.slf4j.Logger;
  51 +
  52 +import br.gov.frameworkdemoiselle.annotation.Name;
  53 +import br.gov.frameworkdemoiselle.security.AuthorizationException;
  54 +import br.gov.frameworkdemoiselle.security.RequiredRole;
  55 +import br.gov.frameworkdemoiselle.security.SecurityContext;
  56 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
  57 +
  58 +/**
  59 + * Intercepts calls with {@code @RequiredRole} annotations.
  60 + *
  61 + * @author SERPRO
  62 + */
  63 +@Interceptor
  64 +@RequiredRole(value = "")
  65 +public class RequiredRoleInterceptor implements Serializable {
  66 +
  67 + private static final long serialVersionUID = 1L;
  68 +
  69 + private final Instance<SecurityContext> securityContext;
  70 +
  71 + private final ResourceBundle bundle;
  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 + }
  82 +
  83 + /**
  84 + * Gets the value property of {@code @RequiredRole}. Delegates to {@code SecurityContext} check role. If the user
  85 + * has the required role it executes the mehtod, otherwise throws an exception. Returns what is returned from the
  86 + * intercepted method. If the method's return type is {@code void} returns {@code null}.
  87 + *
  88 + * @param ic
  89 + * the {@code InvocationContext} in which the method is being called
  90 + * @return what is returned from the intercepted method. If the method's return type is {@code void} returns
  91 + * {@code null}
  92 + * @throws Exception
  93 + * if there is an error during the role check or during the method's processing
  94 + */
  95 + @AroundInvoke
  96 + public Object manage(final InvocationContext ic) throws Exception {
  97 +
  98 + List<String> roles = getRoles(ic);
  99 +
  100 + if (securityContext.get().isLoggedIn()) {
  101 + logger.info(bundle.getString("has-role-verification", securityContext.get().getUser().getId(), roles));
  102 + }
  103 +
  104 + List<String> userRoles = new ArrayList<String>();
  105 +
  106 + for (String role : roles) {
  107 + if (securityContext.get().hasRole(role)) {
  108 + userRoles.add(role);
  109 + }
  110 + }
  111 +
  112 + if (userRoles.isEmpty()) {
  113 + logger.error(bundle.getString("does-not-have-role", securityContext.get().getUser().getId(), roles));
  114 +
  115 + @SuppressWarnings("unused")
  116 + AuthorizationException a = new AuthorizationException(null);
  117 + throw new AuthorizationException(bundle.getString("does-not-have-role-ui", roles));
  118 + }
  119 +
  120 + logger.debug(bundle.getString("user-has-role", securityContext.get().getUser().getId(), userRoles));
  121 +
  122 + return ic.proceed();
  123 +
  124 + }
  125 +
  126 + /**
  127 + * Returns the value defined in {@code @RequiredRole} annotation.
  128 + *
  129 + * @param ic
  130 + * the {@code InvocationContext} in which the method is being called
  131 + * @return the value defined in {@code @RequiredRole} annotation
  132 + */
  133 + private List<String> getRoles(InvocationContext ic) {
  134 +
  135 + String[] roles = {};
  136 +
  137 + if (ic.getMethod().getAnnotation(RequiredRole.class) == null) {
  138 +
  139 + if (ic.getTarget().getClass().getAnnotation(RequiredRole.class) != null) {
  140 + roles = ic.getTarget().getClass().getAnnotation(RequiredRole.class).value();
  141 + }
  142 +
  143 + } else {
  144 +
  145 + roles = ic.getMethod().getAnnotation(RequiredRole.class).value();
  146 +
  147 + }
  148 +
  149 + return Arrays.asList(roles);
  150 +
  151 + }
  152 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/interceptor/TransactionalInterceptor.java 0 → 100644
... ... @@ -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.interceptor;
  38 +
  39 +import java.io.Serializable;
  40 +
  41 +import javax.enterprise.inject.Instance;
  42 +import javax.inject.Inject;
  43 +import javax.interceptor.AroundInvoke;
  44 +import javax.interceptor.Interceptor;
  45 +import javax.interceptor.InvocationContext;
  46 +
  47 +import org.slf4j.Logger;
  48 +
  49 +import br.gov.frameworkdemoiselle.annotation.Name;
  50 +import br.gov.frameworkdemoiselle.exception.ApplicationException;
  51 +import br.gov.frameworkdemoiselle.internal.implementation.TransactionInfo;
  52 +import br.gov.frameworkdemoiselle.transaction.Transaction;
  53 +import br.gov.frameworkdemoiselle.transaction.Transactional;
  54 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
  55 +
  56 +@Interceptor
  57 +@Transactional
  58 +public class TransactionalInterceptor implements Serializable {
  59 +
  60 + private static final long serialVersionUID = 1L;
  61 +
  62 + private final Instance<Transaction> transaction;
  63 +
  64 + private final Logger logger;
  65 +
  66 + private final ResourceBundle bundle;
  67 +
  68 + private final Instance<TransactionInfo> transactionInfo;
  69 +
  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;
  77 +
  78 + }
  79 +
  80 + @AroundInvoke
  81 + public Object manage(final InvocationContext ic) throws Exception {
  82 + initiate(ic);
  83 +
  84 + Object result = null;
  85 + try {
  86 + this.logger.debug(bundle.getString("transactional-execution", ic.getMethod().toGenericString()));
  87 + transactionInfo.get().incrementCounter();
  88 +
  89 + result = ic.proceed();
  90 +
  91 + } catch (Exception cause) {
  92 + handleException(cause);
  93 + throw cause;
  94 +
  95 + } finally {
  96 + transactionInfo.get().decrementCounter();
  97 + complete(ic);
  98 + }
  99 +
  100 + return result;
  101 + }
  102 +
  103 + private void initiate(final InvocationContext ic) {
  104 + Transaction tx = this.transaction.get();
  105 + TransactionInfo ctx = this.transactionInfo.get();
  106 +
  107 + if (!tx.isActive()) {
  108 + tx.begin();
  109 + ctx.markAsOwner();
  110 + this.logger.info(bundle.getString("begin-transaction"));
  111 + }
  112 + }
  113 +
  114 + private void handleException(final Exception cause) {
  115 + Transaction tx = this.transaction.get();
  116 +
  117 + if (!tx.isMarkedRollback()) {
  118 + boolean rollback = false;
  119 + ApplicationException annotation = cause.getClass().getAnnotation(ApplicationException.class);
  120 +
  121 + if (annotation == null || annotation.rollback()) {
  122 + rollback = true;
  123 + }
  124 +
  125 + if (rollback) {
  126 + tx.setRollbackOnly();
  127 + this.logger.info(bundle.getString("transaction-marked-rollback", cause.getMessage()));
  128 + }
  129 + }
  130 + }
  131 +
  132 + private void complete(final InvocationContext ic) {
  133 + Transaction tx = this.transaction.get();
  134 + TransactionInfo ctx = this.transactionInfo.get();
  135 +
  136 + if (ctx.getCounter() == 0 && tx.isActive()) {
  137 +
  138 + if (ctx.isOwner()) {
  139 + if (tx.isMarkedRollback()) {
  140 + tx.rollback();
  141 + this.logger.info(bundle.getString("transaction-rolledback"));
  142 + } else {
  143 + tx.commit();
  144 + this.logger.info(bundle.getString("transaction-commited"));
  145 + }
  146 + }
  147 +
  148 + } else if (ctx.getCounter() == 0 && !tx.isActive()) {
  149 + this.logger.info(bundle.getString("transaction-already-finalized"));
  150 + }
  151 + }
  152 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/AbstractProcessor.java 0 → 100644
... ... @@ -0,0 +1,117 @@
  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.AnnotatedCallable;
  40 +import javax.enterprise.inject.spi.Bean;
  41 +import javax.enterprise.inject.spi.BeanManager;
  42 +
  43 +import org.slf4j.Logger;
  44 +
  45 +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
  46 +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
  47 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
  48 +
  49 +/**
  50 + * It abstract the integration between Processor and the context;
  51 + *
  52 + * @param <DC>
  53 + * the declaring class
  54 + */
  55 +public abstract class AbstractProcessor<DC> implements Processor {
  56 +
  57 + private BeanManager beanManager;
  58 +
  59 + private AnnotatedCallable<DC> annotatedCallable;
  60 +
  61 + private ResourceBundleProducer bundleFactory = new ResourceBundleProducer();
  62 +
  63 + private ResourceBundle bundle;
  64 +
  65 + protected static final String BUNDLE_BASE_NAME = "demoiselle-core-bundle";
  66 +
  67 + public AbstractProcessor(final BeanManager beanManager) {
  68 + this.beanManager = beanManager;
  69 + }
  70 +
  71 + public AbstractProcessor(final AnnotatedCallable<DC> annotatedCallable, final BeanManager beanManager) {
  72 + this.annotatedCallable = annotatedCallable;
  73 + this.beanManager = beanManager;
  74 + }
  75 +
  76 + protected AnnotatedCallable<DC> getAnnotatedCallable() {
  77 + return this.annotatedCallable;
  78 + }
  79 +
  80 + protected BeanManager getBeanManager() {
  81 + return this.beanManager;
  82 + }
  83 +
  84 + /**
  85 + * Ask the bean manager for the firt instance of the declaring classe for this java member, then returns the current
  86 + * reference;
  87 + *
  88 + * @param <T>
  89 + * DeclaringClass
  90 + * @return
  91 + */
  92 + @SuppressWarnings("unchecked")
  93 + protected DC getReferencedBean() {
  94 + Class<DC> classType = (Class<DC>) getAnnotatedCallable().getJavaMember().getDeclaringClass();
  95 + return getReferencedBean(classType);
  96 + }
  97 +
  98 + @SuppressWarnings("unchecked")
  99 + protected DC getReferencedBean(final Class<DC> type) {
  100 + Bean<DC> bean = (Bean<DC>) beanManager.getBeans(type).iterator().next();
  101 + return (DC) beanManager.getReference(bean, type, beanManager.createCreationalContext(bean));
  102 + }
  103 +
  104 + protected ResourceBundle getBundle() {
  105 + return getBundle(BUNDLE_BASE_NAME);
  106 + }
  107 +
  108 + protected ResourceBundle getBundle(String baseName) {
  109 + if (bundle == null)
  110 + bundle = bundleFactory.create(baseName);
  111 + return bundle;
  112 + }
  113 +
  114 + protected Logger getLogger() {
  115 + return LoggerProducer.create(this.getClass());
  116 + }
  117 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/AnnotatedMethodProcessor.java 0 → 100644
... ... @@ -0,0 +1,105 @@
  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 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/Processor.java 0 → 100644
... ... @@ -0,0 +1,45 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +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 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/ShutdownProcessor.java 0 → 100644
... ... @@ -0,0 +1,63 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.internal.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 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/StartupProcessor.java 0 → 100644
... ... @@ -0,0 +1,68 @@
  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 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ContextProducer.java 0 → 100644
... ... @@ -0,0 +1,84 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +/*
  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 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/LocaleProducer.java 0 → 100644
... ... @@ -0,0 +1,16 @@
  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 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/LoggerProducer.java 0 → 100644
... ... @@ -0,0 +1,83 @@
  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.enterprise.inject.spi.InjectionPoint;
  56 +
  57 +import org.slf4j.Logger;
  58 +import org.slf4j.LoggerFactory;
  59 +
  60 +import br.gov.frameworkdemoiselle.internal.proxy.Slf4jLoggerProxy;
  61 +
  62 +public class LoggerProducer implements Serializable {
  63 +
  64 + private static final long serialVersionUID = 1L;
  65 +
  66 + @Produces
  67 + @Default
  68 + public static Logger create(final InjectionPoint ip) {
  69 + Class<?> type;
  70 +
  71 + if (ip != null) {
  72 + type = ip.getMember().getDeclaringClass();
  73 + } else {
  74 + type = LoggerProducer.class;
  75 + }
  76 +
  77 + return create(type);
  78 + }
  79 +
  80 + public static <T> Logger create(Class<T> type) {
  81 + return new Slf4jLoggerProxy(LoggerFactory.getLogger(type));
  82 + }
  83 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducer.java 0 → 100644
... ... @@ -0,0 +1,135 @@
  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.producer;
  38 +
  39 +import java.io.Serializable;
  40 +import java.util.HashMap;
  41 +import java.util.Locale;
  42 +import java.util.Map;
  43 +import java.util.MissingResourceException;
  44 +
  45 +import javax.enterprise.context.ApplicationScoped;
  46 +import javax.enterprise.inject.Default;
  47 +import javax.enterprise.inject.Produces;
  48 +import javax.enterprise.inject.spi.InjectionPoint;
  49 +import javax.inject.Inject;
  50 +
  51 +import br.gov.frameworkdemoiselle.DemoiselleException;
  52 +import br.gov.frameworkdemoiselle.annotation.Name;
  53 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
  54 +
  55 +/**
  56 + * This factory creates ResourceBundles with the application scopes.
  57 + *
  58 + * @author SERPRO
  59 + */
  60 +@ApplicationScoped
  61 +public class ResourceBundleProducer implements Serializable {
  62 +
  63 + private static final long serialVersionUID = 1L;
  64 +
  65 + @Inject
  66 + protected Locale locale;
  67 +
  68 + private final Map<String, ResourceBundle> map = new HashMap<String, ResourceBundle>();
  69 +
  70 + public ResourceBundleProducer() {
  71 + this.locale = Locale.getDefault();
  72 + }
  73 +
  74 + /**
  75 + * This constructor should be used by classes that can not inject ResourceBundle.
  76 + *
  77 + * @param Locale
  78 + * locale
  79 + */
  80 + public ResourceBundleProducer(Locale locale) {
  81 + this.locale = locale;
  82 + }
  83 +
  84 + /**
  85 + * This method should be used by classes that can not inject ResourceBundle, to create the ResourceBundle.
  86 + *
  87 + * @param String
  88 + * baseName
  89 + */
  90 + public ResourceBundle create(String baseName) {
  91 + return getResourceBundle(baseName);
  92 + }
  93 +
  94 + /**
  95 + * This method is the factory default for ResourceBundle. It creates the ResourceBundle based on a file called
  96 + * messages.properties.
  97 + */
  98 + @Produces
  99 + @Default
  100 + public ResourceBundle create(InjectionPoint ip, Locale locale) {
  101 + this.locale = locale;
  102 + String baseName;
  103 +
  104 + if (ip != null && ip.getAnnotated().isAnnotationPresent(Name.class)) {
  105 + baseName = ip.getAnnotated().getAnnotation(Name.class).value();
  106 + } else {
  107 + baseName = "messages";
  108 + }
  109 +
  110 + return create(baseName);
  111 + }
  112 +
  113 + /**
  114 + * This method checks if the bundle was created already. If the bundle has not been created, it creates and saves
  115 + * the bundle on a Map.
  116 + */
  117 + private ResourceBundle getResourceBundle(String baseName) {
  118 + ResourceBundle bundle = null;
  119 +
  120 + if (map.containsKey(baseName + "-" + this.locale)) {
  121 + bundle = map.get(baseName + "-" + this.locale);
  122 +
  123 + } else {
  124 + try {
  125 + bundle = new ResourceBundle(ResourceBundle.getBundle(baseName, this.locale));
  126 + } catch (MissingResourceException e) {
  127 + throw new DemoiselleException("File " + baseName + " not found!");
  128 + }
  129 + map.put(baseName + "-" + this.locale, bundle);
  130 + }
  131 +
  132 + return bundle;
  133 + }
  134 +
  135 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/ContextProxy.java 0 → 100644
... ... @@ -0,0 +1,168 @@
  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 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/Slf4jLoggerProxy.java 0 → 100644
... ... @@ -0,0 +1,371 @@
  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.proxy;
  50 +
  51 +import java.io.Serializable;
  52 +
  53 +import org.slf4j.Logger;
  54 +import org.slf4j.Marker;
  55 +
  56 +public class Slf4jLoggerProxy implements Logger, Serializable {
  57 +
  58 + private static final long serialVersionUID = 1L;
  59 +
  60 + private transient final Logger delegate;
  61 +
  62 + public Slf4jLoggerProxy(final Logger logger) {
  63 + this.delegate = logger;
  64 + }
  65 +
  66 + @Override
  67 + public void debug(final Marker marker, final String msg) {
  68 + this.delegate.debug(marker, msg);
  69 + }
  70 +
  71 + @Override
  72 + public void debug(final Marker marker, final String format, final Object arg) {
  73 + this.delegate.debug(marker, format, arg);
  74 + }
  75 +
  76 + @Override
  77 + public void debug(final Marker marker, final String format, final Object arg1, final Object arg2) {
  78 + this.delegate.debug(marker, format, arg1, arg2);
  79 + }
  80 +
  81 + @Override
  82 + public void debug(final Marker marker, final String format, final Object[] argArray) {
  83 + this.delegate.debug(marker, format, argArray);
  84 + }
  85 +
  86 + @Override
  87 + public void debug(final Marker marker, final String msg, final Throwable t) {
  88 + this.delegate.debug(marker, msg, t);
  89 + }
  90 +
  91 + @Override
  92 + public void debug(final String msg) {
  93 + this.delegate.debug(msg);
  94 + }
  95 +
  96 + @Override
  97 + public void debug(final String format, final Object arg) {
  98 + this.delegate.debug(format, arg);
  99 + }
  100 +
  101 + @Override
  102 + public void debug(final String format, final Object arg1, final Object arg2) {
  103 + this.delegate.debug(format, arg1, arg2);
  104 + }
  105 +
  106 + @Override
  107 + public void debug(final String format, final Object[] argArray) {
  108 + this.delegate.debug(format, argArray);
  109 + }
  110 +
  111 + @Override
  112 + public void debug(final String msg, final Throwable t) {
  113 + this.delegate.debug(msg, t);
  114 + }
  115 +
  116 + @Override
  117 + public void error(final Marker marker, final String msg) {
  118 + this.delegate.error(marker, msg);
  119 + }
  120 +
  121 + @Override
  122 + public void error(final Marker marker, final String format, final Object arg) {
  123 + this.delegate.error(marker, format, arg);
  124 + }
  125 +
  126 + @Override
  127 + public void error(final Marker marker, final String format, final Object arg1, final Object arg2) {
  128 + this.delegate.error(marker, format, arg1, arg2);
  129 + }
  130 +
  131 + @Override
  132 + public void error(final Marker marker, final String format, final Object[] argArray) {
  133 + this.delegate.error(marker, format, argArray);
  134 + }
  135 +
  136 + @Override
  137 + public void error(final Marker marker, final String msg, final Throwable t) {
  138 + this.delegate.error(marker, msg, t);
  139 + }
  140 +
  141 + @Override
  142 + public void error(final String msg) {
  143 + this.delegate.error(msg);
  144 + }
  145 +
  146 + @Override
  147 + public void error(final String format, final Object arg) {
  148 + this.delegate.error(format, arg);
  149 + }
  150 +
  151 + @Override
  152 + public void error(final String format, final Object arg1, final Object arg2) {
  153 + this.delegate.error(format, arg1, arg2);
  154 + }
  155 +
  156 + @Override
  157 + public void error(final String format, final Object[] argArray) {
  158 + this.delegate.error(format, argArray);
  159 + }
  160 +
  161 + @Override
  162 + public void error(final String msg, final Throwable t) {
  163 + this.delegate.error(msg, t);
  164 + }
  165 +
  166 + @Override
  167 + public String getName() {
  168 + return this.delegate.getName();
  169 + }
  170 +
  171 + @Override
  172 + public void info(final Marker marker, final String msg) {
  173 + this.delegate.info(marker, msg);
  174 + }
  175 +
  176 + @Override
  177 + public void info(final Marker marker, final String format, final Object arg) {
  178 + this.delegate.info(marker, format, arg);
  179 + }
  180 +
  181 + @Override
  182 + public void info(final Marker marker, final String format, final Object arg1, final Object arg2) {
  183 + this.delegate.info(marker, format, arg1, arg2);
  184 + }
  185 +
  186 + @Override
  187 + public void info(final Marker marker, final String format, final Object[] argArray) {
  188 + this.delegate.info(marker, format, argArray);
  189 + }
  190 +
  191 + @Override
  192 + public void info(final Marker marker, final String msg, final Throwable t) {
  193 + this.delegate.info(marker, msg, t);
  194 + }
  195 +
  196 + @Override
  197 + public void info(final String msg) {
  198 + this.delegate.info(msg);
  199 + }
  200 +
  201 + @Override
  202 + public void info(final String format, final Object arg) {
  203 + this.delegate.info(format, arg);
  204 + }
  205 +
  206 + @Override
  207 + public void info(final String format, final Object arg1, final Object arg2) {
  208 + this.delegate.info(format, arg1, arg2);
  209 + }
  210 +
  211 + @Override
  212 + public void info(final String format, final Object[] argArray) {
  213 + this.delegate.info(format, argArray);
  214 + }
  215 +
  216 + @Override
  217 + public void info(final String msg, final Throwable t) {
  218 + this.delegate.info(msg, t);
  219 + }
  220 +
  221 + @Override
  222 + public boolean isDebugEnabled() {
  223 + return this.delegate.isDebugEnabled();
  224 + }
  225 +
  226 + @Override
  227 + public boolean isDebugEnabled(final Marker marker) {
  228 + return this.delegate.isDebugEnabled(marker);
  229 + }
  230 +
  231 + @Override
  232 + public boolean isErrorEnabled() {
  233 + return this.delegate.isErrorEnabled();
  234 + }
  235 +
  236 + @Override
  237 + public boolean isErrorEnabled(final Marker marker) {
  238 + return this.delegate.isErrorEnabled(marker);
  239 + }
  240 +
  241 + @Override
  242 + public boolean isInfoEnabled() {
  243 + return this.delegate.isInfoEnabled();
  244 + }
  245 +
  246 + @Override
  247 + public boolean isInfoEnabled(final Marker marker) {
  248 + return this.delegate.isInfoEnabled(marker);
  249 + }
  250 +
  251 + @Override
  252 + public boolean isTraceEnabled() {
  253 + return this.delegate.isTraceEnabled();
  254 + }
  255 +
  256 + @Override
  257 + public boolean isTraceEnabled(final Marker marker) {
  258 + return this.delegate.isTraceEnabled(marker);
  259 + }
  260 +
  261 + @Override
  262 + public boolean isWarnEnabled() {
  263 + return this.delegate.isWarnEnabled();
  264 + }
  265 +
  266 + @Override
  267 + public boolean isWarnEnabled(final Marker marker) {
  268 + return this.delegate.isWarnEnabled(marker);
  269 + }
  270 +
  271 + @Override
  272 + public void trace(final Marker marker, final String msg) {
  273 + this.delegate.trace(marker, msg);
  274 + }
  275 +
  276 + @Override
  277 + public void trace(final Marker marker, final String format, final Object arg) {
  278 + this.delegate.trace(marker, format, arg);
  279 + }
  280 +
  281 + @Override
  282 + public void trace(final Marker marker, final String format, final Object arg1, final Object arg2) {
  283 + this.delegate.trace(marker, format, arg1, arg2);
  284 + }
  285 +
  286 + @Override
  287 + public void trace(final Marker marker, final String format, final Object[] argArray) {
  288 + this.delegate.trace(marker, format, argArray);
  289 + }
  290 +
  291 + @Override
  292 + public void trace(final Marker marker, final String msg, final Throwable t) {
  293 + this.delegate.trace(marker, msg, t);
  294 + }
  295 +
  296 + @Override
  297 + public void trace(final String msg) {
  298 + this.delegate.trace(msg);
  299 + }
  300 +
  301 + @Override
  302 + public void trace(final String format, final Object arg) {
  303 + this.delegate.trace(format, arg);
  304 + }
  305 +
  306 + @Override
  307 + public void trace(final String format, final Object arg1, final Object arg2) {
  308 + this.delegate.trace(format, arg1, arg2);
  309 + }
  310 +
  311 + @Override
  312 + public void trace(final String format, final Object[] argArray) {
  313 + this.delegate.trace(format, argArray);
  314 + }
  315 +
  316 + @Override
  317 + public void trace(final String msg, final Throwable t) {
  318 + this.delegate.trace(msg, t);
  319 + }
  320 +
  321 + @Override
  322 + public void warn(final Marker marker, final String msg) {
  323 + this.delegate.warn(marker, msg);
  324 + }
  325 +
  326 + @Override
  327 + public void warn(final Marker marker, final String format, final Object arg) {
  328 + this.delegate.warn(marker, format, arg);
  329 + }
  330 +
  331 + @Override
  332 + public void warn(final Marker marker, final String format, final Object arg1, final Object arg2) {
  333 + this.delegate.warn(marker, format, arg1, arg2);
  334 + }
  335 +
  336 + @Override
  337 + public void warn(final Marker marker, final String format, final Object[] argArray) {
  338 + this.delegate.warn(marker, format, argArray);
  339 + }
  340 +
  341 + @Override
  342 + public void warn(final Marker marker, final String msg, final Throwable t) {
  343 + this.delegate.warn(marker, msg, t);
  344 + }
  345 +
  346 + @Override
  347 + public void warn(final String msg) {
  348 + this.delegate.warn(msg);
  349 + }
  350 +
  351 + @Override
  352 + public void warn(final String format, final Object arg) {
  353 + this.delegate.warn(format, arg);
  354 + }
  355 +
  356 + @Override
  357 + public void warn(final String format, final Object arg1, final Object arg2) {
  358 + this.delegate.warn(format, arg1, arg2);
  359 + }
  360 +
  361 + @Override
  362 + public void warn(final String format, final Object[] argArray) {
  363 + this.delegate.warn(format, argArray);
  364 + }
  365 +
  366 + @Override
  367 + public void warn(final String msg, final Throwable t) {
  368 + this.delegate.warn(msg, t);
  369 + }
  370 +
  371 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/message/DefaultMessage.java 0 → 100644
... ... @@ -0,0 +1,101 @@
  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.message;
  38 +
  39 +import javax.enterprise.inject.Alternative;
  40 +
  41 +import br.gov.frameworkdemoiselle.util.Beans;
  42 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
  43 +import br.gov.frameworkdemoiselle.util.Strings;
  44 +
  45 +/**
  46 + * @author SERPRO
  47 + */
  48 +@Alternative
  49 +public class DefaultMessage implements Message {
  50 +
  51 + private final String originalText;
  52 +
  53 + private String parsedText;
  54 +
  55 + private final SeverityType severity;
  56 +
  57 + private final Object[] params;
  58 +
  59 + private final ResourceBundle bundle;
  60 +
  61 + public static final SeverityType DEFAULT_SEVERITY = SeverityType.INFO;
  62 +
  63 + public DefaultMessage(String text, SeverityType severity, Object... params) {
  64 + this.originalText = text;
  65 + this.severity = (severity == null ? DEFAULT_SEVERITY : severity);
  66 + this.params = params;
  67 + this.bundle = Beans.getReference(ResourceBundle.class);
  68 + }
  69 +
  70 + public DefaultMessage(String text, Object... params) {
  71 + this(text, null, (Object[]) params);
  72 + }
  73 +
  74 + public String getText() {
  75 + initParsedText();
  76 + return parsedText;
  77 + }
  78 +
  79 + private void initParsedText() {
  80 + if (parsedText == null) {
  81 + if (Strings.isResourceBundleKeyFormat(originalText)) {
  82 + parsedText = bundle.getString(Strings.removeBraces(originalText));
  83 +
  84 + } else if (originalText != null) {
  85 + parsedText = new String(originalText);
  86 + }
  87 +
  88 + parsedText = Strings.getString(parsedText, params);
  89 + }
  90 + }
  91 +
  92 + public SeverityType getSeverity() {
  93 + return severity;
  94 + }
  95 +
  96 + @Override
  97 + public String toString() {
  98 + initParsedText();
  99 + return Strings.toString(this);
  100 + }
  101 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/message/Message.java 0 → 100644
... ... @@ -0,0 +1,60 @@
  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.message;
  38 +
  39 +/**
  40 + * Represents the configuration of a single message.
  41 + *
  42 + * @author SERPRO
  43 + */
  44 +public interface Message {
  45 +
  46 + /**
  47 + * Represents the text of the message.
  48 + */
  49 + String getText();
  50 +
  51 +// void setText(String text);
  52 +
  53 + /**
  54 + * Represents the kind of message. It could be useful for presentation layer.
  55 + */
  56 + SeverityType getSeverity();
  57 +
  58 +// void setSeverity(SeverityType severity);
  59 +
  60 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/message/MessageContext.java 0 → 100644
... ... @@ -0,0 +1,75 @@
  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.message;
  38 +
  39 +import java.util.List;
  40 +
  41 +/**
  42 + * Context interface reserved for messaging purposes.
  43 + * <p>
  44 + * In order to use this, just add the line below in the code:
  45 + * <p>
  46 + * <code>@Inject MessageContext messageContext;</code>
  47 + *
  48 + * @author SERPRO
  49 + * @see Message
  50 + */
  51 +public interface MessageContext {
  52 +
  53 + /**
  54 + * Saves a message into the context.
  55 + *
  56 + * @param message
  57 + */
  58 +
  59 + void add(Message message, Object... params);
  60 +
  61 + void add(String text, Object... params);
  62 +
  63 + void add(String text, SeverityType severity, Object... params);
  64 +
  65 + /**
  66 + * Returns all messages in the context.
  67 + */
  68 + List<Message> getMessages();
  69 +
  70 + /**
  71 + * Clears the list of messages in the context.
  72 + */
  73 + void clear();
  74 +
  75 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/message/SeverityType.java 0 → 100644
... ... @@ -0,0 +1,66 @@
  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.message;
  38 +
  39 +/**
  40 + * Defines severity types to be used.
  41 + *
  42 + * @author SERPRO
  43 + */
  44 +public enum SeverityType {
  45 +
  46 + /**
  47 + * Information (less critical)
  48 + */
  49 + INFO,
  50 +
  51 + /**
  52 + * Warning
  53 + */
  54 + WARN,
  55 +
  56 + /**
  57 + * Error
  58 + */
  59 + ERROR,
  60 +
  61 + /**
  62 + * Fatal (most critical)
  63 + */
  64 + FATAL
  65 +
  66 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/pagination/Pagination.java 0 → 100644
... ... @@ -0,0 +1,92 @@
  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.pagination;
  38 +
  39 +/**
  40 + * Structure used to handle pagination of data results on both <i>backend</i> (i.e., persistence) and <i>frontend</i>
  41 + * (i.e., presentation) layers in the application.
  42 + *
  43 + * @author SERPRO
  44 + */
  45 +public interface Pagination {
  46 +
  47 + /**
  48 + * Returns the current page.
  49 + */
  50 + int getCurrentPage();
  51 +
  52 + /**
  53 + * Sets the current page.
  54 + */
  55 + void setCurrentPage(int currentPage);
  56 +
  57 + /**
  58 + * Returns the page size.
  59 + */
  60 + int getPageSize();
  61 +
  62 + /**
  63 + * Sets the page size.
  64 + */
  65 + void setPageSize(int pageSize);
  66 +
  67 + /**
  68 + * Returns the total number of results.
  69 + */
  70 + int getTotalResults();
  71 +
  72 + /**
  73 + * Sets the total number of results and calculates the number of pages.
  74 + */
  75 + void setTotalResults(int totalResults);
  76 +
  77 + /**
  78 + * Returns the total number of pages.
  79 + */
  80 + int getTotalPages();
  81 +
  82 + /**
  83 + * Returns the position for the first record according to current page and page size.
  84 + */
  85 + int getFirstResult();
  86 +
  87 + /**
  88 + * Sets the position for the first record and hence calculates current page according to page size.
  89 + */
  90 + void setFirstResult(int firstResult);
  91 +
  92 +}
... ...
core/src/main/java/br/gov/frameworkdemoiselle/pagination/PaginationContext.java 0 → 100644
... ... @@ -0,0 +1,69 @@
  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.pagination;
  38 +
  39 +/**
  40 + * Context interface reserved for pagination purposes.
  41 + * <p>
  42 + * In order to use this, just add the line below in the code:
  43 + * <p>
  44 + * <code>@Inject PaginationContext paginationContext;</code>
  45 + *
  46 + * @author SERPRO
  47 + * @see Pagination
  48 + */
  49 +public interface PaginationContext {
  50 +
  51 + /**
  52 + * Retrieves the pagination according to the class type specified.
  53 + *
  54 + * @param clazz a {@code Class} type
  55 + * @return Pagination
  56 + */
  57 + Pagination getPagination(Class<?> clazz);
  58 +
  59 + /**
  60 + * Retrieves the pagination according to the class type specified. If not existing, creates the pagination whenever
  61 + * {@code create} parameter is true.
  62 + *
  63 + * @param clazz a {@code Class} type
  64 + * @param create determines whether pagination must always be returned
  65 + * @return Pagination
  66 + */
  67 + Pagination getPagination(Class<?> clazz, boolean create);
  68 +
  69 +}
... ...