Commit 1154ae17b0d14ba2b8ae9c4ece9fbcbaac176f67
1 parent
c57c2964
Exists in
master
Mais ajustes no appender de mensagem padrão
Showing
4 changed files
with
121 additions
and
69 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConsoleMessageAppender.java
| ... | ... | @@ -1,52 +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.implementation; | |
| 38 | - | |
| 39 | -import static br.gov.frameworkdemoiselle.internal.implementation.StrategySelector.CORE_PRIORITY; | |
| 40 | -import br.gov.frameworkdemoiselle.annotation.Priority; | |
| 41 | -import br.gov.frameworkdemoiselle.message.Message; | |
| 42 | - | |
| 43 | -@Priority(CORE_PRIORITY) | |
| 44 | -public class ConsoleMessageAppender implements MessageAppender { | |
| 45 | - | |
| 46 | - private static final long serialVersionUID = 1L; | |
| 47 | - | |
| 48 | - @Override | |
| 49 | - public void append(Message message) { | |
| 50 | - System.out.println(message.getText()); | |
| 51 | - } | |
| 52 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/LoggerMessageAppender.java
0 → 100644
| ... | ... | @@ -0,0 +1,73 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package br.gov.frameworkdemoiselle.internal.implementation; | |
| 38 | + | |
| 39 | +import static br.gov.frameworkdemoiselle.internal.implementation.StrategySelector.CORE_PRIORITY; | |
| 40 | + | |
| 41 | +import javax.inject.Inject; | |
| 42 | + | |
| 43 | +import org.slf4j.Logger; | |
| 44 | + | |
| 45 | +import br.gov.frameworkdemoiselle.annotation.Priority; | |
| 46 | +import br.gov.frameworkdemoiselle.message.Message; | |
| 47 | + | |
| 48 | +@Priority(CORE_PRIORITY) | |
| 49 | +public class LoggerMessageAppender implements MessageAppender { | |
| 50 | + | |
| 51 | + private static final long serialVersionUID = 1L; | |
| 52 | + | |
| 53 | + @Inject | |
| 54 | + private Logger logger; | |
| 55 | + | |
| 56 | + @Override | |
| 57 | + public void append(Message message) { | |
| 58 | + String text = message.getText(); | |
| 59 | + | |
| 60 | + switch (message.getSeverity()) { | |
| 61 | + case INFO: | |
| 62 | + logger.info(text); | |
| 63 | + break; | |
| 64 | + | |
| 65 | + case WARN: | |
| 66 | + logger.warn(text); | |
| 67 | + break; | |
| 68 | + | |
| 69 | + default: | |
| 70 | + logger.error(text); | |
| 71 | + } | |
| 72 | + } | |
| 73 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/message/DefaultMessage.java
| ... | ... | @@ -36,8 +36,6 @@ |
| 36 | 36 | */ |
| 37 | 37 | package br.gov.frameworkdemoiselle.message; |
| 38 | 38 | |
| 39 | -import javax.enterprise.inject.Alternative; | |
| 40 | - | |
| 41 | 39 | import br.gov.frameworkdemoiselle.util.Beans; |
| 42 | 40 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 43 | 41 | import br.gov.frameworkdemoiselle.util.Strings; |
| ... | ... | @@ -45,7 +43,6 @@ import br.gov.frameworkdemoiselle.util.Strings; |
| 45 | 43 | /** |
| 46 | 44 | * @author SERPRO |
| 47 | 45 | */ |
| 48 | -@Alternative | |
| 49 | 46 | public class DefaultMessage implements Message { |
| 50 | 47 | |
| 51 | 48 | private final String originalText; |
| ... | ... | @@ -65,28 +62,27 @@ public class DefaultMessage implements Message { |
| 65 | 62 | this.severity = (severity == null ? DEFAULT_SEVERITY : severity); |
| 66 | 63 | this.params = params; |
| 67 | 64 | this.bundle = Beans.getReference(ResourceBundle.class); |
| 65 | + | |
| 66 | + initParsedText(); | |
| 68 | 67 | } |
| 69 | 68 | |
| 70 | 69 | public DefaultMessage(String text, Object... params) { |
| 71 | 70 | this(text, null, (Object[]) params); |
| 72 | 71 | } |
| 73 | 72 | |
| 74 | - public String getText() { | |
| 75 | - initParsedText(); | |
| 76 | - return parsedText; | |
| 77 | - } | |
| 78 | - | |
| 79 | 73 | private void initParsedText() { |
| 80 | - if (parsedText == null) { | |
| 81 | - if (Strings.isResourceBundleKeyFormat(originalText)) { | |
| 82 | - parsedText = bundle.getString(Strings.removeBraces(originalText)); | |
| 83 | - | |
| 84 | - } else if (originalText != null) { | |
| 85 | - parsedText = new String(originalText); | |
| 86 | - } | |
| 74 | + if (Strings.isResourceBundleKeyFormat(originalText)) { | |
| 75 | + parsedText = bundle.getString(Strings.removeBraces(originalText)); | |
| 87 | 76 | |
| 88 | - parsedText = Strings.getString(parsedText, params); | |
| 77 | + } else if (originalText != null) { | |
| 78 | + parsedText = new String(originalText); | |
| 89 | 79 | } |
| 80 | + | |
| 81 | + parsedText = Strings.getString(parsedText, params); | |
| 82 | + } | |
| 83 | + | |
| 84 | + public String getText() { | |
| 85 | + return parsedText; | |
| 90 | 86 | } |
| 91 | 87 | |
| 92 | 88 | public SeverityType getSeverity() { |
| ... | ... | @@ -95,7 +91,40 @@ public class DefaultMessage implements Message { |
| 95 | 91 | |
| 96 | 92 | @Override |
| 97 | 93 | public String toString() { |
| 98 | - initParsedText(); | |
| 99 | 94 | return Strings.toString(this); |
| 100 | 95 | } |
| 96 | + | |
| 97 | + @Override | |
| 98 | + public int hashCode() { | |
| 99 | + final int prime = 31; | |
| 100 | + int result = 1; | |
| 101 | + result = prime * result + ((parsedText == null) ? 0 : parsedText.hashCode()); | |
| 102 | + result = prime * result + ((severity == null) ? 0 : severity.hashCode()); | |
| 103 | + return result; | |
| 104 | + } | |
| 105 | + | |
| 106 | + @Override | |
| 107 | + public boolean equals(Object obj) { | |
| 108 | + if (this == obj) { | |
| 109 | + return true; | |
| 110 | + } | |
| 111 | + if (obj == null) { | |
| 112 | + return false; | |
| 113 | + } | |
| 114 | + if (getClass() != obj.getClass()) { | |
| 115 | + return false; | |
| 116 | + } | |
| 117 | + DefaultMessage other = (DefaultMessage) obj; | |
| 118 | + if (parsedText == null) { | |
| 119 | + if (other.parsedText != null) { | |
| 120 | + return false; | |
| 121 | + } | |
| 122 | + } else if (!parsedText.equals(other.parsedText)) { | |
| 123 | + return false; | |
| 124 | + } | |
| 125 | + if (severity != other.severity) { | |
| 126 | + return false; | |
| 127 | + } | |
| 128 | + return true; | |
| 129 | + } | |
| 101 | 130 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/message/MessageContext.java
| ... | ... | @@ -65,11 +65,13 @@ public interface MessageContext { |
| 65 | 65 | /** |
| 66 | 66 | * Returns all messages in the context. |
| 67 | 67 | */ |
| 68 | + @Deprecated | |
| 68 | 69 | List<Message> getMessages(); |
| 69 | 70 | |
| 70 | 71 | /** |
| 71 | 72 | * Clears the list of messages in the context. |
| 72 | 73 | */ |
| 74 | + @Deprecated | |
| 73 | 75 | void clear(); |
| 74 | 76 | |
| 75 | 77 | } | ... | ... |