Commit 04970ec948d41c642b9605b825bbd3607bc9adc2
1 parent
97ebc8f1
Exists in
master
FWK-201: Depreciação da injeção de SLF4J Logger
Task-Url: https://demoiselle.atlassian.net/browse/FWK-201
Showing
2 changed files
with
102 additions
and
0 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/Slf4jLoggerProducer.java
0 → 100644
| @@ -0,0 +1,101 @@ | @@ -0,0 +1,101 @@ | ||
| 1 | +/* | ||
| 2 | + * Demoiselle Framework | ||
| 3 | + * Copyright (C) 2010 SERPRO | ||
| 4 | + * ---------------------------------------------------------------------------- | ||
| 5 | + * This file is part of Demoiselle Framework. | ||
| 6 | + * | ||
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
| 9 | + * as published by the Free Software Foundation. | ||
| 10 | + * | ||
| 11 | + * This program is distributed in the hope that it will be useful, | ||
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | + * GNU General Public License for more details. | ||
| 15 | + * | ||
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 20 | + * ---------------------------------------------------------------------------- | ||
| 21 | + * Este arquivo é parte do Framework Demoiselle. | ||
| 22 | + * | ||
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
| 25 | + * do Software Livre (FSF). | ||
| 26 | + * | ||
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
| 30 | + * para maiores detalhes. | ||
| 31 | + * | ||
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
| 36 | + */ | ||
| 37 | +package br.gov.frameworkdemoiselle.internal.producer; | ||
| 38 | + | ||
| 39 | +import java.io.Serializable; | ||
| 40 | + | ||
| 41 | +import javax.enterprise.inject.Default; | ||
| 42 | +import javax.enterprise.inject.Produces; | ||
| 43 | +import javax.enterprise.inject.spi.InjectionPoint; | ||
| 44 | + | ||
| 45 | +import org.slf4j.Logger; | ||
| 46 | + | ||
| 47 | +import br.gov.frameworkdemoiselle.DemoiselleException; | ||
| 48 | +import br.gov.frameworkdemoiselle.annotation.Name; | ||
| 49 | +import br.gov.frameworkdemoiselle.internal.proxy.Slf4jLoggerProxy; | ||
| 50 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
| 51 | +import br.gov.frameworkdemoiselle.util.Reflections; | ||
| 52 | + | ||
| 53 | +@Deprecated | ||
| 54 | +public class Slf4jLoggerProducer implements Serializable { | ||
| 55 | + | ||
| 56 | + private static final long serialVersionUID = 1L; | ||
| 57 | + | ||
| 58 | + @Default | ||
| 59 | + @Produces | ||
| 60 | + @Deprecated | ||
| 61 | + public Logger create(final InjectionPoint ip) { | ||
| 62 | + Class<?> type; | ||
| 63 | + | ||
| 64 | + if (ip != null && ip.getMember() != null) { | ||
| 65 | + type = ip.getMember().getDeclaringClass(); | ||
| 66 | + } else { | ||
| 67 | + type = Slf4jLoggerProducer.class; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + return create(type); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + @Name("") | ||
| 74 | + @Produces | ||
| 75 | + @Deprecated | ||
| 76 | + public Logger createNamed(final InjectionPoint ip) throws ClassNotFoundException { | ||
| 77 | + Class<?> type; | ||
| 78 | + | ||
| 79 | + try { | ||
| 80 | + String canonicalName = ip.getAnnotated().getAnnotation(Name.class).value(); | ||
| 81 | + type = Reflections.forName(canonicalName); | ||
| 82 | + | ||
| 83 | + } catch (ClassCastException cause) { | ||
| 84 | + // TODO Colocar a mensgaem apropriada mostrando como utilizar a anotação @AmbiguousQualifier corretamente | ||
| 85 | + // com a injeção de | ||
| 86 | + // Logger. | ||
| 87 | + throw new DemoiselleException(null, cause); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + return create(type); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + @Deprecated | ||
| 94 | + public static <T> Logger create(Class<T> type) { | ||
| 95 | + java.util.logging.Logger logger = Beans.getReference(java.util.logging.Logger.class); | ||
| 96 | + logger.warning("Para manter a compatibilidade com as futuras versões do Framework Demoiselle, utilize a injeção de " | ||
| 97 | + + java.util.logging.Logger.class.getName() + " ao invés de " + Logger.class.getName() + "."); | ||
| 98 | + | ||
| 99 | + return new Slf4jLoggerProxy(type); | ||
| 100 | + } | ||
| 101 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/Slf4jLoggerProxy.java
| @@ -54,6 +54,7 @@ import org.slf4j.Logger; | @@ -54,6 +54,7 @@ import org.slf4j.Logger; | ||
| 54 | import org.slf4j.LoggerFactory; | 54 | import org.slf4j.LoggerFactory; |
| 55 | import org.slf4j.Marker; | 55 | import org.slf4j.Marker; |
| 56 | 56 | ||
| 57 | +@Deprecated | ||
| 57 | public class Slf4jLoggerProxy implements Logger, Serializable { | 58 | public class Slf4jLoggerProxy implements Logger, Serializable { |
| 58 | 59 | ||
| 59 | private static final long serialVersionUID = 1L; | 60 | private static final long serialVersionUID = 1L; |