Commit b7e706eb51964f5e60132a5327f47dc8d33f7cab

Authored by Dancovich
2 parents 92684952 5d81688c
Exists in master

Merge remote-tracking branch 'origin/2.4.0' into 2.4.0

Conflicts:
	impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ManagementBootstrap.java
	impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/Management.java
Showing 51 changed files with 1455 additions and 1094 deletions   Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ManagementBootstrap.java
@@ -52,10 +52,10 @@ import javax.enterprise.inject.spi.Extension; @@ -52,10 +52,10 @@ import javax.enterprise.inject.spi.Extension;
52 import javax.enterprise.inject.spi.ProcessAnnotatedType; 52 import javax.enterprise.inject.spi.ProcessAnnotatedType;
53 53
54 import br.gov.frameworkdemoiselle.DemoiselleException; 54 import br.gov.frameworkdemoiselle.DemoiselleException;
55 -import br.gov.frameworkdemoiselle.internal.management.ManagedType;  
56 -import br.gov.frameworkdemoiselle.internal.management.Management; 55 +import br.gov.frameworkdemoiselle.internal.implementation.ManagedType;
  56 +import br.gov.frameworkdemoiselle.internal.implementation.Management;
57 import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; 57 import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess;
58 -import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; 58 +import br.gov.frameworkdemoiselle.management.ManagementExtension;
59 import br.gov.frameworkdemoiselle.stereotype.ManagementController; 59 import br.gov.frameworkdemoiselle.stereotype.ManagementController;
60 import br.gov.frameworkdemoiselle.util.Beans; 60 import br.gov.frameworkdemoiselle.util.Beans;
61 import br.gov.frameworkdemoiselle.util.ResourceBundle; 61 import br.gov.frameworkdemoiselle.util.ResourceBundle;
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AttributeChange.java 0 → 100644
@@ -0,0 +1,62 @@ @@ -0,0 +1,62 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.internal.implementation;
  38 +
  39 +import java.lang.annotation.ElementType;
  40 +import java.lang.annotation.Retention;
  41 +import java.lang.annotation.RetentionPolicy;
  42 +import java.lang.annotation.Target;
  43 +
  44 +import javax.inject.Qualifier;
  45 +
  46 +import br.gov.frameworkdemoiselle.management.AttributeChangeNotification;
  47 +import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent;
  48 +
  49 +/**
  50 + *
  51 + * Enables {@link ManagementNotificationEvent} observers to trigger only with notifications
  52 + * of the specialized type {@link AttributeChangeNotification}.
  53 + *
  54 + * @author SERPRO
  55 + *
  56 + */
  57 +@Qualifier
  58 +@Retention(RetentionPolicy.RUNTIME)
  59 +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})
  60 +public @interface AttributeChange {
  61 +
  62 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/Generic.java 0 → 100644
@@ -0,0 +1,62 @@ @@ -0,0 +1,62 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.internal.implementation;
  38 +
  39 +import java.lang.annotation.ElementType;
  40 +import java.lang.annotation.Retention;
  41 +import java.lang.annotation.RetentionPolicy;
  42 +import java.lang.annotation.Target;
  43 +
  44 +import javax.inject.Qualifier;
  45 +
  46 +import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent;
  47 +import br.gov.frameworkdemoiselle.management.GenericNotification;
  48 +
  49 +/**
  50 + *
  51 + * Enables {@link ManagementNotificationEvent} observers to trigger only with notifications
  52 + * of the base type {@link GenericNotification}.
  53 + *
  54 + * @author SERPRO
  55 + *
  56 + */
  57 +@Qualifier
  58 +@Retention(RetentionPolicy.RUNTIME)
  59 +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})
  60 +public @interface Generic {
  61 +
  62 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ManagedType.java 0 → 100644
@@ -0,0 +1,388 @@ @@ -0,0 +1,388 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.internal.implementation;
  38 +
  39 +import java.lang.annotation.Annotation;
  40 +import java.lang.reflect.Field;
  41 +import java.lang.reflect.Method;
  42 +import java.util.ArrayList;
  43 +import java.util.Locale;
  44 +import java.util.TreeMap;
  45 +
  46 +import javax.inject.Qualifier;
  47 +
  48 +import br.gov.frameworkdemoiselle.DemoiselleException;
  49 +import br.gov.frameworkdemoiselle.annotation.ManagedOperation;
  50 +import br.gov.frameworkdemoiselle.annotation.ManagedProperty;
  51 +import br.gov.frameworkdemoiselle.annotation.ManagedProperty.ManagedPropertyAccess;
  52 +import br.gov.frameworkdemoiselle.annotation.OperationParameter;
  53 +import br.gov.frameworkdemoiselle.annotation.OperationType;
  54 +import br.gov.frameworkdemoiselle.stereotype.ManagementController;
  55 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
  56 +
  57 +/**
  58 + * <p>Package class containing information about a discovered {@link ManagementController}.</p>
  59 + *
  60 + * <p>Instances if this class are passed to each discovered management extension during bootstrap so they can have
  61 + * enough information to expose all discovered {@link ManagementController}'s to management clients.</p>
  62 + *
  63 + * @author SERPRO
  64 + */
  65 +public class ManagedType {
  66 +
  67 + private Class<?> type;
  68 +
  69 + private Annotation[] qualifiers;
  70 +
  71 + private TreeMap<String, FieldDetail> fields;
  72 +
  73 + private TreeMap<String, MethodDetail> operationMethods;
  74 +
  75 + private ResourceBundle bundle;
  76 +
  77 + private String description;
  78 +
  79 + public ManagedType(Class<?> type) {
  80 + bundle = new ResourceBundle("demoiselle-core-bundle",Locale.getDefault());
  81 +
  82 + if (type == null) {
  83 + throw new DemoiselleException(bundle.getString("management-null-class-defined"));
  84 + }
  85 + if (!type.isAnnotationPresent(ManagementController.class)) {
  86 + throw new DemoiselleException(bundle.getString("management-no-annotation-found", type.getCanonicalName()));
  87 + }
  88 +
  89 + this.type = type;
  90 + fields = new TreeMap<String, FieldDetail>();
  91 + operationMethods = new TreeMap<String, MethodDetail>();
  92 + this.description = type.getAnnotation(ManagementController.class).description();
  93 + this.qualifiers = getQualifierAnnotations(type);
  94 +
  95 + initialize();
  96 + }
  97 +
  98 + public Class<?> getType() {
  99 + return type;
  100 + }
  101 +
  102 + public String getDescription() {
  103 + return description;
  104 + }
  105 +
  106 + public TreeMap<String, FieldDetail> getFields() {
  107 + return fields;
  108 + }
  109 +
  110 + public TreeMap<String, MethodDetail> getOperationMethods() {
  111 + return operationMethods;
  112 + }
  113 +
  114 + /**
  115 + * <p>Return a (possibly empty) list of all qualifiers this type have. Qualifiers
  116 + * are any annotations marked as {@link Qualifier}.</p>
  117 + *
  118 + * <p>This method returns the true list of qualifiers. If implementators change this list, it will
  119 + * affect future calls of this method. This is so that resources can be spared by not creating many instances of this list.</p>
  120 + *
  121 + */
  122 + public Annotation[] getQualifiers(){
  123 + return this.qualifiers;
  124 + }
  125 +
  126 + private void initialize() {
  127 + // Para cada atributo verifica se ele está anotado com ManagedProperty e extrai as informações dele (método get, set e
  128 + // descrição do atributo).
  129 + Field[] fields = type.getDeclaredFields();
  130 + if (fields != null) {
  131 + for (Field field : fields) {
  132 + if (field.isAnnotationPresent(ManagedProperty.class)) {
  133 + // Obtém os métodos GET e SET para esta propriedade
  134 + Method getterMethod = getGetterMethod(field);
  135 + Method setterMethod = getSetterMethod(field);
  136 + if (getterMethod == null && setterMethod == null) {
  137 + throw new DemoiselleException(bundle.getString("management-invalid-property-no-getter-setter",
  138 + type.getSimpleName(), field.getName()));
  139 + } else if ((getterMethod != null && getterMethod.isAnnotationPresent(ManagedOperation.class))
  140 + || (setterMethod != null && setterMethod.isAnnotationPresent(ManagedOperation.class))) {
  141 + throw new DemoiselleException(bundle.getString("management-invalid-property-as-operation",
  142 + type.getSimpleName()));
  143 + }
  144 +
  145 + String propertyDescription = field.getAnnotation(ManagedProperty.class).description();
  146 +
  147 + this.fields.put(field.getName(), new FieldDetail(field, propertyDescription, getterMethod,
  148 + setterMethod));
  149 + }
  150 + }
  151 + }
  152 +
  153 + // Para cada metodo verifica se ele está anotado com ManagedOperation e cria um MBeanOperationInfo para ele.
  154 + Method[] methodList = type.getMethods();
  155 + if (methodList != null) {
  156 + for (Method method : methodList) {
  157 + ManagedOperation opAnnotation = method.getAnnotation(ManagedOperation.class);
  158 +
  159 + if (opAnnotation != null) {
  160 + // Lemos as informações sobre o método e criamos uma instância
  161 + // de MethodDetail para representar este método como uma
  162 + // operação.
  163 +
  164 + Class<?>[] parameterTypes = method.getParameterTypes();
  165 + Annotation[][] parameterAnnotations = method.getParameterAnnotations();
  166 + ParameterDetail[] parameterDetails = new ParameterDetail[parameterTypes.length];
  167 + OperationType operationType = opAnnotation.type();
  168 +
  169 + for (int i = 0; i < parameterTypes.length; i++) {
  170 + OperationParameter paramAnnotation = null;
  171 + for (Annotation annotation : parameterAnnotations[i]) {
  172 + if (annotation.annotationType() == OperationParameter.class) {
  173 + paramAnnotation = (OperationParameter) annotation;
  174 + break;
  175 + }
  176 + }
  177 +
  178 + String name = paramAnnotation != null ? paramAnnotation.name() : ("arg" + i);
  179 + String description = paramAnnotation != null ? paramAnnotation.description() : null;
  180 +
  181 + parameterDetails[i] = new ParameterDetail(parameterTypes[i], name, description);
  182 + }
  183 +
  184 + // Com todas as informações, criamos nossa instância de MethodDetail e
  185 + // acrescentamos na lista de todas as operações.
  186 + MethodDetail detail = new MethodDetail(method, opAnnotation.description(), operationType, parameterDetails);
  187 + operationMethods.put(method.getName(), detail);
  188 + }
  189 + }
  190 + }
  191 + }
  192 +
  193 + /**
  194 + * Returns the public getter method for a given field, or <code>null</code> if no getter method can be found.
  195 + */
  196 + private Method getGetterMethod(Field field) {
  197 + StringBuffer getterMethodName = new StringBuffer()
  198 + .append("get")
  199 + .append(field.getName().substring(0, 1).toUpperCase())
  200 + .append(field.getName().substring(1));
  201 +
  202 + //Se propriedade está anotada como WRITE-ONLY, ignora essa etapa.
  203 + ManagedProperty annotation = field.getAnnotation(ManagedProperty.class);
  204 + if (annotation.accessLevel() == ManagedPropertyAccess.WRITE_ONLY){
  205 + return null;
  206 + }
  207 +
  208 + Method getterMethod;
  209 +
  210 + try {
  211 + getterMethod = type.getMethod(getterMethodName.toString());
  212 + } catch (Exception e) {
  213 + getterMethod = null;
  214 + }
  215 +
  216 + // Se atributo for boolean, procura método getter no formato "isAttribute".
  217 + if (getterMethod == null
  218 + && (Boolean.TYPE.isAssignableFrom(field.getType()) || Boolean.class.isAssignableFrom(field.getType()))) {
  219 + // Boolean.TYPE representa o tipo primitivo "boolean", Boolean.class é a classe wrapper.
  220 + getterMethodName = new StringBuffer()
  221 + .append("is")
  222 + .append(field.getName().substring(0, 1).toUpperCase())
  223 + .append(field.getName().substring(1).toUpperCase());
  224 +
  225 + try {
  226 + getterMethod = type.getMethod(getterMethodName.toString());
  227 + } catch (Exception e) {
  228 + getterMethod = null;
  229 + }
  230 + }
  231 +
  232 + return getterMethod;
  233 + }
  234 +
  235 + /**
  236 + * Returns the public setter method for a given field, or <code>null</code> if no setter method can be found.
  237 + */
  238 + private Method getSetterMethod(Field field) {
  239 +
  240 + //Se propriedade está anotada como READ-ONLY, ignora essa etapa.
  241 + ManagedProperty annotation = field.getAnnotation(ManagedProperty.class);
  242 + if (annotation.accessLevel() == ManagedPropertyAccess.READ_ONLY){
  243 + return null;
  244 + }
  245 +
  246 + StringBuffer setterMethodName = new StringBuffer()
  247 + .append("set")
  248 + .append(field.getName().substring(0, 1).toUpperCase())
  249 + .append(field.getName().substring(1));
  250 +
  251 + Method setterMethod;
  252 +
  253 + try {
  254 + setterMethod = type.getMethod(setterMethodName.toString() , field.getType());
  255 + } catch (Exception e) {
  256 + setterMethod = null;
  257 + }
  258 +
  259 + return setterMethod;
  260 + }
  261 +
  262 + /**
  263 + * Indicates another {@link ManagedType} represents the same {@link Class} as this one. This method also supports a
  264 + * {@link Class} as a parameter, in this case it will return <code>true</code> if the passed class is exactly the
  265 + * same Java class represented by this {@link ManagedType}.
  266 + */
  267 + @Override
  268 + public boolean equals(Object other) {
  269 + if (other == null) {
  270 + return false;
  271 + }
  272 +
  273 + return ((ManagedType) other).getType().getCanonicalName().equals(this.getType().getCanonicalName());
  274 + }
  275 +
  276 + private synchronized Annotation[] getQualifierAnnotations(Class<?> beanClass){
  277 + Annotation[] annotations = beanClass.getAnnotations();
  278 + ArrayList<Annotation> qualifiers = new ArrayList<Annotation>(annotations.length);
  279 +
  280 + for (int i=0; i<annotations.length; i++){
  281 + if (annotations[i].annotationType().getAnnotation(Qualifier.class) != null){
  282 + qualifiers.add(annotations[i]);
  283 + }
  284 + }
  285 +
  286 + return qualifiers.toArray(new Annotation[0]);
  287 + }
  288 +
  289 + public final class FieldDetail {
  290 +
  291 + private final Field field;
  292 +
  293 + private final String description;
  294 +
  295 + private Method getterMethod;
  296 +
  297 + private Method setterMethod;
  298 +
  299 + public FieldDetail(Field field, String description, Method getterMethod, Method setterMethod) {
  300 + super();
  301 + this.field = field;
  302 + this.description = description;
  303 + this.getterMethod = getterMethod;
  304 + this.setterMethod = setterMethod;
  305 + }
  306 +
  307 + public Field getField() {
  308 + return field;
  309 + }
  310 +
  311 + public String getDescription() {
  312 + return description;
  313 + }
  314 +
  315 + public Method getGetterMethod() {
  316 + return getterMethod;
  317 + }
  318 +
  319 + public Method getSetterMethod() {
  320 + return setterMethod;
  321 + }
  322 +
  323 + }
  324 +
  325 + public final class MethodDetail {
  326 +
  327 + private final Method method;
  328 +
  329 + private final ParameterDetail[] parameterTypers;
  330 +
  331 + private final String description;
  332 +
  333 + private final OperationType type;
  334 +
  335 + public MethodDetail(Method method, String description, OperationType type,ParameterDetail[] parameterTypers) {
  336 + super();
  337 + this.method = method;
  338 + this.description = description;
  339 + this.type = type;
  340 + this.parameterTypers = parameterTypers;
  341 + }
  342 +
  343 + public Method getMethod() {
  344 + return method;
  345 + }
  346 +
  347 + public ParameterDetail[] getParameterTypers() {
  348 + return parameterTypers;
  349 + }
  350 +
  351 + public String getDescription() {
  352 + return description;
  353 + }
  354 +
  355 + public OperationType getType() {
  356 + return type;
  357 + }
  358 +
  359 + }
  360 +
  361 + public final class ParameterDetail {
  362 +
  363 + private final Class<?> parameterType;
  364 +
  365 + private final String parameterName;
  366 +
  367 + private final String parameterDescription;
  368 +
  369 + public ParameterDetail(Class<?> parameterType, String parameterName, String parameterDescription) {
  370 + super();
  371 + this.parameterType = parameterType;
  372 + this.parameterName = parameterName;
  373 + this.parameterDescription = parameterDescription;
  374 + }
  375 +
  376 + public Class<?> getParameterType() {
  377 + return parameterType;
  378 + }
  379 +
  380 + public String getParameterName() {
  381 + return parameterName;
  382 + }
  383 +
  384 + public String getParameterDescription() {
  385 + return parameterDescription;
  386 + }
  387 + }
  388 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/Management.java 0 → 100644
@@ -0,0 +1,394 @@ @@ -0,0 +1,394 @@
  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.lang.reflect.Method;
  41 +import java.util.ArrayList;
  42 +import java.util.Collection;
  43 +import java.util.List;
  44 +import java.util.Set;
  45 +
  46 +import javax.enterprise.context.ApplicationScoped;
  47 +import javax.inject.Inject;
  48 +import javax.validation.ConstraintViolation;
  49 +import javax.validation.ConstraintViolationException;
  50 +import javax.validation.Validation;
  51 +import javax.validation.ValidationException;
  52 +import javax.validation.Validator;
  53 +
  54 +import org.slf4j.Logger;
  55 +
  56 +import br.gov.frameworkdemoiselle.annotation.ManagedProperty;
  57 +import br.gov.frameworkdemoiselle.annotation.Name;
  58 +import br.gov.frameworkdemoiselle.context.RequestContext;
  59 +import br.gov.frameworkdemoiselle.context.SessionContext;
  60 +import br.gov.frameworkdemoiselle.context.ViewContext;
  61 +import br.gov.frameworkdemoiselle.internal.implementation.ManagedType;
  62 +import br.gov.frameworkdemoiselle.internal.implementation.ManagedType.MethodDetail;
  63 +import br.gov.frameworkdemoiselle.management.AttributeChangeNotification;
  64 +import br.gov.frameworkdemoiselle.management.ManagedAttributeNotFoundException;
  65 +import br.gov.frameworkdemoiselle.management.ManagedInvokationException;
  66 +import br.gov.frameworkdemoiselle.management.ManagementExtension;
  67 +import br.gov.frameworkdemoiselle.management.NotificationManager;
  68 +import br.gov.frameworkdemoiselle.stereotype.ManagementController;
  69 +import br.gov.frameworkdemoiselle.util.Beans;
  70 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
  71 +
  72 +/**
  73 + * Central class used by management extensions to obtain information, access properties and call operations over
  74 + * discovered {@link ManagementController} classes.
  75 + *
  76 + * @author SERPRO
  77 + */
  78 +@ApplicationScoped
  79 +public class Management implements Serializable {
  80 +
  81 + private static final long serialVersionUID = 1L;
  82 +
  83 + @Inject
  84 + private Logger logger;
  85 +
  86 + @Inject
  87 + @Name("demoiselle-core-bundle")
  88 + private ResourceBundle bundle;
  89 +
  90 + private final List<ManagedType> managedTypes = new ArrayList<ManagedType>();
  91 +
  92 + private Validator validator;
  93 +
  94 + public void addManagedType(ManagedType managedType) {
  95 + managedTypes.add(managedType);
  96 + logger.debug(bundle.getString("management-debug-registering-managed-type", managedType.getType()
  97 + .getCanonicalName()));
  98 + }
  99 +
  100 + /**
  101 + * @return List all discovered {@link ManagementController} classes. The returned list is a shallow copy of the
  102 + * internal list, so you are free to modify it. TODO precisamos desse clone na lista?
  103 + */
  104 + public List<ManagedType> getManagedTypes() {
  105 + ArrayList<ManagedType> cloneList = new ArrayList<ManagedType>();
  106 + cloneList.addAll(managedTypes);
  107 + return cloneList;
  108 + }
  109 +
  110 + /**
  111 + * <p>
  112 + * Invoke an operation over a {@link ManagementController}.
  113 + * </p>
  114 + * <p>
  115 + * This method is not thread-safe, it's the user's responsibility to make the operations of the managed type
  116 + * synchronized if necessary.
  117 + * </p>
  118 + *
  119 + * @param managedType
  120 + * A type annotated with {@link ManagementController}. This method will create an (or obtain an already
  121 + * created) instance of this type and invoke the operation over it.
  122 + * @param actionName
  123 + * Name of method to be invoked, the type must have this operation on it's list
  124 + * @param params
  125 + * List of values for the operation parameters. Can be <code>null</code> if the operation require no
  126 + * parameters.
  127 + * @return The return value of the original invoked operation. Methods of return type <code>void</code> will return
  128 + * the {@link Void} type.
  129 + * @throws ManagedInvokationException
  130 + * In case the operation doesn't exist or have a different signature
  131 + */
  132 + public Object invoke(ManagedType managedType, String actionName, Object[] params) {
  133 + if (managedTypes.contains(managedType)) {
  134 + activateContexts(managedType.getType());
  135 +
  136 + try {
  137 + Object delegate = Beans.getReference(managedType.getType() , managedType.getQualifiers());
  138 + MethodDetail method = managedType.getOperationMethods().get(actionName);
  139 +
  140 + if (method != null) {
  141 + try {
  142 + logger.debug(bundle.getString("management-debug-invoking-operation", actionName, managedType
  143 + .getType().getCanonicalName()));
  144 + return method.getMethod().invoke(delegate, params);
  145 + } catch (Exception e) {
  146 + throw new ManagedInvokationException(bundle.getString("management-invoke-error", actionName), e);
  147 + }
  148 + } else {
  149 + throw new ManagedInvokationException(bundle.getString("management-invoke-error", actionName));
  150 + }
  151 + } finally {
  152 + deactivateContexts(managedType.getType());
  153 + }
  154 + } else {
  155 + throw new ManagedInvokationException(bundle.getString("management-type-not-found"));
  156 + }
  157 + }
  158 +
  159 + /**
  160 + * <p>
  161 + * Retrieve the current value of a property from a managed type. Properties are attributes annotated with
  162 + * {@link ManagedProperty}.
  163 + * </p>
  164 + * <p>
  165 + * This method is not thread-safe, it's the user's responsibility to create the property's access methods from the
  166 + * managed type synchronized if necessary.
  167 + * </p>
  168 + *
  169 + * @param managedType
  170 + * The type that has the property the client wants to know the value of.
  171 + * @param propertyName
  172 + * The name of the property
  173 + * @return The current value of the property
  174 + * @throws ManagedAttributeNotFoundException If the given property doesn't exist or there was a problem trying to read the property value.
  175 + * @throws ManagedInvokationException If there was an error trying to invoke the getter method to read the propery value.
  176 + */
  177 + public Object getProperty(ManagedType managedType, String propertyName) {
  178 +
  179 + if (managedTypes.contains(managedType)) {
  180 + Method getterMethod = managedType.getFields().get(propertyName).getGetterMethod();
  181 +
  182 + if (getterMethod != null) {
  183 + logger.debug(bundle.getString("management-debug-acessing-property", getterMethod.getName(), managedType
  184 + .getType().getCanonicalName()));
  185 +
  186 + activateContexts(managedType.getType());
  187 +
  188 + try {
  189 + Object delegate = Beans.getReference(managedType.getType() , managedType.getQualifiers());
  190 +
  191 + return getterMethod.invoke(delegate, (Object[]) null);
  192 + } catch (Exception e) {
  193 + throw new ManagedInvokationException(bundle.getString("management-invoke-error", getterMethod.getName()),
  194 + e);
  195 + } finally {
  196 + deactivateContexts(managedType.getType());
  197 + }
  198 + } else {
  199 + throw new ManagedAttributeNotFoundException(bundle.getString("management-read-value-error", propertyName));
  200 + }
  201 + } else {
  202 + throw new ManagedInvokationException(bundle.getString("management-type-not-found"));
  203 + }
  204 + }
  205 +
  206 + /**
  207 + * <p>
  208 + * Sets a new value for a property contained inside a managed type. A property is an attribute annotated with
  209 + * {@link ManagedProperty}.
  210 + * </p>
  211 + * <p>
  212 + * This method is not thread-safe, it's the user's responsibility to create the property's access methods from the
  213 + * managed type synchronized if necessary.
  214 + * </p>
  215 + *
  216 + * @param managedType
  217 + * The type that has access to the property
  218 + * @param propertyName
  219 + * The name of the property
  220 + * @param newValue
  221 + * The new value of the property
  222 + * @throws ManagedInvokationException If there was an error trying to call the setter method for this property.
  223 + * @throws ManagedAttributeNotFoundException If the giver property doesn't exist or could'n be written to.
  224 + * @throws ConstraintViolationException If the property defined one or more validation constraints and setting this value violates some of those constraints.
  225 + */
  226 + @SuppressWarnings("unchecked")
  227 + public void setProperty(ManagedType managedType, String propertyName, Object newValue) {
  228 +
  229 + if (managedTypes.contains(managedType)) {
  230 + // Procura o método set do atributo em questão
  231 + Method method = managedType.getFields().get(propertyName).getSetterMethod();
  232 + if (method != null) {
  233 + logger.debug(bundle.getString("management-debug-setting-property", method.getName(), managedType
  234 + .getType().getCanonicalName()));
  235 +
  236 + activateContexts(managedType.getType());
  237 + try {
  238 + // Obtém uma instância da classe gerenciada, lembrando que
  239 + // classes
  240 + // anotadas com @ManagementController são sempre singletons.
  241 + Object delegate = Beans.getReference(managedType.getType() , managedType.getQualifiers() );
  242 +
  243 + // Se houver um validador anexado à propriedade alterada, executa o validador sobre
  244 + // o novo valor.
  245 + Validator validator = getDefaultValidator();
  246 + if (validator != null) {
  247 + Set<?> violations = validator.validateValue(managedType.getType(), propertyName, newValue);
  248 + if (violations.size() > 0) {
  249 + StringBuffer errorBuffer = new StringBuffer();
  250 + for (Object objectViolation : violations) {
  251 + ConstraintViolation<?> violation = (ConstraintViolation<?>) objectViolation;
  252 + errorBuffer.append(violation.getMessage()).append('\r').append('\n');
  253 + }
  254 +
  255 + if (errorBuffer.length() > 0) {
  256 + errorBuffer.insert(0, "\r\n");
  257 + errorBuffer.insert(errorBuffer.length(), "\r\n");
  258 + }
  259 +
  260 + throw new ConstraintViolationException(bundle.getString("management-validation-constraint-violation"
  261 + , managedType.getType().getCanonicalName(), propertyName, errorBuffer.toString())
  262 + , (Set<ConstraintViolation<?>>) violations);
  263 + }
  264 + } else {
  265 + logger.warn(bundle.getString("management-validation-validator-not-found"));
  266 + }
  267 +
  268 + Method getterMethod = managedType.getFields().get(propertyName).getGetterMethod();
  269 + Object oldValue;
  270 + try {
  271 + oldValue = getterMethod.invoke(delegate, (Object[]) null);
  272 + } catch (Exception e) {
  273 + oldValue = null;
  274 + }
  275 +
  276 + method.invoke(delegate, new Object[] { newValue });
  277 +
  278 + // Manda uma notificação de mudança de atributo
  279 + NotificationManager notificationManager = Beans.getReference(NotificationManager.class);
  280 + Class<? extends Object> attributeType = newValue != null ? newValue.getClass() : null;
  281 +
  282 + AttributeChangeNotification notification = new AttributeChangeNotification(bundle.getString(
  283 + "management-notification-attribute-changed", propertyName, managedType.getType()
  284 + .getCanonicalName()), propertyName, attributeType, oldValue, newValue);
  285 + notificationManager.sendNotification(notification);
  286 +
  287 + } catch (ConstraintViolationException ce) {
  288 + throw ce;
  289 + } catch (Exception e) {
  290 + throw new ManagedInvokationException(bundle.getString("management-invoke-error", method.getName()), e);
  291 + } finally {
  292 + deactivateContexts(managedType.getType());
  293 + }
  294 +
  295 + } else {
  296 + throw new ManagedAttributeNotFoundException(bundle.getString("management-write-value-error", propertyName));
  297 + }
  298 + } else {
  299 + throw new ManagedInvokationException(bundle.getString("management-type-not-found"));
  300 + }
  301 +
  302 + }
  303 +
  304 + private void activateContexts(Class<?> managedType) {
  305 +
  306 + RequestContext requestContext = Beans.getReference(RequestContext.class);
  307 + ViewContext viewContext = Beans.getReference(ViewContext.class);
  308 + SessionContext sessionContext = Beans.getReference(SessionContext.class);
  309 +
  310 + if (!requestContext.isActive()){
  311 + logger.debug(bundle.getString("management-debug-starting-custom-context",
  312 + requestContext.getClass().getCanonicalName(), managedType.getCanonicalName()));
  313 +
  314 + requestContext.activate();
  315 + }
  316 +
  317 + if (!viewContext.isActive()){
  318 + logger.debug(bundle.getString("management-debug-starting-custom-context",
  319 + viewContext.getClass().getCanonicalName(), managedType.getCanonicalName()));
  320 +
  321 + viewContext.activate();
  322 + }
  323 +
  324 + if (!sessionContext.isActive()){
  325 + logger.debug(bundle.getString("management-debug-starting-custom-context",
  326 + sessionContext.getClass().getCanonicalName(), managedType.getCanonicalName()));
  327 +
  328 + sessionContext.activate();
  329 + }
  330 + }
  331 +
  332 + private void deactivateContexts(Class<?> managedType) {
  333 + RequestContext requestContext = Beans.getReference(RequestContext.class);
  334 + ViewContext viewContext = Beans.getReference(ViewContext.class);
  335 + SessionContext sessionContext = Beans.getReference(SessionContext.class);
  336 +
  337 + if (requestContext.isActive()){
  338 + logger.debug(bundle.getString("management-debug-stoping-custom-context",
  339 + requestContext.getClass().getCanonicalName(), managedType.getCanonicalName()));
  340 +
  341 + requestContext.deactivate();
  342 + }
  343 +
  344 + if (!viewContext.isActive()){
  345 + logger.debug(bundle.getString("management-debug-stoping-custom-context",
  346 + viewContext.getClass().getCanonicalName(), managedType.getCanonicalName()));
  347 +
  348 + viewContext.deactivate();
  349 + }
  350 +
  351 + if (!sessionContext.isActive()){
  352 + logger.debug(bundle.getString("management-debug-stoping-custom-context",
  353 + sessionContext.getClass().getCanonicalName(), managedType.getCanonicalName()));
  354 +
  355 + sessionContext.deactivate();
  356 + }
  357 + }
  358 +
  359 + public void shutdown(Collection<Class<? extends ManagementExtension>> monitoringExtensions) {
  360 + for (Class<? extends ManagementExtension> monitoringExtensionClass : monitoringExtensions) {
  361 +
  362 + ManagementExtension monitoringExtension = Beans.getReference(monitoringExtensionClass);
  363 + monitoringExtension.shutdown(this.getManagedTypes());
  364 + logger.debug(bundle.getString("management-debug-removing-management-extension", monitoringExtension
  365 + .getClass().getCanonicalName()));
  366 +
  367 + }
  368 + }
  369 +
  370 + public void initialize(Collection<Class<? extends ManagementExtension>> monitoringExtensions) {
  371 + for (Class<? extends ManagementExtension> monitoringExtensionClass : monitoringExtensions) {
  372 + ManagementExtension monitoringExtension = Beans.getReference(monitoringExtensionClass);
  373 +
  374 + logger.debug(bundle.getString("management-debug-processing-management-extension", monitoringExtension
  375 + .getClass().getCanonicalName()));
  376 +
  377 + monitoringExtension.initialize(this.getManagedTypes());
  378 + }
  379 + }
  380 +
  381 + private Validator getDefaultValidator() {
  382 + if (validator == null) {
  383 + try {
  384 + this.validator = Validation.buildDefaultValidatorFactory().getValidator();
  385 + } catch (ValidationException e) {
  386 + this.validator = null;
  387 + }
  388 + }
  389 +
  390 + return this.validator;
  391 + }
  392 +
  393 +
  394 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ManagementNotificationEventImpl.java 0 → 100644
@@ -0,0 +1,65 @@ @@ -0,0 +1,65 @@
  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.management.GenericNotification;
  40 +import br.gov.frameworkdemoiselle.management.NotificationManager;
  41 +
  42 +/**
  43 + * Event fired when a notification is sent by {@link NotificationManager}.
  44 + * Implementators can capture this event and be notified when the {@link NotificationManager}
  45 + * sends notifications, so they can pass the notification to the underlying technology.
  46 + *
  47 + * @author SERPRO
  48 + *
  49 + */
  50 +public class ManagementNotificationEventImpl implements br.gov.frameworkdemoiselle.management.ManagementNotificationEvent {
  51 +
  52 + private GenericNotification notification;
  53 +
  54 + public ManagementNotificationEventImpl(GenericNotification notification){
  55 + this.notification = notification;
  56 + }
  57 +
  58 + public GenericNotification getNotification() {
  59 + return notification;
  60 + }
  61 +
  62 + public void setNotification(GenericNotification notification) {
  63 + this.notification = notification;
  64 + }
  65 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationManagerImpl.java
@@ -42,9 +42,6 @@ import javax.enterprise.event.Event; @@ -42,9 +42,6 @@ import javax.enterprise.event.Event;
42 import javax.enterprise.util.AnnotationLiteral; 42 import javax.enterprise.util.AnnotationLiteral;
43 import javax.inject.Inject; 43 import javax.inject.Inject;
44 44
45 -import br.gov.frameworkdemoiselle.internal.management.ManagementNotificationEventImpl;  
46 -import br.gov.frameworkdemoiselle.internal.management.qualifier.AttributeChange;  
47 -import br.gov.frameworkdemoiselle.internal.management.qualifier.Generic;  
48 import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; 45 import br.gov.frameworkdemoiselle.management.AttributeChangeNotification;
49 import br.gov.frameworkdemoiselle.management.GenericNotification; 46 import br.gov.frameworkdemoiselle.management.GenericNotification;
50 import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent; 47 import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent;
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/ManagedType.java
@@ -1,388 +0,0 @@ @@ -1,388 +0,0 @@
1 -/*  
2 - * Demoiselle Framework  
3 - * Copyright (C) 2010 SERPRO  
4 - * ----------------------------------------------------------------------------  
5 - * This file is part of Demoiselle Framework.  
6 - *  
7 - * Demoiselle Framework is free software; you can redistribute it and/or  
8 - * modify it under the terms of the GNU Lesser General Public License version 3  
9 - * as published by the Free Software Foundation.  
10 - *  
11 - * This program is distributed in the hope that it will be useful,  
12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of  
13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
14 - * GNU General Public License for more details.  
15 - *  
16 - * You should have received a copy of the GNU Lesser General Public License version 3  
17 - * along with this program; if not, see <http://www.gnu.org/licenses/>  
18 - * or write to the Free Software Foundation, Inc., 51 Franklin Street,  
19 - * Fifth Floor, Boston, MA 02110-1301, USA.  
20 - * ----------------------------------------------------------------------------  
21 - * Este arquivo é parte do Framework Demoiselle.  
22 - *  
23 - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou  
24 - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação  
25 - * do Software Livre (FSF).  
26 - *  
27 - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA  
28 - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou  
29 - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português  
30 - * para maiores detalhes.  
31 - *  
32 - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título  
33 - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>  
34 - * ou escreva para a Fundação do Software Livre (FSF) Inc.,  
35 - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.  
36 - */  
37 -package br.gov.frameworkdemoiselle.internal.management;  
38 -  
39 -import java.lang.annotation.Annotation;  
40 -import java.lang.reflect.Field;  
41 -import java.lang.reflect.Method;  
42 -import java.util.ArrayList;  
43 -import java.util.Locale;  
44 -import java.util.TreeMap;  
45 -  
46 -import javax.inject.Qualifier;  
47 -  
48 -import br.gov.frameworkdemoiselle.DemoiselleException;  
49 -import br.gov.frameworkdemoiselle.annotation.ManagedOperation;  
50 -import br.gov.frameworkdemoiselle.annotation.ManagedProperty;  
51 -import br.gov.frameworkdemoiselle.annotation.ManagedProperty.ManagedPropertyAccess;  
52 -import br.gov.frameworkdemoiselle.annotation.OperationParameter;  
53 -import br.gov.frameworkdemoiselle.annotation.OperationType;  
54 -import br.gov.frameworkdemoiselle.stereotype.ManagementController;  
55 -import br.gov.frameworkdemoiselle.util.ResourceBundle;  
56 -  
57 -/**  
58 - * <p>Package class containing information about a discovered {@link ManagementController}.</p>  
59 - *  
60 - * <p>Instances if this class are passed to each discovered management extension during bootstrap so they can have  
61 - * enough information to expose all discovered {@link ManagementController}'s to management clients.</p>  
62 - *  
63 - * @author SERPRO  
64 - */  
65 -public class ManagedType {  
66 -  
67 - private Class<?> type;  
68 -  
69 - private Annotation[] qualifiers;  
70 -  
71 - private TreeMap<String, FieldDetail> fields;  
72 -  
73 - private TreeMap<String, MethodDetail> operationMethods;  
74 -  
75 - private ResourceBundle bundle;  
76 -  
77 - private String description;  
78 -  
79 - public ManagedType(Class<?> type) {  
80 - bundle = new ResourceBundle("demoiselle-core-bundle",Locale.getDefault());  
81 -  
82 - if (type == null) {  
83 - throw new DemoiselleException(bundle.getString("management-null-class-defined"));  
84 - }  
85 - if (!type.isAnnotationPresent(ManagementController.class)) {  
86 - throw new DemoiselleException(bundle.getString("management-no-annotation-found", type.getCanonicalName()));  
87 - }  
88 -  
89 - this.type = type;  
90 - fields = new TreeMap<String, FieldDetail>();  
91 - operationMethods = new TreeMap<String, MethodDetail>();  
92 - this.description = type.getAnnotation(ManagementController.class).description();  
93 - this.qualifiers = getQualifierAnnotations(type);  
94 -  
95 - initialize();  
96 - }  
97 -  
98 - public Class<?> getType() {  
99 - return type;  
100 - }  
101 -  
102 - public String getDescription() {  
103 - return description;  
104 - }  
105 -  
106 - public TreeMap<String, FieldDetail> getFields() {  
107 - return fields;  
108 - }  
109 -  
110 - public TreeMap<String, MethodDetail> getOperationMethods() {  
111 - return operationMethods;  
112 - }  
113 -  
114 - /**  
115 - * <p>Return a (possibly empty) list of all qualifiers this type have. Qualifiers  
116 - * are any annotations marked as {@link Qualifier}.</p>  
117 - *  
118 - * <p>This method returns the true list of qualifiers. If implementators change this list, it will  
119 - * affect future calls of this method. This is so that resources can be spared by not creating many instances of this list.</p>  
120 - *  
121 - */  
122 - public Annotation[] getQualifiers(){  
123 - return this.qualifiers;  
124 - }  
125 -  
126 - private void initialize() {  
127 - // Para cada atributo verifica se ele está anotado com ManagedProperty e extrai as informações dele (método get, set e  
128 - // descrição do atributo).  
129 - Field[] fields = type.getDeclaredFields();  
130 - if (fields != null) {  
131 - for (Field field : fields) {  
132 - if (field.isAnnotationPresent(ManagedProperty.class)) {  
133 - // Obtém os métodos GET e SET para esta propriedade  
134 - Method getterMethod = getGetterMethod(field);  
135 - Method setterMethod = getSetterMethod(field);  
136 - if (getterMethod == null && setterMethod == null) {  
137 - throw new DemoiselleException(bundle.getString("management-invalid-property-no-getter-setter",  
138 - type.getSimpleName(), field.getName()));  
139 - } else if ((getterMethod != null && getterMethod.isAnnotationPresent(ManagedOperation.class))  
140 - || (setterMethod != null && setterMethod.isAnnotationPresent(ManagedOperation.class))) {  
141 - throw new DemoiselleException(bundle.getString("management-invalid-property-as-operation",  
142 - type.getSimpleName()));  
143 - }  
144 -  
145 - String propertyDescription = field.getAnnotation(ManagedProperty.class).description();  
146 -  
147 - this.fields.put(field.getName(), new FieldDetail(field, propertyDescription, getterMethod,  
148 - setterMethod));  
149 - }  
150 - }  
151 - }  
152 -  
153 - // Para cada metodo verifica se ele está anotado com ManagedOperation e cria um MBeanOperationInfo para ele.  
154 - Method[] methodList = type.getMethods();  
155 - if (methodList != null) {  
156 - for (Method method : methodList) {  
157 - ManagedOperation opAnnotation = method.getAnnotation(ManagedOperation.class);  
158 -  
159 - if (opAnnotation != null) {  
160 - // Lemos as informações sobre o método e criamos uma instância  
161 - // de MethodDetail para representar este método como uma  
162 - // operação.  
163 -  
164 - Class<?>[] parameterTypes = method.getParameterTypes();  
165 - Annotation[][] parameterAnnotations = method.getParameterAnnotations();  
166 - ParameterDetail[] parameterDetails = new ParameterDetail[parameterTypes.length];  
167 - OperationType operationType = opAnnotation.type();  
168 -  
169 - for (int i = 0; i < parameterTypes.length; i++) {  
170 - OperationParameter paramAnnotation = null;  
171 - for (Annotation annotation : parameterAnnotations[i]) {  
172 - if (annotation.annotationType() == OperationParameter.class) {  
173 - paramAnnotation = (OperationParameter) annotation;  
174 - break;  
175 - }  
176 - }  
177 -  
178 - String name = paramAnnotation != null ? paramAnnotation.name() : ("arg" + i);  
179 - String description = paramAnnotation != null ? paramAnnotation.description() : null;  
180 -  
181 - parameterDetails[i] = new ParameterDetail(parameterTypes[i], name, description);  
182 - }  
183 -  
184 - // Com todas as informações, criamos nossa instância de MethodDetail e  
185 - // acrescentamos na lista de todas as operações.  
186 - MethodDetail detail = new MethodDetail(method, opAnnotation.description(), operationType, parameterDetails);  
187 - operationMethods.put(method.getName(), detail);  
188 - }  
189 - }  
190 - }  
191 - }  
192 -  
193 - /**  
194 - * Returns the public getter method for a given field, or <code>null</code> if no getter method can be found.  
195 - */  
196 - private Method getGetterMethod(Field field) {  
197 - StringBuffer getterMethodName = new StringBuffer()  
198 - .append("get")  
199 - .append(field.getName().substring(0, 1).toUpperCase())  
200 - .append(field.getName().substring(1));  
201 -  
202 - //Se propriedade está anotada como WRITE-ONLY, ignora essa etapa.  
203 - ManagedProperty annotation = field.getAnnotation(ManagedProperty.class);  
204 - if (annotation.accessLevel() == ManagedPropertyAccess.WRITE_ONLY){  
205 - return null;  
206 - }  
207 -  
208 - Method getterMethod;  
209 -  
210 - try {  
211 - getterMethod = type.getMethod(getterMethodName.toString());  
212 - } catch (Exception e) {  
213 - getterMethod = null;  
214 - }  
215 -  
216 - // Se atributo for boolean, procura método getter no formato "isAttribute".  
217 - if (getterMethod == null  
218 - && (Boolean.TYPE.isAssignableFrom(field.getType()) || Boolean.class.isAssignableFrom(field.getType()))) {  
219 - // Boolean.TYPE representa o tipo primitivo "boolean", Boolean.class é a classe wrapper.  
220 - getterMethodName = new StringBuffer()  
221 - .append("is")  
222 - .append(field.getName().substring(0, 1).toUpperCase())  
223 - .append(field.getName().substring(1).toUpperCase());  
224 -  
225 - try {  
226 - getterMethod = type.getMethod(getterMethodName.toString());  
227 - } catch (Exception e) {  
228 - getterMethod = null;  
229 - }  
230 - }  
231 -  
232 - return getterMethod;  
233 - }  
234 -  
235 - /**  
236 - * Returns the public setter method for a given field, or <code>null</code> if no setter method can be found.  
237 - */  
238 - private Method getSetterMethod(Field field) {  
239 -  
240 - //Se propriedade está anotada como READ-ONLY, ignora essa etapa.  
241 - ManagedProperty annotation = field.getAnnotation(ManagedProperty.class);  
242 - if (annotation.accessLevel() == ManagedPropertyAccess.READ_ONLY){  
243 - return null;  
244 - }  
245 -  
246 - StringBuffer setterMethodName = new StringBuffer()  
247 - .append("set")  
248 - .append(field.getName().substring(0, 1).toUpperCase())  
249 - .append(field.getName().substring(1));  
250 -  
251 - Method setterMethod;  
252 -  
253 - try {  
254 - setterMethod = type.getMethod(setterMethodName.toString() , field.getType());  
255 - } catch (Exception e) {  
256 - setterMethod = null;  
257 - }  
258 -  
259 - return setterMethod;  
260 - }  
261 -  
262 - /**  
263 - * Indicates another {@link ManagedType} represents the same {@link Class} as this one. This method also supports a  
264 - * {@link Class} as a parameter, in this case it will return <code>true</code> if the passed class is exactly the  
265 - * same Java class represented by this {@link ManagedType}.  
266 - */  
267 - @Override  
268 - public boolean equals(Object other) {  
269 - if (other == null) {  
270 - return false;  
271 - }  
272 -  
273 - return ((ManagedType) other).getType().getCanonicalName().equals(this.getType().getCanonicalName());  
274 - }  
275 -  
276 - private synchronized Annotation[] getQualifierAnnotations(Class<?> beanClass){  
277 - Annotation[] annotations = beanClass.getAnnotations();  
278 - ArrayList<Annotation> qualifiers = new ArrayList<Annotation>(annotations.length);  
279 -  
280 - for (int i=0; i<annotations.length; i++){  
281 - if (annotations[i].annotationType().getAnnotation(Qualifier.class) != null){  
282 - qualifiers.add(annotations[i]);  
283 - }  
284 - }  
285 -  
286 - return qualifiers.toArray(new Annotation[0]);  
287 - }  
288 -  
289 - public final class FieldDetail {  
290 -  
291 - private final Field field;  
292 -  
293 - private final String description;  
294 -  
295 - private Method getterMethod;  
296 -  
297 - private Method setterMethod;  
298 -  
299 - public FieldDetail(Field field, String description, Method getterMethod, Method setterMethod) {  
300 - super();  
301 - this.field = field;  
302 - this.description = description;  
303 - this.getterMethod = getterMethod;  
304 - this.setterMethod = setterMethod;  
305 - }  
306 -  
307 - public Field getField() {  
308 - return field;  
309 - }  
310 -  
311 - public String getDescription() {  
312 - return description;  
313 - }  
314 -  
315 - public Method getGetterMethod() {  
316 - return getterMethod;  
317 - }  
318 -  
319 - public Method getSetterMethod() {  
320 - return setterMethod;  
321 - }  
322 -  
323 - }  
324 -  
325 - public final class MethodDetail {  
326 -  
327 - private final Method method;  
328 -  
329 - private final ParameterDetail[] parameterTypers;  
330 -  
331 - private final String description;  
332 -  
333 - private final OperationType type;  
334 -  
335 - public MethodDetail(Method method, String description, OperationType type,ParameterDetail[] parameterTypers) {  
336 - super();  
337 - this.method = method;  
338 - this.description = description;  
339 - this.type = type;  
340 - this.parameterTypers = parameterTypers;  
341 - }  
342 -  
343 - public Method getMethod() {  
344 - return method;  
345 - }  
346 -  
347 - public ParameterDetail[] getParameterTypers() {  
348 - return parameterTypers;  
349 - }  
350 -  
351 - public String getDescription() {  
352 - return description;  
353 - }  
354 -  
355 - public OperationType getType() {  
356 - return type;  
357 - }  
358 -  
359 - }  
360 -  
361 - public final class ParameterDetail {  
362 -  
363 - private final Class<?> parameterType;  
364 -  
365 - private final String parameterName;  
366 -  
367 - private final String parameterDescription;  
368 -  
369 - public ParameterDetail(Class<?> parameterType, String parameterName, String parameterDescription) {  
370 - super();  
371 - this.parameterType = parameterType;  
372 - this.parameterName = parameterName;  
373 - this.parameterDescription = parameterDescription;  
374 - }  
375 -  
376 - public Class<?> getParameterType() {  
377 - return parameterType;  
378 - }  
379 -  
380 - public String getParameterName() {  
381 - return parameterName;  
382 - }  
383 -  
384 - public String getParameterDescription() {  
385 - return parameterDescription;  
386 - }  
387 - }  
388 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/Management.java
@@ -1,393 +0,0 @@ @@ -1,393 +0,0 @@
1 -/*  
2 - * Demoiselle Framework  
3 - * Copyright (C) 2010 SERPRO  
4 - * ----------------------------------------------------------------------------  
5 - * This file is part of Demoiselle Framework.  
6 - *  
7 - * Demoiselle Framework is free software; you can redistribute it and/or  
8 - * modify it under the terms of the GNU Lesser General Public License version 3  
9 - * as published by the Free Software Foundation.  
10 - *  
11 - * This program is distributed in the hope that it will be useful,  
12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of  
13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
14 - * GNU General Public License for more details.  
15 - *  
16 - * You should have received a copy of the GNU Lesser General Public License version 3  
17 - * along with this program; if not, see <http://www.gnu.org/licenses/>  
18 - * or write to the Free Software Foundation, Inc., 51 Franklin Street,  
19 - * Fifth Floor, Boston, MA 02110-1301, USA.  
20 - * ----------------------------------------------------------------------------  
21 - * Este arquivo é parte do Framework Demoiselle.  
22 - *  
23 - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou  
24 - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação  
25 - * do Software Livre (FSF).  
26 - *  
27 - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA  
28 - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou  
29 - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português  
30 - * para maiores detalhes.  
31 - *  
32 - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título  
33 - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>  
34 - * ou escreva para a Fundação do Software Livre (FSF) Inc.,  
35 - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.  
36 - */  
37 -package br.gov.frameworkdemoiselle.internal.management;  
38 -  
39 -import java.io.Serializable;  
40 -import java.lang.reflect.Method;  
41 -import java.util.ArrayList;  
42 -import java.util.Collection;  
43 -import java.util.List;  
44 -import java.util.Set;  
45 -  
46 -import javax.enterprise.context.ApplicationScoped;  
47 -import javax.inject.Inject;  
48 -import javax.validation.ConstraintViolation;  
49 -import javax.validation.ConstraintViolationException;  
50 -import javax.validation.Validation;  
51 -import javax.validation.ValidationException;  
52 -import javax.validation.Validator;  
53 -  
54 -import org.slf4j.Logger;  
55 -  
56 -import br.gov.frameworkdemoiselle.annotation.ManagedProperty;  
57 -import br.gov.frameworkdemoiselle.annotation.Name;  
58 -import br.gov.frameworkdemoiselle.context.RequestContext;  
59 -import br.gov.frameworkdemoiselle.context.SessionContext;  
60 -import br.gov.frameworkdemoiselle.context.ViewContext;  
61 -import br.gov.frameworkdemoiselle.internal.management.ManagedType.MethodDetail;  
62 -import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension;  
63 -import br.gov.frameworkdemoiselle.management.AttributeChangeNotification;  
64 -import br.gov.frameworkdemoiselle.management.ManagedAttributeNotFoundException;  
65 -import br.gov.frameworkdemoiselle.management.ManagedInvokationException;  
66 -import br.gov.frameworkdemoiselle.management.NotificationManager;  
67 -import br.gov.frameworkdemoiselle.stereotype.ManagementController;  
68 -import br.gov.frameworkdemoiselle.util.Beans;  
69 -import br.gov.frameworkdemoiselle.util.ResourceBundle;  
70 -  
71 -/**  
72 - * Central class used by management extensions to obtain information, access properties and call operations over  
73 - * discovered {@link ManagementController} classes.  
74 - *  
75 - * @author SERPRO  
76 - */  
77 -@ApplicationScoped  
78 -public class Management implements Serializable {  
79 -  
80 - private static final long serialVersionUID = 1L;  
81 -  
82 - @Inject  
83 - private Logger logger;  
84 -  
85 - @Inject  
86 - @Name("demoiselle-core-bundle")  
87 - private ResourceBundle bundle;  
88 -  
89 - private final List<ManagedType> managedTypes = new ArrayList<ManagedType>();  
90 -  
91 - private Validator validator;  
92 -  
93 - public void addManagedType(ManagedType managedType) {  
94 - managedTypes.add(managedType);  
95 - logger.debug(bundle.getString("management-debug-registering-managed-type", managedType.getType()  
96 - .getCanonicalName()));  
97 - }  
98 -  
99 - /**  
100 - * @return List all discovered {@link ManagementController} classes. The returned list is a shallow copy of the  
101 - * internal list, so you are free to modify it. TODO precisamos desse clone na lista?  
102 - */  
103 - public List<ManagedType> getManagedTypes() {  
104 - ArrayList<ManagedType> cloneList = new ArrayList<ManagedType>();  
105 - cloneList.addAll(managedTypes);  
106 - return cloneList;  
107 - }  
108 -  
109 - /**  
110 - * <p>  
111 - * Invoke an operation over a {@link ManagementController}.  
112 - * </p>  
113 - * <p>  
114 - * This method is not thread-safe, it's the user's responsibility to make the operations of the managed type  
115 - * synchronized if necessary.  
116 - * </p>  
117 - *  
118 - * @param managedType  
119 - * A type annotated with {@link ManagementController}. This method will create an (or obtain an already  
120 - * created) instance of this type and invoke the operation over it.  
121 - * @param actionName  
122 - * Name of method to be invoked, the type must have this operation on it's list  
123 - * @param params  
124 - * List of values for the operation parameters. Can be <code>null</code> if the operation require no  
125 - * parameters.  
126 - * @return The return value of the original invoked operation. Methods of return type <code>void</code> will return  
127 - * the {@link Void} type.  
128 - * @throws ManagedInvokationException  
129 - * In case the operation doesn't exist or have a different signature  
130 - */  
131 - public Object invoke(ManagedType managedType, String actionName, Object[] params) {  
132 - if (managedTypes.contains(managedType)) {  
133 - activateContexts(managedType.getType());  
134 -  
135 - try {  
136 - Object delegate = Beans.getReference(managedType.getType() , managedType.getQualifiers());  
137 - MethodDetail method = managedType.getOperationMethods().get(actionName);  
138 -  
139 - if (method != null) {  
140 - try {  
141 - logger.debug(bundle.getString("management-debug-invoking-operation", actionName, managedType  
142 - .getType().getCanonicalName()));  
143 - return method.getMethod().invoke(delegate, params);  
144 - } catch (Exception e) {  
145 - throw new ManagedInvokationException(bundle.getString("management-invoke-error", actionName), e);  
146 - }  
147 - } else {  
148 - throw new ManagedInvokationException(bundle.getString("management-invoke-error", actionName));  
149 - }  
150 - } finally {  
151 - deactivateContexts(managedType.getType());  
152 - }  
153 - } else {  
154 - throw new ManagedInvokationException(bundle.getString("management-type-not-found"));  
155 - }  
156 - }  
157 -  
158 - /**  
159 - * <p>  
160 - * Retrieve the current value of a property from a managed type. Properties are attributes annotated with  
161 - * {@link ManagedProperty}.  
162 - * </p>  
163 - * <p>  
164 - * This method is not thread-safe, it's the user's responsibility to create the property's access methods from the  
165 - * managed type synchronized if necessary.  
166 - * </p>  
167 - *  
168 - * @param managedType  
169 - * The type that has the property the client wants to know the value of.  
170 - * @param propertyName  
171 - * The name of the property  
172 - * @return The current value of the property  
173 - * @throws ManagedAttributeNotFoundException If the given property doesn't exist or there was a problem trying to read the property value.  
174 - * @throws ManagedInvokationException If there was an error trying to invoke the getter method to read the propery value.  
175 - */  
176 - public Object getProperty(ManagedType managedType, String propertyName) {  
177 -  
178 - if (managedTypes.contains(managedType)) {  
179 - Method getterMethod = managedType.getFields().get(propertyName).getGetterMethod();  
180 -  
181 - if (getterMethod != null) {  
182 - logger.debug(bundle.getString("management-debug-acessing-property", getterMethod.getName(), managedType  
183 - .getType().getCanonicalName()));  
184 -  
185 - activateContexts(managedType.getType());  
186 -  
187 - try {  
188 - Object delegate = Beans.getReference(managedType.getType() , managedType.getQualifiers());  
189 -  
190 - return getterMethod.invoke(delegate, (Object[]) null);  
191 - } catch (Exception e) {  
192 - throw new ManagedInvokationException(bundle.getString("management-invoke-error", getterMethod.getName()),  
193 - e);  
194 - } finally {  
195 - deactivateContexts(managedType.getType());  
196 - }  
197 - } else {  
198 - throw new ManagedAttributeNotFoundException(bundle.getString("management-read-value-error", propertyName));  
199 - }  
200 - } else {  
201 - throw new ManagedInvokationException(bundle.getString("management-type-not-found"));  
202 - }  
203 - }  
204 -  
205 - /**  
206 - * <p>  
207 - * Sets a new value for a property contained inside a managed type. A property is an attribute annotated with  
208 - * {@link ManagedProperty}.  
209 - * </p>  
210 - * <p>  
211 - * This method is not thread-safe, it's the user's responsibility to create the property's access methods from the  
212 - * managed type synchronized if necessary.  
213 - * </p>  
214 - *  
215 - * @param managedType  
216 - * The type that has access to the property  
217 - * @param propertyName  
218 - * The name of the property  
219 - * @param newValue  
220 - * The new value of the property  
221 - * @throws ManagedInvokationException If there was an error trying to call the setter method for this property.  
222 - * @throws ManagedAttributeNotFoundException If the giver property doesn't exist or could'n be written to.  
223 - * @throws ConstraintViolationException If the property defined one or more validation constraints and setting this value violates some of those constraints.  
224 - */  
225 - @SuppressWarnings("unchecked")  
226 - public void setProperty(ManagedType managedType, String propertyName, Object newValue) {  
227 -  
228 - if (managedTypes.contains(managedType)) {  
229 - // Procura o método set do atributo em questão  
230 - Method method = managedType.getFields().get(propertyName).getSetterMethod();  
231 - if (method != null) {  
232 - logger.debug(bundle.getString("management-debug-setting-property", method.getName(), managedType  
233 - .getType().getCanonicalName()));  
234 -  
235 - activateContexts(managedType.getType());  
236 - try {  
237 - // Obtém uma instância da classe gerenciada, lembrando que  
238 - // classes  
239 - // anotadas com @ManagementController são sempre singletons.  
240 - Object delegate = Beans.getReference(managedType.getType() , managedType.getQualifiers() );  
241 -  
242 - // Se houver um validador anexado à propriedade alterada, executa o validador sobre  
243 - // o novo valor.  
244 - Validator validator = getDefaultValidator();  
245 - if (validator != null) {  
246 - Set<?> violations = validator.validateValue(managedType.getType(), propertyName, newValue);  
247 - if (violations.size() > 0) {  
248 - StringBuffer errorBuffer = new StringBuffer();  
249 - for (Object objectViolation : violations) {  
250 - ConstraintViolation<?> violation = (ConstraintViolation<?>) objectViolation;  
251 - errorBuffer.append(violation.getMessage()).append('\r').append('\n');  
252 - }  
253 -  
254 - if (errorBuffer.length() > 0) {  
255 - errorBuffer.insert(0, "\r\n");  
256 - errorBuffer.insert(errorBuffer.length(), "\r\n");  
257 - }  
258 -  
259 - throw new ConstraintViolationException(bundle.getString("management-validation-constraint-violation"  
260 - , managedType.getType().getCanonicalName(), propertyName, errorBuffer.toString())  
261 - , (Set<ConstraintViolation<?>>) violations);  
262 - }  
263 - } else {  
264 - logger.warn(bundle.getString("management-validation-validator-not-found"));  
265 - }  
266 -  
267 - Method getterMethod = managedType.getFields().get(propertyName).getGetterMethod();  
268 - Object oldValue;  
269 - try {  
270 - oldValue = getterMethod.invoke(delegate, (Object[]) null);  
271 - } catch (Exception e) {  
272 - oldValue = null;  
273 - }  
274 -  
275 - method.invoke(delegate, new Object[] { newValue });  
276 -  
277 - // Manda uma notificação de mudança de atributo  
278 - NotificationManager notificationManager = Beans.getReference(NotificationManager.class);  
279 - Class<? extends Object> attributeType = newValue != null ? newValue.getClass() : null;  
280 -  
281 - AttributeChangeNotification notification = new AttributeChangeNotification(bundle.getString(  
282 - "management-notification-attribute-changed", propertyName, managedType.getType()  
283 - .getCanonicalName()), propertyName, attributeType, oldValue, newValue);  
284 - notificationManager.sendNotification(notification);  
285 -  
286 - } catch (ConstraintViolationException ce) {  
287 - throw ce;  
288 - } catch (Exception e) {  
289 - throw new ManagedInvokationException(bundle.getString("management-invoke-error", method.getName()), e);  
290 - } finally {  
291 - deactivateContexts(managedType.getType());  
292 - }  
293 -  
294 - } else {  
295 - throw new ManagedAttributeNotFoundException(bundle.getString("management-write-value-error", propertyName));  
296 - }  
297 - } else {  
298 - throw new ManagedInvokationException(bundle.getString("management-type-not-found"));  
299 - }  
300 -  
301 - }  
302 -  
303 - private void activateContexts(Class<?> managedType) {  
304 -  
305 - RequestContext requestContext = Beans.getReference(RequestContext.class);  
306 - ViewContext viewContext = Beans.getReference(ViewContext.class);  
307 - SessionContext sessionContext = Beans.getReference(SessionContext.class);  
308 -  
309 - if (!requestContext.isActive()){  
310 - logger.debug(bundle.getString("management-debug-starting-custom-context",  
311 - requestContext.getClass().getCanonicalName(), managedType.getCanonicalName()));  
312 -  
313 - requestContext.activate();  
314 - }  
315 -  
316 - if (!viewContext.isActive()){  
317 - logger.debug(bundle.getString("management-debug-starting-custom-context",  
318 - viewContext.getClass().getCanonicalName(), managedType.getCanonicalName()));  
319 -  
320 - viewContext.activate();  
321 - }  
322 -  
323 - if (!sessionContext.isActive()){  
324 - logger.debug(bundle.getString("management-debug-starting-custom-context",  
325 - sessionContext.getClass().getCanonicalName(), managedType.getCanonicalName()));  
326 -  
327 - sessionContext.activate();  
328 - }  
329 - }  
330 -  
331 - private void deactivateContexts(Class<?> managedType) {  
332 - RequestContext requestContext = Beans.getReference(RequestContext.class);  
333 - ViewContext viewContext = Beans.getReference(ViewContext.class);  
334 - SessionContext sessionContext = Beans.getReference(SessionContext.class);  
335 -  
336 - if (requestContext.isActive()){  
337 - logger.debug(bundle.getString("management-debug-stoping-custom-context",  
338 - requestContext.getClass().getCanonicalName(), managedType.getCanonicalName()));  
339 -  
340 - requestContext.deactivate();  
341 - }  
342 -  
343 - if (!viewContext.isActive()){  
344 - logger.debug(bundle.getString("management-debug-stoping-custom-context",  
345 - viewContext.getClass().getCanonicalName(), managedType.getCanonicalName()));  
346 -  
347 - viewContext.deactivate();  
348 - }  
349 -  
350 - if (!sessionContext.isActive()){  
351 - logger.debug(bundle.getString("management-debug-stoping-custom-context",  
352 - sessionContext.getClass().getCanonicalName(), managedType.getCanonicalName()));  
353 -  
354 - sessionContext.deactivate();  
355 - }  
356 - }  
357 -  
358 - public void shutdown(Collection<Class<? extends ManagementExtension>> monitoringExtensions) {  
359 - for (Class<? extends ManagementExtension> monitoringExtensionClass : monitoringExtensions) {  
360 -  
361 - ManagementExtension monitoringExtension = Beans.getReference(monitoringExtensionClass);  
362 - monitoringExtension.shutdown(this.getManagedTypes());  
363 - logger.debug(bundle.getString("management-debug-removing-management-extension", monitoringExtension  
364 - .getClass().getCanonicalName()));  
365 -  
366 - }  
367 - }  
368 -  
369 - public void initialize(Collection<Class<? extends ManagementExtension>> monitoringExtensions) {  
370 - for (Class<? extends ManagementExtension> monitoringExtensionClass : monitoringExtensions) {  
371 - ManagementExtension monitoringExtension = Beans.getReference(monitoringExtensionClass);  
372 -  
373 - logger.debug(bundle.getString("management-debug-processing-management-extension", monitoringExtension  
374 - .getClass().getCanonicalName()));  
375 -  
376 - monitoringExtension.initialize(this.getManagedTypes());  
377 - }  
378 - }  
379 -  
380 - private Validator getDefaultValidator() {  
381 - if (validator == null) {  
382 - try {  
383 - this.validator = Validation.buildDefaultValidatorFactory().getValidator();  
384 - } catch (ValidationException e) {  
385 - this.validator = null;  
386 - }  
387 - }  
388 -  
389 - return this.validator;  
390 - }  
391 -  
392 -  
393 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/ManagementNotificationEventImpl.java
@@ -1,65 +0,0 @@ @@ -1,65 +0,0 @@
1 -/*  
2 - * Demoiselle Framework  
3 - * Copyright (C) 2010 SERPRO  
4 - * ----------------------------------------------------------------------------  
5 - * This file is part of Demoiselle Framework.  
6 - *  
7 - * Demoiselle Framework is free software; you can redistribute it and/or  
8 - * modify it under the terms of the GNU Lesser General Public License version 3  
9 - * as published by the Free Software Foundation.  
10 - *  
11 - * This program is distributed in the hope that it will be useful,  
12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of  
13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
14 - * GNU General Public License for more details.  
15 - *  
16 - * You should have received a copy of the GNU Lesser General Public License version 3  
17 - * along with this program; if not, see <http://www.gnu.org/licenses/>  
18 - * or write to the Free Software Foundation, Inc., 51 Franklin Street,  
19 - * Fifth Floor, Boston, MA 02110-1301, USA.  
20 - * ----------------------------------------------------------------------------  
21 - * Este arquivo é parte do Framework Demoiselle.  
22 - *  
23 - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou  
24 - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação  
25 - * do Software Livre (FSF).  
26 - *  
27 - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA  
28 - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou  
29 - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português  
30 - * para maiores detalhes.  
31 - *  
32 - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título  
33 - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>  
34 - * ou escreva para a Fundação do Software Livre (FSF) Inc.,  
35 - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.  
36 - */  
37 -package br.gov.frameworkdemoiselle.internal.management;  
38 -  
39 -import br.gov.frameworkdemoiselle.management.GenericNotification;  
40 -import br.gov.frameworkdemoiselle.management.NotificationManager;  
41 -  
42 -/**  
43 - * Event fired when a notification is sent by {@link NotificationManager}.  
44 - * Implementators can capture this event and be notified when the {@link NotificationManager}  
45 - * sends notifications, so they can pass the notification to the underlying technology.  
46 - *  
47 - * @author SERPRO  
48 - *  
49 - */  
50 -public class ManagementNotificationEventImpl implements br.gov.frameworkdemoiselle.management.ManagementNotificationEvent {  
51 -  
52 - private GenericNotification notification;  
53 -  
54 - public ManagementNotificationEventImpl(GenericNotification notification){  
55 - this.notification = notification;  
56 - }  
57 -  
58 - public GenericNotification getNotification() {  
59 - return notification;  
60 - }  
61 -  
62 - public void setNotification(GenericNotification notification) {  
63 - this.notification = notification;  
64 - }  
65 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/qualifier/AttributeChange.java
@@ -1,62 +0,0 @@ @@ -1,62 +0,0 @@
1 -/*  
2 - * Demoiselle Framework  
3 - * Copyright (C) 2010 SERPRO  
4 - * ----------------------------------------------------------------------------  
5 - * This file is part of Demoiselle Framework.  
6 - *  
7 - * Demoiselle Framework is free software; you can redistribute it and/or  
8 - * modify it under the terms of the GNU Lesser General Public License version 3  
9 - * as published by the Free Software Foundation.  
10 - *  
11 - * This program is distributed in the hope that it will be useful,  
12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of  
13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
14 - * GNU General Public License for more details.  
15 - *  
16 - * You should have received a copy of the GNU Lesser General Public License version 3  
17 - * along with this program; if not, see <http://www.gnu.org/licenses/>  
18 - * or write to the Free Software Foundation, Inc., 51 Franklin Street,  
19 - * Fifth Floor, Boston, MA 02110-1301, USA.  
20 - * ----------------------------------------------------------------------------  
21 - * Este arquivo é parte do Framework Demoiselle.  
22 - *  
23 - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou  
24 - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação  
25 - * do Software Livre (FSF).  
26 - *  
27 - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA  
28 - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou  
29 - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português  
30 - * para maiores detalhes.  
31 - *  
32 - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título  
33 - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>  
34 - * ou escreva para a Fundação do Software Livre (FSF) Inc.,  
35 - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.  
36 - */  
37 -package br.gov.frameworkdemoiselle.internal.management.qualifier;  
38 -  
39 -import java.lang.annotation.ElementType;  
40 -import java.lang.annotation.Retention;  
41 -import java.lang.annotation.RetentionPolicy;  
42 -import java.lang.annotation.Target;  
43 -  
44 -import javax.inject.Qualifier;  
45 -  
46 -import br.gov.frameworkdemoiselle.management.AttributeChangeNotification;  
47 -import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent;  
48 -  
49 -/**  
50 - *  
51 - * Enables {@link ManagementNotificationEvent} observers to trigger only with notifications  
52 - * of the specialized type {@link AttributeChangeNotification}.  
53 - *  
54 - * @author SERPRO  
55 - *  
56 - */  
57 -@Qualifier  
58 -@Retention(RetentionPolicy.RUNTIME)  
59 -@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})  
60 -public @interface AttributeChange {  
61 -  
62 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/qualifier/Generic.java
@@ -1,62 +0,0 @@ @@ -1,62 +0,0 @@
1 -/*  
2 - * Demoiselle Framework  
3 - * Copyright (C) 2010 SERPRO  
4 - * ----------------------------------------------------------------------------  
5 - * This file is part of Demoiselle Framework.  
6 - *  
7 - * Demoiselle Framework is free software; you can redistribute it and/or  
8 - * modify it under the terms of the GNU Lesser General Public License version 3  
9 - * as published by the Free Software Foundation.  
10 - *  
11 - * This program is distributed in the hope that it will be useful,  
12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of  
13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
14 - * GNU General Public License for more details.  
15 - *  
16 - * You should have received a copy of the GNU Lesser General Public License version 3  
17 - * along with this program; if not, see <http://www.gnu.org/licenses/>  
18 - * or write to the Free Software Foundation, Inc., 51 Franklin Street,  
19 - * Fifth Floor, Boston, MA 02110-1301, USA.  
20 - * ----------------------------------------------------------------------------  
21 - * Este arquivo é parte do Framework Demoiselle.  
22 - *  
23 - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou  
24 - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação  
25 - * do Software Livre (FSF).  
26 - *  
27 - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA  
28 - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou  
29 - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português  
30 - * para maiores detalhes.  
31 - *  
32 - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título  
33 - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>  
34 - * ou escreva para a Fundação do Software Livre (FSF) Inc.,  
35 - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.  
36 - */  
37 -package br.gov.frameworkdemoiselle.internal.management.qualifier;  
38 -  
39 -import java.lang.annotation.ElementType;  
40 -import java.lang.annotation.Retention;  
41 -import java.lang.annotation.RetentionPolicy;  
42 -import java.lang.annotation.Target;  
43 -  
44 -import javax.inject.Qualifier;  
45 -  
46 -import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent;  
47 -import br.gov.frameworkdemoiselle.management.GenericNotification;  
48 -  
49 -/**  
50 - *  
51 - * Enables {@link ManagementNotificationEvent} observers to trigger only with notifications  
52 - * of the base type {@link GenericNotification}.  
53 - *  
54 - * @author SERPRO  
55 - *  
56 - */  
57 -@Qualifier  
58 -@Retention(RetentionPolicy.RUNTIME)  
59 -@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})  
60 -public @interface Generic {  
61 -  
62 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/lifecycle/ManagementExtension.java
@@ -1,78 +0,0 @@ @@ -1,78 +0,0 @@
1 -/*  
2 - * Demoiselle Framework  
3 - * Copyright (C) 2010 SERPRO  
4 - * ----------------------------------------------------------------------------  
5 - * This file is part of Demoiselle Framework.  
6 - *  
7 - * Demoiselle Framework is free software; you can redistribute it and/or  
8 - * modify it under the terms of the GNU Lesser General Public License version 3  
9 - * as published by the Free Software Foundation.  
10 - *  
11 - * This program is distributed in the hope that it will be useful,  
12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of  
13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
14 - * GNU General Public License for more details.  
15 - *  
16 - * You should have received a copy of the GNU Lesser General Public License version 3  
17 - * along with this program; if not, see <http://www.gnu.org/licenses/>  
18 - * or write to the Free Software Foundation, Inc., 51 Franklin Street,  
19 - * Fifth Floor, Boston, MA 02110-1301, USA.  
20 - * ----------------------------------------------------------------------------  
21 - * Este arquivo é parte do Framework Demoiselle.  
22 - *  
23 - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou  
24 - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação  
25 - * do Software Livre (FSF).  
26 - *  
27 - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA  
28 - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou  
29 - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português  
30 - * para maiores detalhes.  
31 - *  
32 - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título  
33 - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>  
34 - * ou escreva para a Fundação do Software Livre (FSF) Inc.,  
35 - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.  
36 - */  
37 -package br.gov.frameworkdemoiselle.lifecycle;  
38 -  
39 -import java.util.List;  
40 -  
41 -import br.gov.frameworkdemoiselle.internal.management.ManagedType;  
42 -import br.gov.frameworkdemoiselle.stereotype.ManagementController;  
43 -  
44 -/**  
45 - * <p>  
46 - * Interface defining the lifecycle of a <b>management extension</b>, an extension capable of exposing  
47 - * {@link ManagementController}'s to external clients in one of the available management technologies, such as JMX or  
48 - * SNMP.  
49 - * </p>  
50 - * <p>  
51 - * To include a management extension into the management lifecycle, it just needs to implement this interface and be a  
52 - * CDI bean (have a <b>beans.xml</b> file inside the META-INF folder of it's java package). The Demoiselle Core  
53 - * lifecycle controller will call the {@link #initialize(List managedTypes)} and {@link #shutdown(List managedTypes)}  
54 - * methods at the apropriate times.  
55 - * </p>  
56 - *  
57 - * @author SERPRO  
58 - */  
59 -public interface ManagementExtension {  
60 -  
61 - /**  
62 - * This method is called during the application initialization process for each concrete implementation of this  
63 - * interface.  
64 - *  
65 - * @param managedTypes  
66 - * The list of discovered {@link ManagementController} classes.  
67 - */  
68 - void initialize(List<ManagedType> managedTypes);  
69 -  
70 - /**  
71 - * This method is called during the application shutdown process for each concrete implementation of this interface.  
72 - *  
73 - * @param managedTypes  
74 - * The list of discovered {@link ManagementController} classes.  
75 - */  
76 - void shutdown(List<ManagedType> managedTypes);  
77 -  
78 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/ManagementExtension.java 0 → 100644
@@ -0,0 +1,78 @@ @@ -0,0 +1,78 @@
  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.management;
  38 +
  39 +import java.util.List;
  40 +
  41 +import br.gov.frameworkdemoiselle.internal.implementation.ManagedType;
  42 +import br.gov.frameworkdemoiselle.stereotype.ManagementController;
  43 +
  44 +/**
  45 + * <p>
  46 + * Interface defining the lifecycle of a <b>management extension</b>, an extension capable of exposing
  47 + * {@link ManagementController}'s to external clients in one of the available management technologies, such as JMX or
  48 + * SNMP.
  49 + * </p>
  50 + * <p>
  51 + * To include a management extension into the management lifecycle, it just needs to implement this interface and be a
  52 + * CDI bean (have a <b>beans.xml</b> file inside the META-INF folder of it's java package). The Demoiselle Core
  53 + * lifecycle controller will call the {@link #initialize(List managedTypes)} and {@link #shutdown(List managedTypes)}
  54 + * methods at the apropriate times.
  55 + * </p>
  56 + *
  57 + * @author SERPRO
  58 + */
  59 +public interface ManagementExtension {
  60 +
  61 + /**
  62 + * This method is called during the application initialization process for each concrete implementation of this
  63 + * interface.
  64 + *
  65 + * @param managedTypes
  66 + * The list of discovered {@link ManagementController} classes.
  67 + */
  68 + void initialize(List<ManagedType> managedTypes);
  69 +
  70 + /**
  71 + * This method is called during the application shutdown process for each concrete implementation of this interface.
  72 + *
  73 + * @param managedTypes
  74 + * The list of discovered {@link ManagementController} classes.
  75 + */
  76 + void shutdown(List<ManagedType> managedTypes);
  77 +
  78 +}
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/NotificationManager.java
@@ -40,8 +40,8 @@ import javax.enterprise.context.ApplicationScoped; @@ -40,8 +40,8 @@ import javax.enterprise.context.ApplicationScoped;
40 import javax.enterprise.event.Observes; 40 import javax.enterprise.event.Observes;
41 import javax.inject.Inject; 41 import javax.inject.Inject;
42 42
43 -import br.gov.frameworkdemoiselle.internal.management.qualifier.AttributeChange;  
44 -import br.gov.frameworkdemoiselle.internal.management.qualifier.Generic; 43 +import br.gov.frameworkdemoiselle.internal.implementation.AttributeChange;
  44 +import br.gov.frameworkdemoiselle.internal.implementation.Generic;
45 import br.gov.frameworkdemoiselle.util.Beans; 45 import br.gov.frameworkdemoiselle.util.Beans;
46 46
47 /** 47 /**
impl/core/src/test/java/management/bootstrap/ManagementBootstrapTest.java
@@ -50,9 +50,9 @@ import org.junit.Test; @@ -50,9 +50,9 @@ import org.junit.Test;
50 import org.junit.runner.RunWith; 50 import org.junit.runner.RunWith;
51 51
52 import test.Tests; 52 import test.Tests;
53 -import br.gov.frameworkdemoiselle.internal.management.ManagedType; 53 +import br.gov.frameworkdemoiselle.internal.implementation.ManagedType;
54 import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; 54 import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess;
55 -import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; 55 +import br.gov.frameworkdemoiselle.management.ManagementExtension;
56 import br.gov.frameworkdemoiselle.util.Beans; 56 import br.gov.frameworkdemoiselle.util.Beans;
57 57
58 @RunWith(Arquillian.class) 58 @RunWith(Arquillian.class)
impl/core/src/test/java/management/notification/NotificationTest.java
@@ -50,8 +50,8 @@ import org.junit.runner.RunWith; @@ -50,8 +50,8 @@ import org.junit.runner.RunWith;
50 50
51 import test.Tests; 51 import test.Tests;
52 import br.gov.frameworkdemoiselle.annotation.Name; 52 import br.gov.frameworkdemoiselle.annotation.Name;
53 -import br.gov.frameworkdemoiselle.internal.management.ManagedType;  
54 -import br.gov.frameworkdemoiselle.internal.management.Management; 53 +import br.gov.frameworkdemoiselle.internal.implementation.ManagedType;
  54 +import br.gov.frameworkdemoiselle.internal.implementation.Management;
55 import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; 55 import br.gov.frameworkdemoiselle.management.AttributeChangeNotification;
56 import br.gov.frameworkdemoiselle.management.GenericNotification; 56 import br.gov.frameworkdemoiselle.management.GenericNotification;
57 import br.gov.frameworkdemoiselle.management.NotificationManager; 57 import br.gov.frameworkdemoiselle.management.NotificationManager;
impl/core/src/test/java/management/testclasses/DummyManagementExtension.java
@@ -41,8 +41,8 @@ import java.util.List; @@ -41,8 +41,8 @@ import java.util.List;
41 import javax.inject.Inject; 41 import javax.inject.Inject;
42 42
43 43
44 -import br.gov.frameworkdemoiselle.internal.management.ManagedType;  
45 -import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; 44 +import br.gov.frameworkdemoiselle.internal.implementation.ManagedType;
  45 +import br.gov.frameworkdemoiselle.management.ManagementExtension;
46 46
47 public class DummyManagementExtension implements ManagementExtension { 47 public class DummyManagementExtension implements ManagementExtension {
48 48
impl/core/src/test/java/management/testclasses/DummyNotificationListener.java
@@ -39,8 +39,8 @@ package management.testclasses; @@ -39,8 +39,8 @@ package management.testclasses;
39 import javax.enterprise.context.ApplicationScoped; 39 import javax.enterprise.context.ApplicationScoped;
40 import javax.enterprise.event.Observes; 40 import javax.enterprise.event.Observes;
41 41
42 -import br.gov.frameworkdemoiselle.internal.management.qualifier.AttributeChange;  
43 -import br.gov.frameworkdemoiselle.internal.management.qualifier.Generic; 42 +import br.gov.frameworkdemoiselle.internal.implementation.AttributeChange;
  43 +import br.gov.frameworkdemoiselle.internal.implementation.Generic;
44 import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; 44 import br.gov.frameworkdemoiselle.management.AttributeChangeNotification;
45 import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent; 45 import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent;
46 import br.gov.frameworkdemoiselle.management.NotificationManager; 46 import br.gov.frameworkdemoiselle.management.NotificationManager;
impl/core/src/test/java/management/testclasses/ManagedClassStore.java
@@ -42,8 +42,8 @@ import java.util.List; @@ -42,8 +42,8 @@ import java.util.List;
42 42
43 import javax.enterprise.context.ApplicationScoped; 43 import javax.enterprise.context.ApplicationScoped;
44 44
45 -import br.gov.frameworkdemoiselle.internal.management.ManagedType;  
46 -import br.gov.frameworkdemoiselle.internal.management.Management; 45 +import br.gov.frameworkdemoiselle.internal.implementation.ManagedType;
  46 +import br.gov.frameworkdemoiselle.internal.implementation.Management;
47 import br.gov.frameworkdemoiselle.util.Beans; 47 import br.gov.frameworkdemoiselle.util.Beans;
48 48
49 /** 49 /**
impl/extension/jdbc/src/test/resources/.arquillian-glassfish-embedded.profile 0 → 100644
impl/extension/jdbc/src/test/resources/.glassfish.profile
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/DynamicMBeanProxy.java
@@ -53,11 +53,11 @@ import javax.management.MBeanParameterInfo; @@ -53,11 +53,11 @@ import javax.management.MBeanParameterInfo;
53 import javax.management.ReflectionException; 53 import javax.management.ReflectionException;
54 54
55 import br.gov.frameworkdemoiselle.DemoiselleException; 55 import br.gov.frameworkdemoiselle.DemoiselleException;
56 -import br.gov.frameworkdemoiselle.internal.management.ManagedType;  
57 -import br.gov.frameworkdemoiselle.internal.management.ManagedType.FieldDetail;  
58 -import br.gov.frameworkdemoiselle.internal.management.ManagedType.MethodDetail;  
59 -import br.gov.frameworkdemoiselle.internal.management.ManagedType.ParameterDetail;  
60 -import br.gov.frameworkdemoiselle.internal.management.Management; 56 +import br.gov.frameworkdemoiselle.internal.implementation.ManagedType;
  57 +import br.gov.frameworkdemoiselle.internal.implementation.ManagedType.FieldDetail;
  58 +import br.gov.frameworkdemoiselle.internal.implementation.ManagedType.MethodDetail;
  59 +import br.gov.frameworkdemoiselle.internal.implementation.ManagedType.ParameterDetail;
  60 +import br.gov.frameworkdemoiselle.internal.implementation.Management;
61 import br.gov.frameworkdemoiselle.management.ManagedAttributeNotFoundException; 61 import br.gov.frameworkdemoiselle.management.ManagedAttributeNotFoundException;
62 import br.gov.frameworkdemoiselle.management.ManagedInvokationException; 62 import br.gov.frameworkdemoiselle.management.ManagedInvokationException;
63 import br.gov.frameworkdemoiselle.stereotype.ManagementController; 63 import br.gov.frameworkdemoiselle.stereotype.ManagementController;
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/JMXManagementExtension.java
@@ -42,8 +42,8 @@ import javax.management.ObjectInstance; @@ -42,8 +42,8 @@ import javax.management.ObjectInstance;
42 42
43 import br.gov.frameworkdemoiselle.annotation.Name; 43 import br.gov.frameworkdemoiselle.annotation.Name;
44 import br.gov.frameworkdemoiselle.configuration.JMXConfig; 44 import br.gov.frameworkdemoiselle.configuration.JMXConfig;
45 -import br.gov.frameworkdemoiselle.internal.management.ManagedType;  
46 -import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; 45 +import br.gov.frameworkdemoiselle.internal.implementation.ManagedType;
  46 +import br.gov.frameworkdemoiselle.management.ManagementExtension;
47 import br.gov.frameworkdemoiselle.util.Beans; 47 import br.gov.frameworkdemoiselle.util.Beans;
48 48
49 public class JMXManagementExtension implements ManagementExtension { 49 public class JMXManagementExtension implements ManagementExtension {
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/NotificationEventListener.java
@@ -42,8 +42,8 @@ import javax.enterprise.context.ApplicationScoped; @@ -42,8 +42,8 @@ import javax.enterprise.context.ApplicationScoped;
42 import javax.enterprise.event.Observes; 42 import javax.enterprise.event.Observes;
43 43
44 import br.gov.frameworkdemoiselle.configuration.JMXConfig; 44 import br.gov.frameworkdemoiselle.configuration.JMXConfig;
45 -import br.gov.frameworkdemoiselle.internal.management.qualifier.AttributeChange;  
46 -import br.gov.frameworkdemoiselle.internal.management.qualifier.Generic; 45 +import br.gov.frameworkdemoiselle.internal.implementation.AttributeChange;
  46 +import br.gov.frameworkdemoiselle.internal.implementation.Generic;
47 import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent; 47 import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent;
48 import br.gov.frameworkdemoiselle.management.NotificationManager; 48 import br.gov.frameworkdemoiselle.management.NotificationManager;
49 49
impl/extension/jmx/src/test/resources/.arquillian-weld-se-embedded.profile 0 → 100644
impl/extension/jmx/src/test/resources/.weldse.profile
impl/extension/jpa/src/test/resources/.arquillian-glassfish-embedded.profile 0 → 100644
impl/extension/jpa/src/test/resources/.glassfish.profile
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/JsfBootstrap.java
@@ -42,7 +42,7 @@ import javax.enterprise.inject.spi.AfterDeploymentValidation; @@ -42,7 +42,7 @@ import javax.enterprise.inject.spi.AfterDeploymentValidation;
42 import javax.enterprise.inject.spi.Extension; 42 import javax.enterprise.inject.spi.Extension;
43 43
44 import br.gov.frameworkdemoiselle.context.ViewContext; 44 import br.gov.frameworkdemoiselle.context.ViewContext;
45 -import br.gov.frameworkdemoiselle.internal.context.ContextManager2; 45 +import br.gov.frameworkdemoiselle.internal.context.CustomContextProducer;
46 import br.gov.frameworkdemoiselle.internal.context.FacesViewContextImpl; 46 import br.gov.frameworkdemoiselle.internal.context.FacesViewContextImpl;
47 import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; 47 import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess;
48 import br.gov.frameworkdemoiselle.util.Beans; 48 import br.gov.frameworkdemoiselle.util.Beans;
@@ -52,14 +52,18 @@ public class JsfBootstrap implements Extension { @@ -52,14 +52,18 @@ public class JsfBootstrap implements Extension {
52 //private List<CustomContext> customContexts = new ArrayList<CustomContext>(); 52 //private List<CustomContext> customContexts = new ArrayList<CustomContext>();
53 53
54 //private AfterBeanDiscovery afterBeanDiscoveryEvent; 54 //private AfterBeanDiscovery afterBeanDiscoveryEvent;
55 -  
56 - public void storeContexts(@Observes final AfterBeanDiscovery event) {  
57 - //Registra o ViewContext para controlar o escopo ViewScoped.  
58 - ContextManager2 contextManager = Beans.getReference(ContextManager2.class);  
59 - contextManager.addCustomContext(new FacesViewContextImpl()); 55 +
  56 + private FacesViewContextImpl context;
  57 +
  58 + public void createCustomContext(@Observes AfterBeanDiscovery event){
  59 + context = new FacesViewContextImpl();
  60 + event.addContext(context);
60 } 61 }
61 62
62 public void addContexts(@Observes final AfterDeploymentValidation event) { 63 public void addContexts(@Observes final AfterDeploymentValidation event) {
  64 + CustomContextProducer producer = Beans.getReference(CustomContextProducer.class);
  65 + producer.addRegisteredContext(context);
  66 +
63 //Ativa o ViewContext 67 //Ativa o ViewContext
64 ViewContext ctx = Beans.getReference(FacesViewContextImpl.class); 68 ViewContext ctx = Beans.getReference(FacesViewContextImpl.class);
65 ctx.activate(); 69 ctx.activate();
impl/extension/jsf/src/test/java/test/Tests.java 0 → 100644
@@ -0,0 +1,84 @@ @@ -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 test;
  38 +
  39 +import java.io.File;
  40 +
  41 +import org.jboss.shrinkwrap.api.ShrinkWrap;
  42 +import org.jboss.shrinkwrap.api.asset.FileAsset;
  43 +import org.jboss.shrinkwrap.api.spec.WebArchive;
  44 +import org.jboss.shrinkwrap.resolver.api.maven.Maven;
  45 +import org.junit.Ignore;
  46 +
  47 +@Ignore
  48 +public final class Tests {
  49 +
  50 + private Tests() {
  51 + }
  52 +
  53 + public static WebArchive createDeployment(final Class<?> baseClass) {
  54 + return createDeployment().addPackages(true, baseClass.getPackage()).addClass(Tests.class);
  55 + }
  56 +
  57 + public static WebArchive createDeployment() {
  58 + File[] libs = Maven.resolver().offline().loadPomFromFile("pom.xml", "arquillian-test")
  59 + .importCompileAndRuntimeDependencies().resolve().withTransitivity().asFile();
  60 +
  61 + return ShrinkWrap
  62 + .create(WebArchive.class)
  63 + // .addClass(ServletAuthenticator.class)
  64 + // .addClass(ServletAuthorizer.class)
  65 + // .addClass(ServletFilter.class)
  66 + // .addClass(ServletListener.class)
  67 + // .addClass(HttpServletRequestProducer.class)
  68 + // .addClass(HttpServletResponseProducer.class)
  69 + // .addClass(HttpSessionProducer.class)
  70 + // .addClass(ServletLocaleProducer.class)
  71 + // .addClass(BasicAuthenticationFilter.class)
  72 + // .addClass(HttpServletRequestProducerFilter.class)
  73 + // .addClass(HttpServletResponseProducerFilter.class)
  74 + // .addClass(InternalProcessorFilterImpl.class)
  75 + .addAsResource(createFileAsset("src/main/resources/demoiselle-jsf-bundle.properties"),
  76 + "demoiselle-jsf-bundle.properties")
  77 + .addAsWebInfResource(createFileAsset("src/test/resources/test/beans.xml"), "beans.xml")
  78 + .addAsLibraries(libs);
  79 + }
  80 +
  81 + public static FileAsset createFileAsset(final String pathname) {
  82 + return new FileAsset(new File(pathname));
  83 + }
  84 +}
impl/extension/jsf/src/test/java/xxxx/XServlet.java 0 → 100644
@@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
  1 +package xxxx;
  2 +
  3 +import java.io.IOException;
  4 +
  5 +import javax.inject.Inject;
  6 +import javax.servlet.ServletException;
  7 +import javax.servlet.annotation.WebServlet;
  8 +import javax.servlet.http.HttpServlet;
  9 +import javax.servlet.http.HttpServletRequest;
  10 +import javax.servlet.http.HttpServletResponse;
  11 +
  12 +import br.gov.frameworkdemoiselle.security.Credentials;
  13 +import br.gov.frameworkdemoiselle.security.SecurityContext;
  14 +
  15 +@WebServlet("/login")
  16 +public class XServlet extends HttpServlet {
  17 +
  18 + private static final long serialVersionUID = 1L;
  19 +
  20 + @Inject
  21 + private SecurityContext securityContext;
  22 +
  23 + @Inject
  24 + private Credentials credentials;
  25 +
  26 + @Override
  27 + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  28 + super.doGet(request, response);
  29 +
  30 + credentials.setUsername("admin");
  31 + credentials.setPassword("changeit");
  32 +
  33 + securityContext.login();
  34 + }
  35 +}
impl/extension/jsf/src/test/java/xxxx/XTest.java 0 → 100644
@@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
  1 +package xxxx;
  2 +
  3 +import java.net.URL;
  4 +
  5 +import org.jboss.arquillian.container.test.api.Deployment;
  6 +import org.jboss.arquillian.drone.api.annotation.Drone;
  7 +import org.jboss.arquillian.junit.Arquillian;
  8 +import org.jboss.arquillian.test.api.ArquillianResource;
  9 +import org.jboss.shrinkwrap.api.spec.WebArchive;
  10 +import org.junit.Test;
  11 +import org.junit.runner.RunWith;
  12 +
  13 +import test.Tests;
  14 +
  15 +import com.thoughtworks.selenium.DefaultSelenium;
  16 +
  17 +@RunWith(Arquillian.class)
  18 +public class XTest {
  19 +
  20 + private static final String PATH = "src/test/resources/xxx";
  21 +
  22 + @Drone
  23 + private DefaultSelenium browser;
  24 +
  25 + @ArquillianResource
  26 + private URL deploymentUrl;
  27 +
  28 + @Deployment(testable = false)
  29 + public static WebArchive createDeployment() {
  30 + return Tests.createDeployment().addClass(XServlet.class)
  31 + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml");
  32 + }
  33 +
  34 + @Test
  35 + public void xxxx() {
  36 + browser.open(deploymentUrl + "login");
  37 +
  38 + // browser.type("id=xxx-input", "demo");
  39 + // browser.waitForPageToLoad("15000");
  40 +
  41 + // assertTrue("User should be logged in!",
  42 + // browser.isElementPresent("xpath=//li[contains(text(), 'Welcome')]"));
  43 + // assertTrue("Username should be shown!",
  44 + // browser.isElementPresent("xpath=//p[contains(text(), 'You are signed in as demo.')]"));
  45 + }
  46 +}
impl/extension/jsf/src/test/resources/.arquillian-drone.profile 0 → 100644
impl/extension/jsf/src/test/resources/.arquillian-glassfish-embedded.profile 0 → 100644
impl/extension/jsf/src/test/resources/.drone.profile
impl/extension/jsf/src/test/resources/.glassfish.profile
impl/extension/jsf/src/test/resources/arquillian.xml 0 → 100644
@@ -0,0 +1,68 @@ @@ -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 +<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  38 + xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
  39 +
  40 + <!--
  41 + -->
  42 + <engine>
  43 + <property name="deploymentExportPath">target/deployments</property>
  44 + </engine>
  45 +
  46 + <!--
  47 + <extension qualifier="selenium">
  48 + <property name="browser">*googlechrome</property>
  49 + </extension>
  50 + -->
  51 +
  52 + <!--
  53 + <container qualifier="glassfish" default="true">
  54 + <configuration>
  55 + <property name="autoDelete">true</property>
  56 + </configuration>
  57 + </container>
  58 + -->
  59 +
  60 + <!--
  61 + <container qualifier="jbossas-managed" default="true">
  62 + <protocol type="Servlet 3.0" />
  63 + <configuration>
  64 + <property name="jbossHome">target/jboss-as-${jboss.as.version}</property>
  65 + </configuration>
  66 + </container>
  67 + -->
  68 +</arquillian>
impl/extension/jsf/src/test/resources/test/beans.xml 0 → 100644
@@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
  1 +<!--
  2 + Demoiselle Framework
  3 + Copyright (C) 2010 SERPRO
  4 + ============================================================================
  5 + This file is part of Demoiselle Framework.
  6 +
  7 + Demoiselle Framework is free software; you can redistribute it and/or
  8 + modify it under the terms of the GNU Lesser General Public License version 3
  9 + as published by the Free Software Foundation.
  10 +
  11 + This program is distributed in the hope that it will be useful,
  12 + but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + GNU General Public License for more details.
  15 +
  16 + You should have received a copy of the GNU Lesser General Public License version 3
  17 + along with this program; if not, see <http://www.gnu.org/licenses />
  18 + or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + Fifth Floor, Boston, MA 02110-1301, USA.
  20 + ============================================================================
  21 + Este arquivo é parte do Framework Demoiselle.
  22 +
  23 + O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + do Software Livre (FSF).
  26 +
  27 + Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + para maiores detalhes.
  31 +
  32 + Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses />
  34 + ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 +-->
  37 +<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  38 + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
  39 +
  40 + <interceptors>
  41 + <class>br.gov.frameworkdemoiselle.transaction.TransactionalInterceptor</class>
  42 + <class>br.gov.frameworkdemoiselle.security.RequiredPermissionInterceptor</class>
  43 + <class>br.gov.frameworkdemoiselle.security.RequiredRoleInterceptor</class>
  44 + <class>br.gov.frameworkdemoiselle.exception.ExceptionHandlerInterceptor</class>
  45 + </interceptors>
  46 +
  47 +</beans>
impl/extension/jsf/src/test/resources/xxx/web.xml 0 → 100644
@@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
  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 +<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  38 + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  39 +
  40 + <listener>
  41 + <listener-class>br.gov.frameworkdemoiselle.util.ServletListener</listener-class>
  42 + </listener>
  43 + <filter>
  44 + <filter-name>Demoiselle Servlet Filter</filter-name>
  45 + <filter-class>br.gov.frameworkdemoiselle.util.ServletFilter</filter-class>
  46 + </filter>
  47 + <filter-mapping>
  48 + <filter-name>Demoiselle Servlet Filter</filter-name>
  49 + <url-pattern>/*</url-pattern>
  50 + </filter-mapping>
  51 +
  52 +</web-app>
0 \ No newline at end of file 53 \ No newline at end of file
impl/extension/jta/pom.xml
@@ -71,6 +71,12 @@ @@ -71,6 +71,12 @@
71 <groupId>javax.transaction</groupId> 71 <groupId>javax.transaction</groupId>
72 <artifactId>jta</artifactId> 72 <artifactId>jta</artifactId>
73 </dependency> 73 </dependency>
  74 +
  75 + <dependency>
  76 + <groupId>org.hibernate</groupId>
  77 + <artifactId>hibernate-entitymanager</artifactId>
  78 + <scope>test</scope>
  79 + </dependency>
74 </dependencies> 80 </dependencies>
75 81
76 <repositories> 82 <repositories>
impl/extension/jta/src/test/java/jtatransaction/interceptor/InterceptorJTATransactionTest.java
@@ -6,7 +6,7 @@ import static junit.framework.Assert.assertNull; @@ -6,7 +6,7 @@ import static junit.framework.Assert.assertNull;
6 6
7 import javax.persistence.EntityManager; 7 import javax.persistence.EntityManager;
8 import javax.persistence.PersistenceContext; 8 import javax.persistence.PersistenceContext;
9 -import javax.persistence.TransactionRequiredException; 9 +import javax.transaction.TransactionRequiredException;
10 10
11 import org.jboss.arquillian.container.test.api.Deployment; 11 import org.jboss.arquillian.container.test.api.Deployment;
12 import org.jboss.arquillian.junit.Arquillian; 12 import org.jboss.arquillian.junit.Arquillian;
impl/extension/se/src/test/resources/.arquillian-weld-se-embedded.profile 0 → 100644
impl/extension/se/src/test/resources/.weldse.profile
impl/extension/servlet/pom.xml
@@ -84,6 +84,12 @@ @@ -84,6 +84,12 @@
84 <scope>test</scope> 84 <scope>test</scope>
85 </dependency> 85 </dependency>
86 --> 86 -->
  87 + <dependency>
  88 + <groupId>commons-httpclient</groupId>
  89 + <artifactId>commons-httpclient</artifactId>
  90 + <version>3.1</version>
  91 + <scope>test</scope>
  92 + </dependency>
87 </dependencies> 93 </dependencies>
88 94
89 <repositories> 95 <repositories>
impl/extension/servlet/src/test/java/xxxx/XServlet.java
@@ -26,6 +26,8 @@ public class XServlet extends HttpServlet { @@ -26,6 +26,8 @@ public class XServlet extends HttpServlet {
26 @Override 26 @Override
27 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 27 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
28 super.doGet(request, response); 28 super.doGet(request, response);
  29 +
  30 + System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
29 31
30 credentials.setUsername("admin"); 32 credentials.setUsername("admin");
31 credentials.setPassword("changeit"); 33 credentials.setPassword("changeit");
impl/extension/servlet/src/test/java/xxxx/XTest.java
1 package xxxx; 1 package xxxx;
2 2
  3 +import java.io.IOException;
3 import java.net.URL; 4 import java.net.URL;
4 5
  6 +import org.apache.commons.httpclient.HttpClient;
  7 +import org.apache.commons.httpclient.HttpException;
  8 +import org.apache.commons.httpclient.methods.GetMethod;
5 import org.jboss.arquillian.container.test.api.Deployment; 9 import org.jboss.arquillian.container.test.api.Deployment;
6 -import org.jboss.arquillian.drone.api.annotation.Drone;  
7 import org.jboss.arquillian.junit.Arquillian; 10 import org.jboss.arquillian.junit.Arquillian;
8 import org.jboss.arquillian.test.api.ArquillianResource; 11 import org.jboss.arquillian.test.api.ArquillianResource;
9 import org.jboss.shrinkwrap.api.spec.WebArchive; 12 import org.jboss.shrinkwrap.api.spec.WebArchive;
@@ -12,27 +15,37 @@ import org.junit.runner.RunWith; @@ -12,27 +15,37 @@ import org.junit.runner.RunWith;
12 15
13 import test.Tests; 16 import test.Tests;
14 17
15 -import com.thoughtworks.selenium.DefaultSelenium;  
16 -  
17 @RunWith(Arquillian.class) 18 @RunWith(Arquillian.class)
18 public class XTest { 19 public class XTest {
19 20
20 private static final String PATH = "src/test/resources/xxx"; 21 private static final String PATH = "src/test/resources/xxx";
21 22
22 - @Drone  
23 - private DefaultSelenium browser;  
24 -  
25 @ArquillianResource 23 @ArquillianResource
26 private URL deploymentUrl; 24 private URL deploymentUrl;
27 25
28 @Deployment(testable = false) 26 @Deployment(testable = false)
29 public static WebArchive createDeployment() { 27 public static WebArchive createDeployment() {
30 - return Tests.createDeployment().addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); 28 + return Tests.createDeployment().addClass(XServlet.class)
  29 + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml");
31 } 30 }
32 31
33 @Test 32 @Test
34 public void xxxx() { 33 public void xxxx() {
35 - browser.open(deploymentUrl + "login"); 34 + HttpClient client = new HttpClient();
  35 + GetMethod method = new GetMethod(deploymentUrl + "login");
  36 +
  37 + try {
  38 + int status = client.executeMethod(method);
  39 + System.out.println(status);
  40 +
  41 + } catch (HttpException e) {
  42 + e.printStackTrace();
  43 +
  44 + } catch (IOException e) {
  45 + e.printStackTrace();
  46 + }
  47 +
  48 + // browser.open(deploymentUrl + "login");
36 49
37 // browser.type("id=xxx-input", "demo"); 50 // browser.type("id=xxx-input", "demo");
38 // browser.waitForPageToLoad("15000"); 51 // browser.waitForPageToLoad("15000");
impl/extension/servlet/src/test/resources/.arquillian-glassfish-embedded.profile 0 → 100644
impl/extension/servlet/src/test/resources/.drone.profile
impl/extension/servlet/src/test/resources/.glassfish.profile
parent/extension/pom.xml
@@ -191,7 +191,7 @@ @@ -191,7 +191,7 @@
191 <id>arquillian-weld-se-embedded</id> 191 <id>arquillian-weld-se-embedded</id>
192 <activation> 192 <activation>
193 <file> 193 <file>
194 - <exists>src/test/resources/.weldse.profile</exists> 194 + <exists>src/test/resources/.arquillian-weld-se-embedded.profile</exists>
195 </file> 195 </file>
196 </activation> 196 </activation>
197 <dependencies> 197 <dependencies>
@@ -210,7 +210,7 @@ @@ -210,7 +210,7 @@
210 <id>arquillian-glassfish-embedded</id> 210 <id>arquillian-glassfish-embedded</id>
211 <activation> 211 <activation>
212 <file> 212 <file>
213 - <exists>src/test/resources/.glassfish.profile</exists> 213 + <exists>src/test/resources/.arquillian-glassfish-embedded.profile</exists>
214 </file> 214 </file>
215 <!-- 215 <!--
216 <activeByDefault>true</activeByDefault> 216 <activeByDefault>true</activeByDefault>
@@ -235,7 +235,7 @@ @@ -235,7 +235,7 @@
235 <id>arquillian-jbossas7-managed</id> 235 <id>arquillian-jbossas7-managed</id>
236 <activation> 236 <activation>
237 <file> 237 <file>
238 - <exists>src/test/resources/.jbossas7.profile</exists> 238 + <exists>src/test/resources/.arquillian-jbossas7-managed.profile</exists>
239 </file> 239 </file>
240 </activation> 240 </activation>
241 <build> 241 <build>
@@ -321,7 +321,7 @@ @@ -321,7 +321,7 @@
321 <id>arquillian-drone</id> 321 <id>arquillian-drone</id>
322 <activation> 322 <activation>
323 <file> 323 <file>
324 - <exists>src/test/resources/.drone.profile</exists> 324 + <exists>src/test/resources/.arquillian-drone.profile</exists>
325 </file> 325 </file>
326 </activation> 326 </activation>
327 <dependencyManagement> 327 <dependencyManagement>