Commit 89f655dd71898c320b6f0dbc4bc00af86923f3f5

Authored by Dancovich
1 parent 044a3c54
Exists in master

IN PROGRESS - issue FWK-144: Classes anotadas com @ManagementController

e @Named não conseguem ser acessadas para monitoração 
https://demoiselle.atlassian.net/browse/FWK-144
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ManagedType.java
... ... @@ -43,6 +43,7 @@ import java.util.ArrayList;
43 43 import java.util.Locale;
44 44 import java.util.TreeMap;
45 45  
  46 +import javax.inject.Named;
46 47 import javax.inject.Qualifier;
47 48  
48 49 import br.gov.frameworkdemoiselle.DemoiselleException;
... ... @@ -52,6 +53,7 @@ import br.gov.frameworkdemoiselle.annotation.ManagedProperty.ManagedPropertyAcce
52 53 import br.gov.frameworkdemoiselle.annotation.OperationParameter;
53 54 import br.gov.frameworkdemoiselle.annotation.OperationType;
54 55 import br.gov.frameworkdemoiselle.stereotype.ManagementController;
  56 +import br.gov.frameworkdemoiselle.util.NamedQualifier;
55 57 import br.gov.frameworkdemoiselle.util.ResourceBundle;
56 58  
57 59 /**
... ... @@ -273,18 +275,29 @@ public class ManagedType {
273 275 return ((ManagedType) other).getType().getCanonicalName().equals(this.getType().getCanonicalName());
274 276 }
275 277  
276   - private synchronized Annotation[] getQualifierAnnotations(Class<?> beanClass){
277   - Annotation[] annotations = beanClass.getAnnotations();
  278 + private synchronized Annotation[] getQualifierAnnotations(final Class<?> beanClass){
  279 + Annotation[] annotations = beanClass.getDeclaredAnnotations();
278 280 ArrayList<Annotation> qualifiers = new ArrayList<Annotation>(annotations.length);
279   -
  281 +
280 282 for (int i=0; i<annotations.length; i++){
281 283 if (annotations[i].annotationType().getAnnotation(Qualifier.class) != null){
282   - qualifiers.add(annotations[i]);
  284 + if (annotations[i].annotationType().equals(Named.class)
  285 + && "".equals( ((Named)annotations[i]).value() )
  286 + ){
  287 + qualifiers.add( new NamedQualifier(formatClassName(beanClass)) );
  288 + }
  289 + else{
  290 + qualifiers.add(annotations[i]);
  291 + }
283 292 }
284 293 }
285 294  
286 295 return qualifiers.toArray(new Annotation[0]);
287 296 }
  297 +
  298 + private String formatClassName(Class<?> type){
  299 + return type.getSimpleName().substring(0, 1).toLowerCase() +type.getSimpleName().substring(1);
  300 + }
288 301  
289 302 public final class FieldDetail {
290 303  
... ...
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/NamedQualifier.java 0 → 100644
... ... @@ -0,0 +1,69 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.util;
  38 +
  39 +import java.lang.annotation.Annotation;
  40 +
  41 +import javax.enterprise.util.AnnotationLiteral;
  42 +import javax.inject.Named;
  43 +
  44 +import util.beans.ambiguous.AmbiguousQualifier;
  45 +
  46 +/**
  47 + * Annotation litteral that allows to create instances of the {@link Named} qualifier.
  48 + * Those instances can then be used to call {@link Beans#getReference(Class type, Annotation... qualifiers)}.
  49 + *
  50 + * @see Beans
  51 + * @see Named
  52 + *
  53 + * @author SERPRO
  54 + */
  55 +@SuppressWarnings("all")
  56 +public class NamedQualifier extends AnnotationLiteral<Named> implements Named {
  57 +
  58 + private static final long serialVersionUID = 6790759427086052113L;
  59 +
  60 + private String namedValue;
  61 +
  62 + public NamedQualifier(String value) {
  63 + namedValue = value;
  64 + }
  65 +
  66 + public String value() {
  67 + return namedValue;
  68 + }
  69 +}
... ...