Commit 4b5516e7d166e508597f4c66d56e9f68b281262a
1 parent
04970ec9
Exists in
master
FWK-202: Injeção de java.util.logging.Logger
Task-Url: https://demoiselle.atlassian.net/browse/FWK-202
Showing
30 changed files
with
628 additions
and
592 deletions
Show diff stats
impl/core/pom.xml
| ... | ... | @@ -34,7 +34,8 @@ |
| 34 | 34 | ou escreva para a Fundação do Software Livre (FSF) Inc., |
| 35 | 35 | 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 36 | 36 | --> |
| 37 | -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
| 37 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 38 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
| 38 | 39 | |
| 39 | 40 | <modelVersion>4.0.0</modelVersion> |
| 40 | 41 | |
| ... | ... | @@ -117,10 +118,6 @@ |
| 117 | 118 | <groupId>javax.validation</groupId> |
| 118 | 119 | </dependency> |
| 119 | 120 | <dependency> |
| 120 | - <groupId>org.slf4j</groupId> | |
| 121 | - <artifactId>slf4j-api</artifactId> | |
| 122 | - </dependency> | |
| 123 | - <dependency> | |
| 124 | 121 | <groupId>org.javassist</groupId> |
| 125 | 122 | <artifactId>javassist</artifactId> |
| 126 | 123 | </dependency> |
| ... | ... | @@ -129,6 +126,12 @@ |
| 129 | 126 | <artifactId>commons-configuration</artifactId> |
| 130 | 127 | </dependency> |
| 131 | 128 | |
| 129 | + <!-- @Deprecated --> | |
| 130 | + <dependency> | |
| 131 | + <groupId>org.slf4j</groupId> | |
| 132 | + <artifactId>slf4j-api</artifactId> | |
| 133 | + </dependency> | |
| 134 | + | |
| 132 | 135 | <!-- for tests --> |
| 133 | 136 | <dependency> |
| 134 | 137 | <groupId>junit</groupId> |
| ... | ... | @@ -143,7 +146,6 @@ |
| 143 | 146 | <dependency> |
| 144 | 147 | <groupId>org.jboss.arquillian.container</groupId> |
| 145 | 148 | <artifactId>arquillian-weld-se-embedded-1.1</artifactId> |
| 146 | -<!-- <version>1.0.0.CR7</version> --> | |
| 147 | 149 | <scope>test</scope> |
| 148 | 150 | </dependency> |
| 149 | 151 | <dependency> |
| ... | ... | @@ -156,11 +158,6 @@ |
| 156 | 158 | <artifactId>hibernate-validator</artifactId> |
| 157 | 159 | <scope>test</scope> |
| 158 | 160 | </dependency> |
| 159 | - <dependency> | |
| 160 | - <groupId>org.slf4j</groupId> | |
| 161 | - <artifactId>slf4j-log4j12</artifactId> | |
| 162 | - <scope>test</scope> | |
| 163 | - </dependency> | |
| 164 | 161 | </dependencies> |
| 165 | 162 | |
| 166 | 163 | <repositories> | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/exception/ExceptionHandlerInterceptor.java
| ... | ... | @@ -44,13 +44,12 @@ import java.util.Arrays; |
| 44 | 44 | import java.util.HashMap; |
| 45 | 45 | import java.util.List; |
| 46 | 46 | import java.util.Map; |
| 47 | +import java.util.logging.Logger; | |
| 47 | 48 | |
| 48 | 49 | import javax.interceptor.AroundInvoke; |
| 49 | 50 | import javax.interceptor.Interceptor; |
| 50 | 51 | import javax.interceptor.InvocationContext; |
| 51 | 52 | |
| 52 | -import org.slf4j.Logger; | |
| 53 | - | |
| 54 | 53 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 55 | 54 | import br.gov.frameworkdemoiselle.stereotype.Controller; |
| 56 | 55 | import br.gov.frameworkdemoiselle.util.Beans; |
| ... | ... | @@ -93,6 +92,9 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 93 | 92 | * } |
| 94 | 93 | * } |
| 95 | 94 | * |
| 95 | + * | |
| 96 | + * | |
| 97 | + * | |
| 96 | 98 | * </pre> |
| 97 | 99 | * |
| 98 | 100 | * </blockquote> |
| ... | ... | @@ -255,7 +257,7 @@ public class ExceptionHandlerInterceptor implements Serializable { |
| 255 | 257 | |
| 256 | 258 | private Logger getLogger() { |
| 257 | 259 | if (logger == null) { |
| 258 | - logger = Beans.getReference(Logger.class, new NameQualifier(ExceptionHandlerInterceptor.class.getName())); | |
| 260 | + logger = Beans.getReference(Logger.class, new NameQualifier("br.gov.frameworkdemoiselle.exception")); | |
| 259 | 261 | } |
| 260 | 262 | |
| 261 | 263 | return logger; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractLifecycleBootstrap.java
| ... | ... | @@ -42,6 +42,7 @@ import java.util.Collections; |
| 42 | 42 | import java.util.HashMap; |
| 43 | 43 | import java.util.Iterator; |
| 44 | 44 | import java.util.List; |
| 45 | +import java.util.logging.Logger; | |
| 45 | 46 | |
| 46 | 47 | import javax.enterprise.event.Observes; |
| 47 | 48 | import javax.enterprise.inject.spi.AnnotatedMethod; |
| ... | ... | @@ -49,8 +50,6 @@ import javax.enterprise.inject.spi.AnnotatedType; |
| 49 | 50 | import javax.enterprise.inject.spi.Extension; |
| 50 | 51 | import javax.enterprise.inject.spi.ProcessAnnotatedType; |
| 51 | 52 | |
| 52 | -import org.slf4j.Logger; | |
| 53 | - | |
| 54 | 53 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 55 | 54 | import br.gov.frameworkdemoiselle.context.ConversationContext; |
| 56 | 55 | import br.gov.frameworkdemoiselle.context.CustomContext; |
| ... | ... | @@ -73,11 +72,11 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement |
| 73 | 72 | .synchronizedList(new ArrayList<AnnotatedMethodProcessor>()); |
| 74 | 73 | |
| 75 | 74 | private transient static ResourceBundle bundle; |
| 76 | - | |
| 75 | + | |
| 77 | 76 | private boolean registered = false; |
| 78 | - | |
| 77 | + | |
| 79 | 78 | private HashMap<String, Boolean> startedContextHere = new HashMap<String, Boolean>(); |
| 80 | - | |
| 79 | + | |
| 81 | 80 | private transient CustomContext backupContext = null; |
| 82 | 81 | |
| 83 | 82 | protected abstract Logger getLogger(); |
| ... | ... | @@ -115,13 +114,13 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement |
| 115 | 114 | |
| 116 | 115 | @SuppressWarnings({ "unchecked", "rawtypes" }) |
| 117 | 116 | protected synchronized void proccessEvent() { |
| 118 | - getLogger().debug(getBundle().getString("executing-all", getAnnotationClass().getSimpleName())); | |
| 117 | + getLogger().fine(getBundle().getString("executing-all", getAnnotationClass().getSimpleName())); | |
| 119 | 118 | |
| 120 | 119 | Collections.sort(processors); |
| 121 | 120 | Exception failure = null; |
| 122 | - | |
| 121 | + | |
| 123 | 122 | startContexts(); |
| 124 | - | |
| 123 | + | |
| 125 | 124 | for (Iterator<AnnotatedMethodProcessor> iter = processors.iterator(); iter.hasNext();) { |
| 126 | 125 | AnnotatedMethodProcessor<?> processor = iter.next(); |
| 127 | 126 | |
| ... | ... | @@ -138,49 +137,48 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement |
| 138 | 137 | failure = cause; |
| 139 | 138 | } |
| 140 | 139 | } |
| 141 | - | |
| 140 | + | |
| 142 | 141 | stopContexts(); |
| 143 | 142 | |
| 144 | 143 | if (failure != null) { |
| 145 | 144 | throw new DemoiselleException(failure); |
| 146 | 145 | } |
| 147 | 146 | } |
| 148 | - | |
| 149 | - private void startContexts(){ | |
| 150 | - if (!registered){ | |
| 147 | + | |
| 148 | + private void startContexts() { | |
| 149 | + if (!registered) { | |
| 151 | 150 | RequestContext requestContext = Beans.getReference(RequestContext.class); |
| 152 | 151 | SessionContext sessionContext = Beans.getReference(SessionContext.class); |
| 153 | 152 | ViewContext viewContext = Beans.getReference(ViewContext.class); |
| 154 | 153 | ConversationContext conversationContext = Beans.getReference(ConversationContext.class); |
| 155 | - | |
| 156 | - if (requestContext!=null){ | |
| 154 | + | |
| 155 | + if (requestContext != null) { | |
| 157 | 156 | startedContextHere.put("request", requestContext.activate()); |
| 158 | 157 | } |
| 159 | - | |
| 160 | - if (sessionContext!=null){ | |
| 158 | + | |
| 159 | + if (sessionContext != null) { | |
| 161 | 160 | startedContextHere.put("session", sessionContext.activate()); |
| 162 | 161 | } |
| 163 | - | |
| 164 | - | |
| 165 | - if (conversationContext!=null){ | |
| 162 | + | |
| 163 | + if (conversationContext != null) { | |
| 166 | 164 | startedContextHere.put("conversation", conversationContext.activate()); |
| 167 | 165 | } |
| 168 | - | |
| 169 | - //Contexto temporário de visão precisa de tratamento especial | |
| 170 | - //para evitar conflito com o contexto presente na extensão demoiselle-jsf | |
| 171 | - if (viewContext!=null){ | |
| 172 | - if (TemporaryViewContextImpl.class.isInstance(viewContext)){ | |
| 166 | + | |
| 167 | + // Contexto temporário de visão precisa de tratamento especial | |
| 168 | + // para evitar conflito com o contexto presente na extensão demoiselle-jsf | |
| 169 | + if (viewContext != null) { | |
| 170 | + if (TemporaryViewContextImpl.class.isInstance(viewContext)) { | |
| 173 | 171 | startedContextHere.put("view", viewContext.activate()); |
| 174 | - } | |
| 175 | - else{ | |
| 176 | - //Precisamos desativar temporariamente o contexto | |
| 177 | - if (viewContext.isActive()){ | |
| 172 | + } else { | |
| 173 | + // Precisamos desativar temporariamente o contexto | |
| 174 | + if (viewContext.isActive()) { | |
| 178 | 175 | backupContext = viewContext; |
| 179 | 176 | viewContext.deactivate(); |
| 180 | - | |
| 181 | - CustomContextBootstrap customContextBootstrap = Beans.getReference(CustomContextBootstrap.class); | |
| 182 | - for (CustomContext customContext : customContextBootstrap.getCustomContexts()){ | |
| 183 | - if ( TemporaryViewContextImpl.class.isInstance(customContext) ){ | |
| 177 | + | |
| 178 | + CustomContextBootstrap customContextBootstrap = Beans | |
| 179 | + .getReference(CustomContextBootstrap.class); | |
| 180 | + for (CustomContext customContext : customContextBootstrap.getCustomContexts()) { | |
| 181 | + if (TemporaryViewContextImpl.class.isInstance(customContext)) { | |
| 184 | 182 | startedContextHere.put("view", customContext.activate()); |
| 185 | 183 | break; |
| 186 | 184 | } |
| ... | ... | @@ -188,37 +186,37 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement |
| 188 | 186 | } |
| 189 | 187 | } |
| 190 | 188 | } |
| 191 | - | |
| 189 | + | |
| 192 | 190 | registered = true; |
| 193 | 191 | } |
| 194 | 192 | } |
| 195 | - | |
| 196 | - private void stopContexts(){ | |
| 197 | - if (registered){ | |
| 193 | + | |
| 194 | + private void stopContexts() { | |
| 195 | + if (registered) { | |
| 198 | 196 | RequestContext requestContext = Beans.getReference(RequestContext.class); |
| 199 | 197 | SessionContext sessionContext = Beans.getReference(SessionContext.class); |
| 200 | 198 | ViewContext viewContext = Beans.getReference(ViewContext.class); |
| 201 | 199 | ConversationContext conversationContext = Beans.getReference(ConversationContext.class); |
| 202 | - | |
| 203 | - if (requestContext!=null && Boolean.TRUE.equals(startedContextHere.get("request"))){ | |
| 200 | + | |
| 201 | + if (requestContext != null && Boolean.TRUE.equals(startedContextHere.get("request"))) { | |
| 204 | 202 | requestContext.deactivate(); |
| 205 | 203 | } |
| 206 | - | |
| 207 | - if (sessionContext!=null && Boolean.TRUE.equals(startedContextHere.get("session"))){ | |
| 204 | + | |
| 205 | + if (sessionContext != null && Boolean.TRUE.equals(startedContextHere.get("session"))) { | |
| 208 | 206 | sessionContext.deactivate(); |
| 209 | 207 | } |
| 210 | - | |
| 211 | - if (conversationContext!=null && Boolean.TRUE.equals(startedContextHere.get("conversation"))){ | |
| 208 | + | |
| 209 | + if (conversationContext != null && Boolean.TRUE.equals(startedContextHere.get("conversation"))) { | |
| 212 | 210 | conversationContext.deactivate(); |
| 213 | 211 | } |
| 214 | - | |
| 215 | - //Contexto temporário de visão precisa de tratamento especial | |
| 216 | - //para evitar conflito com o contexto presente na extensão demoiselle-jsf | |
| 217 | - if (viewContext!=null){ | |
| 218 | - if (TemporaryViewContextImpl.class.isInstance(viewContext) && startedContextHere.get("view")){ | |
| 212 | + | |
| 213 | + // Contexto temporário de visão precisa de tratamento especial | |
| 214 | + // para evitar conflito com o contexto presente na extensão demoiselle-jsf | |
| 215 | + if (viewContext != null) { | |
| 216 | + if (TemporaryViewContextImpl.class.isInstance(viewContext) && startedContextHere.get("view")) { | |
| 219 | 217 | viewContext.deactivate(); |
| 220 | - | |
| 221 | - if (backupContext!=null){ | |
| 218 | + | |
| 219 | + if (backupContext != null) { | |
| 222 | 220 | backupContext.activate(); |
| 223 | 221 | backupContext = null; |
| 224 | 222 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractStrategyBootstrap.java
| ... | ... | @@ -3,14 +3,13 @@ package br.gov.frameworkdemoiselle.internal.bootstrap; |
| 3 | 3 | import java.util.Collection; |
| 4 | 4 | import java.util.Collections; |
| 5 | 5 | import java.util.HashSet; |
| 6 | +import java.util.logging.Logger; | |
| 6 | 7 | |
| 7 | 8 | import javax.enterprise.event.Observes; |
| 8 | 9 | import javax.enterprise.inject.spi.AnnotatedType; |
| 9 | 10 | import javax.enterprise.inject.spi.Extension; |
| 10 | 11 | import javax.enterprise.inject.spi.ProcessAnnotatedType; |
| 11 | 12 | |
| 12 | -import org.slf4j.Logger; | |
| 13 | - | |
| 14 | 13 | import br.gov.frameworkdemoiselle.util.Reflections; |
| 15 | 14 | |
| 16 | 15 | public abstract class AbstractStrategyBootstrap<I> implements Extension { | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ConfigurationBootstrap.java
| ... | ... | @@ -42,6 +42,7 @@ import java.util.Collections; |
| 42 | 42 | import java.util.HashMap; |
| 43 | 43 | import java.util.List; |
| 44 | 44 | import java.util.Map; |
| 45 | +import java.util.logging.Logger; | |
| 45 | 46 | |
| 46 | 47 | import javassist.ClassPool; |
| 47 | 48 | import javassist.CtClass; |
| ... | ... | @@ -55,8 +56,6 @@ import javax.enterprise.inject.spi.AnnotatedType; |
| 55 | 56 | import javax.enterprise.inject.spi.BeanManager; |
| 56 | 57 | import javax.enterprise.inject.spi.ProcessAnnotatedType; |
| 57 | 58 | |
| 58 | -import org.slf4j.Logger; | |
| 59 | - | |
| 60 | 59 | import br.gov.frameworkdemoiselle.configuration.Configuration; |
| 61 | 60 | import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; |
| 62 | 61 | import br.gov.frameworkdemoiselle.internal.implementation.ConfigurationImpl; |
| ... | ... | @@ -139,7 +138,7 @@ public class ConfigurationBootstrap extends AbstractStrategyBootstrap<Configurat |
| 139 | 138 | @Override |
| 140 | 139 | protected Logger getLogger() { |
| 141 | 140 | if (logger == null) { |
| 142 | - logger = LoggerProducer.create(ConfigurationBootstrap.class); | |
| 141 | + logger = LoggerProducer.create("br.gov.frameworkdemoiselle.configuration"); | |
| 143 | 142 | } |
| 144 | 143 | |
| 145 | 144 | return logger; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CoreBootstrap.java
| ... | ... | @@ -37,6 +37,7 @@ |
| 37 | 37 | package br.gov.frameworkdemoiselle.internal.bootstrap; |
| 38 | 38 | |
| 39 | 39 | import java.util.Locale; |
| 40 | +import java.util.logging.Logger; | |
| 40 | 41 | |
| 41 | 42 | import javax.enterprise.event.Observes; |
| 42 | 43 | import javax.enterprise.inject.spi.AfterDeploymentValidation; |
| ... | ... | @@ -45,8 +46,6 @@ import javax.enterprise.inject.spi.BeforeBeanDiscovery; |
| 45 | 46 | import javax.enterprise.inject.spi.BeforeShutdown; |
| 46 | 47 | import javax.enterprise.inject.spi.Extension; |
| 47 | 48 | |
| 48 | -import org.slf4j.Logger; | |
| 49 | - | |
| 50 | 49 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
| 51 | 50 | import br.gov.frameworkdemoiselle.util.Beans; |
| 52 | 51 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| ... | ... | @@ -56,10 +55,10 @@ public class CoreBootstrap implements Extension { |
| 56 | 55 | private Logger logger; |
| 57 | 56 | |
| 58 | 57 | private transient ResourceBundle bundle; |
| 59 | - | |
| 58 | + | |
| 60 | 59 | private Logger getLogger() { |
| 61 | 60 | if (this.logger == null) { |
| 62 | - this.logger = LoggerProducer.create(CoreBootstrap.class); | |
| 61 | + this.logger = LoggerProducer.create("br.gov.frameworkdemoiselle.lifecycle"); | |
| 63 | 62 | } |
| 64 | 63 | |
| 65 | 64 | return this.logger; |
| ... | ... | @@ -77,14 +76,14 @@ public class CoreBootstrap implements Extension { |
| 77 | 76 | getLogger().info(getBundle().getString("engine-on")); |
| 78 | 77 | |
| 79 | 78 | Beans.setBeanManager(beanManager); |
| 80 | - getLogger().trace(getBundle().getString("setting-up-bean-manager", Beans.class.getCanonicalName())); | |
| 79 | + getLogger().finer(getBundle().getString("setting-up-bean-manager", Beans.class.getCanonicalName())); | |
| 81 | 80 | } |
| 82 | - | |
| 81 | + | |
| 83 | 82 | public void takeOff(@Observes final AfterDeploymentValidation event) { |
| 84 | - getLogger().trace(getBundle().getString("taking-off")); | |
| 83 | + getLogger().fine(getBundle().getString("taking-off")); | |
| 85 | 84 | } |
| 86 | 85 | |
| 87 | 86 | public void engineOff(@Observes final BeforeShutdown event) { |
| 88 | - getLogger().trace(getBundle().getString("engine-off")); | |
| 87 | + getLogger().fine(getBundle().getString("engine-off")); | |
| 89 | 88 | } |
| 90 | 89 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ShutdownBootstrap.java
| ... | ... | @@ -36,9 +36,9 @@ |
| 36 | 36 | */ |
| 37 | 37 | package br.gov.frameworkdemoiselle.internal.bootstrap; |
| 38 | 38 | |
| 39 | -import javax.enterprise.event.Observes; | |
| 39 | +import java.util.logging.Logger; | |
| 40 | 40 | |
| 41 | -import org.slf4j.Logger; | |
| 41 | +import javax.enterprise.event.Observes; | |
| 42 | 42 | |
| 43 | 43 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
| 44 | 44 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; |
| ... | ... | @@ -54,7 +54,7 @@ public class ShutdownBootstrap extends AbstractLifecycleBootstrap<Shutdown> { |
| 54 | 54 | @Override |
| 55 | 55 | protected Logger getLogger() { |
| 56 | 56 | if (logger == null) { |
| 57 | - logger = LoggerProducer.create(ShutdownBootstrap.class); | |
| 57 | + logger = LoggerProducer.create("br.gov.frameworkdemoiselle.lifecycle"); | |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | return logger; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/StartupBootstrap.java
| ... | ... | @@ -36,9 +36,9 @@ |
| 36 | 36 | */ |
| 37 | 37 | package br.gov.frameworkdemoiselle.internal.bootstrap; |
| 38 | 38 | |
| 39 | -import javax.enterprise.event.Observes; | |
| 39 | +import java.util.logging.Logger; | |
| 40 | 40 | |
| 41 | -import org.slf4j.Logger; | |
| 41 | +import javax.enterprise.event.Observes; | |
| 42 | 42 | |
| 43 | 43 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
| 44 | 44 | import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess; |
| ... | ... | @@ -54,7 +54,7 @@ public class StartupBootstrap extends AbstractLifecycleBootstrap<Startup> { |
| 54 | 54 | @Override |
| 55 | 55 | protected Logger getLogger() { |
| 56 | 56 | if (logger == null) { |
| 57 | - logger = LoggerProducer.create(StartupBootstrap.class); | |
| 57 | + logger = LoggerProducer.create("br.gov.frameworkdemoiselle.lifecycle"); | |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | return logger; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractCustomContext.java
| ... | ... | @@ -38,6 +38,7 @@ package br.gov.frameworkdemoiselle.internal.context; |
| 38 | 38 | |
| 39 | 39 | import java.lang.annotation.Annotation; |
| 40 | 40 | import java.util.Locale; |
| 41 | +import java.util.logging.Logger; | |
| 41 | 42 | |
| 42 | 43 | import javax.enterprise.context.ContextNotActiveException; |
| 43 | 44 | import javax.enterprise.context.spi.Context; |
| ... | ... | @@ -46,8 +47,6 @@ import javax.enterprise.context.spi.CreationalContext; |
| 46 | 47 | import javax.enterprise.inject.spi.Bean; |
| 47 | 48 | import javax.enterprise.inject.spi.BeanManager; |
| 48 | 49 | |
| 49 | -import org.slf4j.Logger; | |
| 50 | - | |
| 51 | 50 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 52 | 51 | import br.gov.frameworkdemoiselle.context.CustomContext; |
| 53 | 52 | import br.gov.frameworkdemoiselle.internal.bootstrap.CustomContextBootstrap; |
| ... | ... | @@ -60,9 +59,9 @@ public abstract class AbstractCustomContext implements CustomContext { |
| 60 | 59 | private boolean active; |
| 61 | 60 | |
| 62 | 61 | private final Class<? extends Annotation> scope; |
| 63 | - | |
| 62 | + | |
| 64 | 63 | private transient Logger logger; |
| 65 | - | |
| 64 | + | |
| 66 | 65 | private transient ResourceBundle bundle; |
| 67 | 66 | |
| 68 | 67 | protected AbstractCustomContext(final Class<? extends Annotation> scope) { |
| ... | ... | @@ -71,7 +70,7 @@ public abstract class AbstractCustomContext implements CustomContext { |
| 71 | 70 | } |
| 72 | 71 | |
| 73 | 72 | protected abstract BeanStore getStore(); |
| 74 | - | |
| 73 | + | |
| 75 | 74 | protected abstract boolean isStoreInitialized(); |
| 76 | 75 | |
| 77 | 76 | @Override |
| ... | ... | @@ -90,17 +89,16 @@ public abstract class AbstractCustomContext implements CustomContext { |
| 90 | 89 | |
| 91 | 90 | String id = getContextualStore().putIfAbsentAndGetId(contextual); |
| 92 | 91 | BeanStore store = getStore(); |
| 93 | - if (store!=null){ | |
| 92 | + if (store != null) { | |
| 94 | 93 | if (store.contains(id)) { |
| 95 | 94 | instance = (T) store.getInstance(id); |
| 96 | - } | |
| 97 | - else if (creationalContext!=null){ | |
| 95 | + } else if (creationalContext != null) { | |
| 98 | 96 | instance = contextual.create(creationalContext); |
| 99 | - store.put(id, instance,creationalContext); | |
| 97 | + store.put(id, instance, creationalContext); | |
| 100 | 98 | } |
| 101 | - } | |
| 102 | - else{ | |
| 103 | - throw new DemoiselleException(getBundle().getString("store-not-found" , ((Bean<?>)contextual).getBeanClass().getName() , getScope().getName())); | |
| 99 | + } else { | |
| 100 | + throw new DemoiselleException(getBundle().getString("store-not-found", | |
| 101 | + ((Bean<?>) contextual).getBeanClass().getName(), getScope().getName())); | |
| 104 | 102 | } |
| 105 | 103 | |
| 106 | 104 | return instance; |
| ... | ... | @@ -114,34 +112,39 @@ public abstract class AbstractCustomContext implements CustomContext { |
| 114 | 112 | @Override |
| 115 | 113 | public boolean activate() { |
| 116 | 114 | boolean success = false; |
| 117 | - | |
| 118 | - if (!this.active){ | |
| 115 | + | |
| 116 | + if (!this.active) { | |
| 119 | 117 | BeanManager beanManager = Beans.getBeanManager(); |
| 120 | - if (beanManager!=null){ | |
| 121 | - try{ | |
| 118 | + if (beanManager != null) { | |
| 119 | + try { | |
| 122 | 120 | Context ctx = beanManager.getContext(this.getScope()); |
| 123 | - if (ctx!=null){ | |
| 124 | - getLogger().trace( getBundle().getString("custom-context-already-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() , ctx.getClass().getCanonicalName() ) ); | |
| 121 | + if (ctx != null) { | |
| 122 | + getLogger().finest( | |
| 123 | + getBundle().getString("custom-context-already-activated", | |
| 124 | + this.getClass().getCanonicalName(), this.getScope().getSimpleName(), | |
| 125 | + ctx.getClass().getCanonicalName())); | |
| 125 | 126 | } |
| 126 | - } | |
| 127 | - catch(ContextNotActiveException ce){ | |
| 127 | + } catch (ContextNotActiveException ce) { | |
| 128 | 128 | success = this.active = true; |
| 129 | - getLogger().trace( getBundle().getString("custom-context-was-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); | |
| 129 | + getLogger().finest( | |
| 130 | + getBundle().getString("custom-context-was-activated", this.getClass().getCanonicalName(), | |
| 131 | + this.getScope().getSimpleName())); | |
| 130 | 132 | } |
| 131 | - } | |
| 132 | - else{ | |
| 133 | + } else { | |
| 133 | 134 | success = this.active = true; |
| 134 | - getLogger().trace( getBundle().getString("custom-context-was-activated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); | |
| 135 | + getLogger().finer( | |
| 136 | + getBundle().getString("custom-context-was-activated", this.getClass().getCanonicalName(), | |
| 137 | + this.getScope().getSimpleName())); | |
| 135 | 138 | } |
| 136 | 139 | } |
| 137 | - | |
| 140 | + | |
| 138 | 141 | return success; |
| 139 | 142 | } |
| 140 | - | |
| 143 | + | |
| 141 | 144 | @Override |
| 142 | - public void deactivate(){ | |
| 143 | - if (this.active){ | |
| 144 | - if (isStoreInitialized()){ | |
| 145 | + public void deactivate() { | |
| 146 | + if (this.active) { | |
| 147 | + if (isStoreInitialized()) { | |
| 145 | 148 | clearInstances(); |
| 146 | 149 | |
| 147 | 150 | getStore().clear(); |
| ... | ... | @@ -152,26 +155,27 @@ public abstract class AbstractCustomContext implements CustomContext { |
| 152 | 155 | |
| 153 | 156 | Logger logger = getLogger(); |
| 154 | 157 | ResourceBundle bundle = getBundle(); |
| 155 | - logger.trace( bundle.getString("custom-context-was-deactivated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); | |
| 158 | + logger.finer(bundle.getString("custom-context-was-deactivated", this.getClass().getCanonicalName(), this | |
| 159 | + .getScope().getSimpleName())); | |
| 156 | 160 | } |
| 157 | 161 | } |
| 158 | - | |
| 162 | + | |
| 159 | 163 | @SuppressWarnings({ "rawtypes", "unchecked" }) |
| 160 | - public void clearInstances(){ | |
| 164 | + public void clearInstances() { | |
| 161 | 165 | BeanStore store = getStore(); |
| 162 | - if (store!=null){ | |
| 163 | - for (String id : store){ | |
| 166 | + if (store != null) { | |
| 167 | + for (String id : store) { | |
| 164 | 168 | Contextual contextual = getContextualStore().getContextual(id); |
| 165 | 169 | Object instance = store.getInstance(id); |
| 166 | 170 | CreationalContext creationalContext = store.getCreationalContext(id); |
| 167 | - | |
| 168 | - if (contextual!=null && instance!=null){ | |
| 171 | + | |
| 172 | + if (contextual != null && instance != null) { | |
| 169 | 173 | contextual.destroy(instance, creationalContext); |
| 170 | 174 | } |
| 171 | 175 | } |
| 172 | 176 | } |
| 173 | 177 | } |
| 174 | - | |
| 178 | + | |
| 175 | 179 | @Override |
| 176 | 180 | public Class<? extends Annotation> getScope() { |
| 177 | 181 | return this.scope; |
| ... | ... | @@ -180,39 +184,39 @@ public abstract class AbstractCustomContext implements CustomContext { |
| 180 | 184 | protected static BeanStore createStore() { |
| 181 | 185 | return new BeanStore(); |
| 182 | 186 | } |
| 183 | - | |
| 187 | + | |
| 184 | 188 | protected static ContextualStore createContextualStore() { |
| 185 | 189 | return new ContextualStore(); |
| 186 | 190 | } |
| 187 | - | |
| 188 | - private ResourceBundle getBundle(){ | |
| 189 | - if (bundle==null){ | |
| 191 | + | |
| 192 | + private ResourceBundle getBundle() { | |
| 193 | + if (bundle == null) { | |
| 190 | 194 | bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); |
| 191 | 195 | } |
| 192 | - | |
| 196 | + | |
| 193 | 197 | return bundle; |
| 194 | 198 | } |
| 195 | - | |
| 196 | - private Logger getLogger(){ | |
| 197 | - if (logger==null){ | |
| 198 | - logger = LoggerProducer.create(this.getClass()); | |
| 199 | + | |
| 200 | + private Logger getLogger() { | |
| 201 | + if (logger == null) { | |
| 202 | + logger = LoggerProducer.create("br.gov.frameworkdemoiselle.context"); | |
| 199 | 203 | } |
| 200 | - | |
| 204 | + | |
| 201 | 205 | return logger; |
| 202 | 206 | } |
| 203 | - | |
| 204 | - protected ContextualStore getContextualStore(){ | |
| 207 | + | |
| 208 | + protected ContextualStore getContextualStore() { | |
| 205 | 209 | CustomContextBootstrap bootstrap = Beans.getReference(CustomContextBootstrap.class); |
| 206 | 210 | return bootstrap.getContextualStore(); |
| 207 | 211 | } |
| 208 | - | |
| 212 | + | |
| 209 | 213 | @Override |
| 210 | 214 | public boolean equals(Object obj) { |
| 211 | 215 | if (this == obj) |
| 212 | 216 | return true; |
| 213 | 217 | if (obj == null) |
| 214 | 218 | return false; |
| 215 | - if ( !this.getClass().equals(obj.getClass()) ) | |
| 219 | + if (!this.getClass().equals(obj.getClass())) | |
| 216 | 220 | return false; |
| 217 | 221 | AbstractCustomContext other = (AbstractCustomContext) obj; |
| 218 | 222 | if (scope == null) { | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContextProducer.java
| ... | ... | @@ -51,6 +51,7 @@ package br.gov.frameworkdemoiselle.internal.context; |
| 51 | 51 | import java.util.ArrayList; |
| 52 | 52 | import java.util.List; |
| 53 | 53 | import java.util.Locale; |
| 54 | +import java.util.logging.Logger; | |
| 54 | 55 | |
| 55 | 56 | import javax.annotation.PreDestroy; |
| 56 | 57 | import javax.enterprise.context.ApplicationScoped; |
| ... | ... | @@ -58,8 +59,6 @@ import javax.enterprise.inject.Produces; |
| 58 | 59 | import javax.enterprise.inject.spi.AfterBeanDiscovery; |
| 59 | 60 | import javax.enterprise.inject.spi.InjectionPoint; |
| 60 | 61 | |
| 61 | -import org.slf4j.Logger; | |
| 62 | - | |
| 63 | 62 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 64 | 63 | import br.gov.frameworkdemoiselle.context.ConversationContext; |
| 65 | 64 | import br.gov.frameworkdemoiselle.context.CustomContext; |
| ... | ... | @@ -74,37 +73,38 @@ import br.gov.frameworkdemoiselle.util.Beans; |
| 74 | 73 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 75 | 74 | |
| 76 | 75 | /** |
| 77 | - * Produces instances of {@link CustomContext} to control contexts not activated | |
| 78 | - * by the container | |
| 76 | + * Produces instances of {@link CustomContext} to control contexts not activated by the container | |
| 79 | 77 | * |
| 80 | 78 | * @author serpro |
| 81 | - * | |
| 82 | 79 | */ |
| 83 | 80 | @ApplicationScoped |
| 84 | 81 | public class CustomContextProducer { |
| 85 | - | |
| 82 | + | |
| 86 | 83 | private Logger logger; |
| 87 | 84 | |
| 88 | 85 | private transient ResourceBundle bundle; |
| 89 | - | |
| 86 | + | |
| 90 | 87 | /** |
| 91 | - * <p>Store a context into this producer. The context must have | |
| 92 | - * been registered into CDI (unsing {@link AfterBeanDiscovery#addContext(javax.enterprise.context.spi.Context context)}) by a portable extension, | |
| 93 | - * this method will not do this.</p> | |
| 94 | - * | |
| 95 | - * <p>This producer can only produce contexts registered through this method.</p> | |
| 96 | - * | |
| 88 | + * <p> | |
| 89 | + * Store a context into this producer. The context must have been registered into CDI (unsing | |
| 90 | + * {@link AfterBeanDiscovery#addContext(javax.enterprise.context.spi.Context context)}) by a portable extension, | |
| 91 | + * this method will not do this. | |
| 92 | + * </p> | |
| 93 | + * <p> | |
| 94 | + * This producer can only produce contexts registered through this method. | |
| 95 | + * </p> | |
| 97 | 96 | */ |
| 98 | - public void addRegisteredContext(CustomContext context){ | |
| 97 | + public void addRegisteredContext(CustomContext context) { | |
| 99 | 98 | Logger logger = getLogger(); |
| 100 | 99 | ResourceBundle bundle = getBundle(); |
| 101 | - | |
| 102 | - if (!getContexts().contains(context)){ | |
| 100 | + | |
| 101 | + if (!getContexts().contains(context)) { | |
| 103 | 102 | getContexts().add(context); |
| 104 | - logger.trace( bundle.getString("bootstrap-context-added", context.getClass().getCanonicalName() , context.getScope().getSimpleName() ) ); | |
| 105 | - } | |
| 106 | - else{ | |
| 107 | - logger.warn( bundle.getString("bootstrap-context-already-managed", context.getClass().getCanonicalName() , context.getScope().getSimpleName() ) ); | |
| 103 | + logger.finest(bundle.getString("bootstrap-context-added", context.getClass().getCanonicalName(), context | |
| 104 | + .getScope().getSimpleName())); | |
| 105 | + } else { | |
| 106 | + logger.finest(bundle.getString("bootstrap-context-already-managed", context.getClass().getCanonicalName(), | |
| 107 | + context.getScope().getSimpleName())); | |
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
| ... | ... | @@ -112,140 +112,138 @@ public class CustomContextProducer { |
| 112 | 112 | * Deactivates all registered contexts and clear the context collection |
| 113 | 113 | */ |
| 114 | 114 | @PreDestroy |
| 115 | - public void closeContexts(){ | |
| 116 | - //Desativa todos os contextos registrados. | |
| 117 | - for (CustomContext context : getContexts()){ | |
| 115 | + public void closeContexts() { | |
| 116 | + // Desativa todos os contextos registrados. | |
| 117 | + for (CustomContext context : getContexts()) { | |
| 118 | 118 | context.deactivate(); |
| 119 | 119 | } |
| 120 | - | |
| 120 | + | |
| 121 | 121 | getContexts().clear(); |
| 122 | 122 | } |
| 123 | - | |
| 124 | - private List<CustomContext> getContexts(){ | |
| 125 | - /* The demoiselle-core CustomContextBootstrap class creates default contexts for the main | |
| 126 | - * scopes of an application (request, session and conversation) and some custom contexts | |
| 127 | - * (view and static). This method injects a reference to the CustomContextBootstrap to obtain those | |
| 128 | - * contexts. Also any context registered after application start-up will be obtained by this method. */ | |
| 129 | - | |
| 123 | + | |
| 124 | + private List<CustomContext> getContexts() { | |
| 125 | + /* | |
| 126 | + * The demoiselle-core CustomContextBootstrap class creates default contexts for the main scopes of an | |
| 127 | + * application (request, session and conversation) and some custom contexts (view and static). This method | |
| 128 | + * injects a reference to the CustomContextBootstrap to obtain those contexts. Also any context registered after | |
| 129 | + * application start-up will be obtained by this method. | |
| 130 | + */ | |
| 131 | + | |
| 130 | 132 | CustomContextBootstrap contextBootstrap = Beans.getReference(CustomContextBootstrap.class); |
| 131 | 133 | return contextBootstrap.getCustomContexts(); |
| 132 | 134 | } |
| 133 | - | |
| 134 | - /////////////PRODUCERS/////////////////// | |
| 135 | - | |
| 135 | + | |
| 136 | + // ///////////PRODUCERS/////////////////// | |
| 137 | + | |
| 136 | 138 | @Produces |
| 137 | - protected RequestContext getRequestContext(InjectionPoint ip){ | |
| 138 | - if (ip!=null){ | |
| 139 | + protected RequestContext getRequestContext(InjectionPoint ip) { | |
| 140 | + if (ip != null) { | |
| 139 | 141 | return getContext(ip); |
| 140 | - } | |
| 141 | - else{ | |
| 142 | + } else { | |
| 142 | 143 | return getContext(RequestContext.class); |
| 143 | 144 | } |
| 144 | 145 | } |
| 145 | - | |
| 146 | + | |
| 146 | 147 | @Produces |
| 147 | - protected SessionContext getSessionContext(InjectionPoint ip){ | |
| 148 | - if (ip!=null){ | |
| 148 | + protected SessionContext getSessionContext(InjectionPoint ip) { | |
| 149 | + if (ip != null) { | |
| 149 | 150 | return getContext(ip); |
| 150 | - } | |
| 151 | - else{ | |
| 151 | + } else { | |
| 152 | 152 | return getContext(SessionContext.class); |
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | - | |
| 155 | + | |
| 156 | 156 | @Produces |
| 157 | - protected ViewContext getViewContext(InjectionPoint ip){ | |
| 158 | - if (ip!=null){ | |
| 157 | + protected ViewContext getViewContext(InjectionPoint ip) { | |
| 158 | + if (ip != null) { | |
| 159 | 159 | return getContext(ip); |
| 160 | - } | |
| 161 | - else{ | |
| 160 | + } else { | |
| 162 | 161 | return getContext(ViewContext.class); |
| 163 | 162 | } |
| 164 | 163 | } |
| 165 | - | |
| 164 | + | |
| 166 | 165 | @Produces |
| 167 | - protected StaticContext getStaticContext(InjectionPoint ip){ | |
| 168 | - if (ip!=null){ | |
| 166 | + protected StaticContext getStaticContext(InjectionPoint ip) { | |
| 167 | + if (ip != null) { | |
| 169 | 168 | return getContext(ip); |
| 170 | - } | |
| 171 | - else{ | |
| 169 | + } else { | |
| 172 | 170 | return getContext(StaticContext.class); |
| 173 | 171 | } |
| 174 | 172 | } |
| 175 | - | |
| 173 | + | |
| 176 | 174 | @Produces |
| 177 | - protected ConversationContext getConversationContext(InjectionPoint ip){ | |
| 178 | - if (ip!=null){ | |
| 175 | + protected ConversationContext getConversationContext(InjectionPoint ip) { | |
| 176 | + if (ip != null) { | |
| 179 | 177 | return getContext(ip); |
| 180 | - } | |
| 181 | - else{ | |
| 178 | + } else { | |
| 182 | 179 | return getContext(ConversationContext.class); |
| 183 | 180 | } |
| 184 | 181 | } |
| 185 | - | |
| 186 | - /////////////END OF PRODUCERS/////////////////// | |
| 187 | - | |
| 182 | + | |
| 183 | + // ///////////END OF PRODUCERS/////////////////// | |
| 184 | + | |
| 188 | 185 | /** |
| 189 | 186 | * Obtain a custom context for the provided injection point. |
| 190 | 187 | * |
| 191 | - * @param ip The object containing information about the injection point - most importantly | |
| 192 | - * the declared type of the injection point, to decide the context to return | |
| 193 | - * | |
| 194 | - * @return A context of a type compatible with the type of the injection point, or <code>null</code> if there is | |
| 195 | - * no such context. | |
| 188 | + * @param ip | |
| 189 | + * The object containing information about the injection point - most importantly the declared type of | |
| 190 | + * the injection point, to decide the context to return | |
| 191 | + * @return A context of a type compatible with the type of the injection point, or <code>null</code> if there is no | |
| 192 | + * such context. | |
| 196 | 193 | */ |
| 197 | 194 | @SuppressWarnings("unchecked") |
| 198 | - public <T extends CustomContext> T getContext(InjectionPoint ip){ | |
| 195 | + public <T extends CustomContext> T getContext(InjectionPoint ip) { | |
| 199 | 196 | T producedContext = null; |
| 200 | - | |
| 201 | - if (ip!=null){ | |
| 197 | + | |
| 198 | + if (ip != null) { | |
| 202 | 199 | Class<T> beanClass = (Class<T>) ip.getType(); |
| 203 | 200 | producedContext = (T) getContext(beanClass); |
| 204 | 201 | } |
| 205 | - | |
| 206 | - if (producedContext!=null){ | |
| 207 | - getLogger().trace( getBundle().getString("custom-context-selected" , producedContext.getClass().getCanonicalName()) ); | |
| 202 | + | |
| 203 | + if (producedContext != null) { | |
| 204 | + getLogger().finest( | |
| 205 | + getBundle().getString("custom-context-selected", producedContext.getClass().getCanonicalName())); | |
| 208 | 206 | } |
| 209 | - | |
| 207 | + | |
| 210 | 208 | return producedContext; |
| 211 | 209 | } |
| 212 | - | |
| 210 | + | |
| 213 | 211 | /** |
| 214 | 212 | * Obtain a context compatible with the provided type. |
| 215 | 213 | * |
| 216 | - * @param contextClass The type of the desired context. The returned context will be compatible with this type, if there | |
| 217 | - * is more than one compatible type, this method will decide witch one to return based on the {@link Priority} annotation. | |
| 218 | - * | |
| 214 | + * @param contextClass | |
| 215 | + * The type of the desired context. The returned context will be compatible with this type, if there is | |
| 216 | + * more than one compatible type, this method will decide witch one to return based on the | |
| 217 | + * {@link Priority} annotation. | |
| 219 | 218 | * @return A context of a type compatible with the informed type, or <code>null</code> if there is no such context. |
| 220 | 219 | */ |
| 221 | 220 | @SuppressWarnings("unchecked") |
| 222 | - public <T extends CustomContext> T getContext(Class<T> contextClass){ | |
| 221 | + public <T extends CustomContext> T getContext(Class<T> contextClass) { | |
| 223 | 222 | CustomContext producedContext = null; |
| 224 | - | |
| 223 | + | |
| 225 | 224 | ArrayList<CustomContext> selectableContexts = new ArrayList<CustomContext>(); |
| 226 | - | |
| 227 | - for (CustomContext context : getContexts()){ | |
| 228 | - if ( contextClass.isAssignableFrom( context.getClass() ) ){ | |
| 229 | - if (context.isActive()){ | |
| 225 | + | |
| 226 | + for (CustomContext context : getContexts()) { | |
| 227 | + if (contextClass.isAssignableFrom(context.getClass())) { | |
| 228 | + if (context.isActive()) { | |
| 230 | 229 | producedContext = context; |
| 231 | 230 | break; |
| 232 | - } | |
| 233 | - else{ | |
| 231 | + } else { | |
| 234 | 232 | selectableContexts.add(context); |
| 235 | 233 | } |
| 236 | 234 | } |
| 237 | 235 | } |
| 238 | - | |
| 239 | - if (producedContext==null && !selectableContexts.isEmpty()){ | |
| 236 | + | |
| 237 | + if (producedContext == null && !selectableContexts.isEmpty()) { | |
| 240 | 238 | producedContext = StrategySelector.selectInstance(CustomContext.class, selectableContexts); |
| 241 | 239 | } |
| 242 | - | |
| 240 | + | |
| 243 | 241 | return (T) producedContext; |
| 244 | 242 | } |
| 245 | - | |
| 243 | + | |
| 246 | 244 | private Logger getLogger() { |
| 247 | 245 | if (this.logger == null) { |
| 248 | - this.logger = LoggerProducer.create(this.getClass()); | |
| 246 | + this.logger = LoggerProducer.create("br.gov.frameworkdemoiselle.context"); | |
| 249 | 247 | } |
| 250 | 248 | |
| 251 | 249 | return this.logger; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AnnotatedMethodProcessor.java
| ... | ... | @@ -36,12 +36,13 @@ |
| 36 | 36 | */ |
| 37 | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
| 38 | 38 | |
| 39 | +import static java.util.logging.Level.SEVERE; | |
| 40 | + | |
| 39 | 41 | import java.lang.reflect.InvocationTargetException; |
| 42 | +import java.util.logging.Logger; | |
| 40 | 43 | |
| 41 | 44 | import javax.enterprise.inject.spi.AnnotatedMethod; |
| 42 | 45 | |
| 43 | -import org.slf4j.Logger; | |
| 44 | - | |
| 45 | 46 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 46 | 47 | import br.gov.frameworkdemoiselle.exception.ApplicationException; |
| 47 | 48 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
| ... | ... | @@ -110,11 +111,11 @@ public class AnnotatedMethodProcessor<T> implements Comparable<AnnotatedMethodPr |
| 110 | 111 | break; |
| 111 | 112 | |
| 112 | 113 | case WARN: |
| 113 | - getLogger().warn(cause.getMessage()); | |
| 114 | + getLogger().warning(cause.getMessage()); | |
| 114 | 115 | break; |
| 115 | 116 | |
| 116 | 117 | default: |
| 117 | - getLogger().error(getBundle().getString("processing-fail"), cause); | |
| 118 | + getLogger().log(SEVERE, getBundle().getString("processing-fail"), cause); | |
| 118 | 119 | break; |
| 119 | 120 | } |
| 120 | 121 | } |
| ... | ... | @@ -140,6 +141,6 @@ public class AnnotatedMethodProcessor<T> implements Comparable<AnnotatedMethodPr |
| 140 | 141 | } |
| 141 | 142 | |
| 142 | 143 | protected Logger getLogger() { |
| 143 | - return LoggerProducer.create(this.getClass()); | |
| 144 | + return LoggerProducer.create("br.gov.frameworkdemoiselle.lifecycle"); | |
| 144 | 145 | } |
| 145 | 146 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationEnumValueExtractor.java
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationLoader.java
| ... | ... | @@ -45,6 +45,7 @@ import java.util.Collection; |
| 45 | 45 | import java.util.HashSet; |
| 46 | 46 | import java.util.Iterator; |
| 47 | 47 | import java.util.Set; |
| 48 | +import java.util.logging.Logger; | |
| 48 | 49 | |
| 49 | 50 | import javax.validation.ConstraintViolation; |
| 50 | 51 | import javax.validation.ConstraintViolationException; |
| ... | ... | @@ -58,7 +59,6 @@ import org.apache.commons.configuration.FileConfiguration; |
| 58 | 59 | import org.apache.commons.configuration.PropertiesConfiguration; |
| 59 | 60 | import org.apache.commons.configuration.SystemConfiguration; |
| 60 | 61 | import org.apache.commons.configuration.XMLConfiguration; |
| 61 | -import org.slf4j.Logger; | |
| 62 | 62 | |
| 63 | 63 | import br.gov.frameworkdemoiselle.annotation.Ignore; |
| 64 | 64 | import br.gov.frameworkdemoiselle.annotation.Name; |
| ... | ... | @@ -105,7 +105,7 @@ public class ConfigurationLoader implements Serializable { |
| 105 | 105 | |
| 106 | 106 | public void load(Object object, boolean logLoadingProcess) throws ConfigurationException { |
| 107 | 107 | if (logLoadingProcess) { |
| 108 | - getLogger().debug(getBundle().getString("loading-configuration-class", object.getClass().getName())); | |
| 108 | + getLogger().fine(getBundle().getString("loading-configuration-class", object.getClass().getName())); | |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | this.object = object; |
| ... | ... | @@ -167,7 +167,7 @@ public class ConfigurationLoader implements Serializable { |
| 167 | 167 | ((FileConfiguration) config).load(); |
| 168 | 168 | |
| 169 | 169 | } catch (org.apache.commons.configuration.ConfigurationException cause) { |
| 170 | - getLogger().warn(getBundle().getString("file-not-found", this.resource)); | |
| 170 | + getLogger().warning(getBundle().getString("file-not-found", this.resource)); | |
| 171 | 171 | config = null; |
| 172 | 172 | } |
| 173 | 173 | } |
| ... | ... | @@ -199,7 +199,7 @@ public class ConfigurationLoader implements Serializable { |
| 199 | 199 | String prefix = this.object.getClass().getAnnotation(Configuration.class).prefix(); |
| 200 | 200 | |
| 201 | 201 | if (prefix.endsWith(".")) { |
| 202 | - getLogger().warn(getBundle().getString("configuration-dot-after-prefix", this.resource)); | |
| 202 | + getLogger().warning(getBundle().getString("configuration-dot-after-prefix", this.resource)); | |
| 203 | 203 | } else if (!prefix.isEmpty()) { |
| 204 | 204 | prefix += "."; |
| 205 | 205 | } |
| ... | ... | @@ -223,11 +223,11 @@ public class ConfigurationLoader implements Serializable { |
| 223 | 223 | Object finalValue = (loadedValue == null ? defaultValue : loadedValue); |
| 224 | 224 | |
| 225 | 225 | if (loadedValue == null) { |
| 226 | - getLogger().trace(getBundle().getString("configuration-key-not-found", this.prefix + getKey(field))); | |
| 226 | + getLogger().fine(getBundle().getString("configuration-key-not-found", this.prefix + getKey(field))); | |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | Reflections.setFieldValue(field, this.object, finalValue); |
| 230 | - getLogger().debug( | |
| 230 | + getLogger().finer( | |
| 231 | 231 | getBundle().getString("configuration-field-loaded", this.prefix + getKey(field), field.getName(), |
| 232 | 232 | finalValue == null ? "null" : finalValue)); |
| 233 | 233 | } |
| ... | ... | @@ -329,7 +329,8 @@ public class ConfigurationLoader implements Serializable { |
| 329 | 329 | |
| 330 | 330 | private Logger getLogger() { |
| 331 | 331 | if (logger == null) { |
| 332 | - logger = Beans.getReference(Logger.class, new NameQualifier(ConfigurationLoader.class.getName())); | |
| 332 | + logger = Beans.getReference(Logger.class, new NameQualifier("br.gov.frameworkdemoiselle.configuration")); | |
| 333 | + | |
| 333 | 334 | } |
| 334 | 335 | |
| 335 | 336 | return logger; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/LoggerMessageAppender.java
| ... | ... | @@ -38,9 +38,9 @@ package br.gov.frameworkdemoiselle.internal.implementation; |
| 38 | 38 | |
| 39 | 39 | import static br.gov.frameworkdemoiselle.annotation.Priority.L1_PRIORITY; |
| 40 | 40 | |
| 41 | -import javax.inject.Inject; | |
| 41 | +import java.util.logging.Logger; | |
| 42 | 42 | |
| 43 | -import org.slf4j.Logger; | |
| 43 | +import javax.inject.Inject; | |
| 44 | 44 | |
| 45 | 45 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 46 | 46 | import br.gov.frameworkdemoiselle.message.Message; |
| ... | ... | @@ -64,11 +64,11 @@ public class LoggerMessageAppender implements MessageAppender { |
| 64 | 64 | break; |
| 65 | 65 | |
| 66 | 66 | case WARN: |
| 67 | - logger.warn(text); | |
| 67 | + logger.warning(text); | |
| 68 | 68 | break; |
| 69 | 69 | |
| 70 | 70 | default: |
| 71 | - logger.error(text); | |
| 71 | + logger.severe(text); | |
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/Management.java
| ... | ... | @@ -42,6 +42,7 @@ import java.util.ArrayList; |
| 42 | 42 | import java.util.Collection; |
| 43 | 43 | import java.util.List; |
| 44 | 44 | import java.util.Set; |
| 45 | +import java.util.logging.Logger; | |
| 45 | 46 | |
| 46 | 47 | import javax.enterprise.context.ApplicationScoped; |
| 47 | 48 | import javax.inject.Inject; |
| ... | ... | @@ -51,8 +52,6 @@ import javax.validation.Validation; |
| 51 | 52 | import javax.validation.ValidationException; |
| 52 | 53 | import javax.validation.Validator; |
| 53 | 54 | |
| 54 | -import org.slf4j.Logger; | |
| 55 | - | |
| 56 | 55 | import br.gov.frameworkdemoiselle.annotation.ManagedProperty; |
| 57 | 56 | import br.gov.frameworkdemoiselle.annotation.Name; |
| 58 | 57 | import br.gov.frameworkdemoiselle.context.ConversationContext; |
| ... | ... | @@ -93,7 +92,7 @@ public class Management implements Serializable { |
| 93 | 92 | |
| 94 | 93 | public void addManagedType(ManagedType managedType) { |
| 95 | 94 | managedTypes.add(managedType); |
| 96 | - logger.debug(bundle.getString("management-debug-registering-managed-type", managedType.getType() | |
| 95 | + logger.fine(bundle.getString("management-debug-registering-managed-type", managedType.getType() | |
| 97 | 96 | .getCanonicalName())); |
| 98 | 97 | } |
| 99 | 98 | |
| ... | ... | @@ -134,12 +133,12 @@ public class Management implements Serializable { |
| 134 | 133 | activateContexts(managedType.getType()); |
| 135 | 134 | |
| 136 | 135 | try { |
| 137 | - Object delegate = Beans.getReference(managedType.getType() , managedType.getQualifiers()); | |
| 136 | + Object delegate = Beans.getReference(managedType.getType(), managedType.getQualifiers()); | |
| 138 | 137 | MethodDetail method = managedType.getOperationMethods().get(actionName); |
| 139 | 138 | |
| 140 | 139 | if (method != null) { |
| 141 | 140 | try { |
| 142 | - logger.debug(bundle.getString("management-debug-invoking-operation", actionName, managedType | |
| 141 | + logger.fine(bundle.getString("management-debug-invoking-operation", actionName, managedType | |
| 143 | 142 | .getType().getCanonicalName())); |
| 144 | 143 | return method.getMethod().invoke(delegate, params); |
| 145 | 144 | } catch (Exception e) { |
| ... | ... | @@ -171,8 +170,10 @@ public class Management implements Serializable { |
| 171 | 170 | * @param propertyName |
| 172 | 171 | * The name of the property |
| 173 | 172 | * @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. | |
| 173 | + * @throws ManagedAttributeNotFoundException | |
| 174 | + * If the given property doesn't exist or there was a problem trying to read the property value. | |
| 175 | + * @throws ManagedInvokationException | |
| 176 | + * If there was an error trying to invoke the getter method to read the propery value. | |
| 176 | 177 | */ |
| 177 | 178 | public Object getProperty(ManagedType managedType, String propertyName) { |
| 178 | 179 | |
| ... | ... | @@ -180,23 +181,24 @@ public class Management implements Serializable { |
| 180 | 181 | Method getterMethod = managedType.getFields().get(propertyName).getGetterMethod(); |
| 181 | 182 | |
| 182 | 183 | if (getterMethod != null) { |
| 183 | - logger.debug(bundle.getString("management-debug-acessing-property", getterMethod.getName(), managedType | |
| 184 | + logger.fine(bundle.getString("management-debug-acessing-property", getterMethod.getName(), managedType | |
| 184 | 185 | .getType().getCanonicalName())); |
| 185 | 186 | |
| 186 | 187 | activateContexts(managedType.getType()); |
| 187 | 188 | |
| 188 | 189 | try { |
| 189 | - Object delegate = Beans.getReference(managedType.getType() , managedType.getQualifiers()); | |
| 190 | + Object delegate = Beans.getReference(managedType.getType(), managedType.getQualifiers()); | |
| 190 | 191 | |
| 191 | 192 | return getterMethod.invoke(delegate, (Object[]) null); |
| 192 | 193 | } catch (Exception e) { |
| 193 | - throw new ManagedInvokationException(bundle.getString("management-invoke-error", getterMethod.getName()), | |
| 194 | - e); | |
| 194 | + throw new ManagedInvokationException(bundle.getString("management-invoke-error", | |
| 195 | + getterMethod.getName()), e); | |
| 195 | 196 | } finally { |
| 196 | 197 | deactivateContexts(managedType.getType()); |
| 197 | 198 | } |
| 198 | 199 | } else { |
| 199 | - throw new ManagedAttributeNotFoundException(bundle.getString("management-read-value-error", propertyName)); | |
| 200 | + throw new ManagedAttributeNotFoundException(bundle.getString("management-read-value-error", | |
| 201 | + propertyName)); | |
| 200 | 202 | } |
| 201 | 203 | } else { |
| 202 | 204 | throw new ManagedInvokationException(bundle.getString("management-type-not-found")); |
| ... | ... | @@ -219,9 +221,13 @@ public class Management implements Serializable { |
| 219 | 221 | * The name of the property |
| 220 | 222 | * @param newValue |
| 221 | 223 | * 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. | |
| 224 | + * @throws ManagedInvokationException | |
| 225 | + * If there was an error trying to call the setter method for this property. | |
| 226 | + * @throws ManagedAttributeNotFoundException | |
| 227 | + * If the giver property doesn't exist or could'n be written to. | |
| 228 | + * @throws ConstraintViolationException | |
| 229 | + * If the property defined one or more validation constraints and setting this value violates some of | |
| 230 | + * those constraints. | |
| 225 | 231 | */ |
| 226 | 232 | @SuppressWarnings("unchecked") |
| 227 | 233 | public void setProperty(ManagedType managedType, String propertyName, Object newValue) { |
| ... | ... | @@ -230,7 +236,7 @@ public class Management implements Serializable { |
| 230 | 236 | // Procura o método set do atributo em questão |
| 231 | 237 | Method method = managedType.getFields().get(propertyName).getSetterMethod(); |
| 232 | 238 | if (method != null) { |
| 233 | - logger.debug(bundle.getString("management-debug-setting-property", method.getName(), managedType | |
| 239 | + logger.fine(bundle.getString("management-debug-setting-property", method.getName(), managedType | |
| 234 | 240 | .getType().getCanonicalName())); |
| 235 | 241 | |
| 236 | 242 | activateContexts(managedType.getType()); |
| ... | ... | @@ -238,7 +244,7 @@ public class Management implements Serializable { |
| 238 | 244 | // Obtém uma instância da classe gerenciada, lembrando que |
| 239 | 245 | // classes |
| 240 | 246 | // anotadas com @ManagementController são sempre singletons. |
| 241 | - Object delegate = Beans.getReference(managedType.getType() , managedType.getQualifiers() ); | |
| 247 | + Object delegate = Beans.getReference(managedType.getType(), managedType.getQualifiers()); | |
| 242 | 248 | |
| 243 | 249 | // Se houver um validador anexado à propriedade alterada, executa o validador sobre |
| 244 | 250 | // o novo valor. |
| ... | ... | @@ -257,12 +263,13 @@ public class Management implements Serializable { |
| 257 | 263 | errorBuffer.insert(errorBuffer.length(), "\r\n"); |
| 258 | 264 | } |
| 259 | 265 | |
| 260 | - throw new ConstraintViolationException(bundle.getString("management-validation-constraint-violation" | |
| 261 | - , managedType.getType().getCanonicalName(), propertyName, errorBuffer.toString()) | |
| 262 | - , (Set<ConstraintViolation<?>>) violations); | |
| 266 | + throw new ConstraintViolationException(bundle.getString( | |
| 267 | + "management-validation-constraint-violation", managedType.getType() | |
| 268 | + .getCanonicalName(), propertyName, errorBuffer.toString()), | |
| 269 | + (Set<ConstraintViolation<?>>) violations); | |
| 263 | 270 | } |
| 264 | 271 | } else { |
| 265 | - logger.warn(bundle.getString("management-validation-validator-not-found")); | |
| 272 | + logger.warning(bundle.getString("management-validation-validator-not-found")); | |
| 266 | 273 | } |
| 267 | 274 | |
| 268 | 275 | Method getterMethod = managedType.getFields().get(propertyName).getGetterMethod(); |
| ... | ... | @@ -279,24 +286,23 @@ public class Management implements Serializable { |
| 279 | 286 | NotificationManager notificationManager = Beans.getReference(NotificationManager.class); |
| 280 | 287 | Class<? extends Object> attributeType = newValue != null ? newValue.getClass() : null; |
| 281 | 288 | |
| 282 | - Notification notification = new DefaultNotification( new AttributeChangeMessage( | |
| 283 | - bundle.getString("management-notification-attribute-changed", propertyName, managedType.getType().getCanonicalName()) | |
| 284 | - , propertyName | |
| 285 | - , attributeType | |
| 286 | - , oldValue | |
| 287 | - , newValue) ); | |
| 289 | + Notification notification = new DefaultNotification(new AttributeChangeMessage(bundle.getString( | |
| 290 | + "management-notification-attribute-changed", propertyName, managedType.getType() | |
| 291 | + .getCanonicalName()), propertyName, attributeType, oldValue, newValue)); | |
| 288 | 292 | notificationManager.sendNotification(notification); |
| 289 | 293 | |
| 290 | 294 | } catch (ConstraintViolationException ce) { |
| 291 | 295 | throw ce; |
| 292 | 296 | } catch (Exception e) { |
| 293 | - throw new ManagedInvokationException(bundle.getString("management-invoke-error", method.getName()), e); | |
| 297 | + throw new ManagedInvokationException(bundle.getString("management-invoke-error", method.getName()), | |
| 298 | + e); | |
| 294 | 299 | } finally { |
| 295 | 300 | deactivateContexts(managedType.getType()); |
| 296 | 301 | } |
| 297 | 302 | |
| 298 | 303 | } else { |
| 299 | - throw new ManagedAttributeNotFoundException(bundle.getString("management-write-value-error", propertyName)); | |
| 304 | + throw new ManagedAttributeNotFoundException(bundle.getString("management-write-value-error", | |
| 305 | + propertyName)); | |
| 300 | 306 | } |
| 301 | 307 | } else { |
| 302 | 308 | throw new ManagedInvokationException(bundle.getString("management-type-not-found")); |
| ... | ... | @@ -307,18 +313,18 @@ public class Management implements Serializable { |
| 307 | 313 | private void activateContexts(Class<?> managedType) { |
| 308 | 314 | RequestContext requestContext = Beans.getReference(RequestContext.class); |
| 309 | 315 | ConversationContext conversationContext = Beans.getReference(ConversationContext.class); |
| 310 | - | |
| 311 | - if (!requestContext.isActive()){ | |
| 312 | - logger.debug(bundle.getString("management-debug-starting-custom-context", | |
| 313 | - requestContext.getClass().getCanonicalName(), managedType.getCanonicalName())); | |
| 314 | - | |
| 316 | + | |
| 317 | + if (!requestContext.isActive()) { | |
| 318 | + logger.fine(bundle.getString("management-debug-starting-custom-context", requestContext.getClass() | |
| 319 | + .getCanonicalName(), managedType.getCanonicalName())); | |
| 320 | + | |
| 315 | 321 | requestContext.activate(); |
| 316 | 322 | } |
| 317 | - | |
| 318 | - if (!conversationContext.isActive()){ | |
| 319 | - logger.debug(bundle.getString("management-debug-starting-custom-context", | |
| 320 | - conversationContext.getClass().getCanonicalName(), managedType.getCanonicalName())); | |
| 321 | - | |
| 323 | + | |
| 324 | + if (!conversationContext.isActive()) { | |
| 325 | + logger.fine(bundle.getString("management-debug-starting-custom-context", conversationContext.getClass() | |
| 326 | + .getCanonicalName(), managedType.getCanonicalName())); | |
| 327 | + | |
| 322 | 328 | conversationContext.activate(); |
| 323 | 329 | } |
| 324 | 330 | } |
| ... | ... | @@ -326,18 +332,18 @@ public class Management implements Serializable { |
| 326 | 332 | private void deactivateContexts(Class<?> managedType) { |
| 327 | 333 | RequestContext requestContext = Beans.getReference(RequestContext.class); |
| 328 | 334 | ConversationContext conversationContext = Beans.getReference(ConversationContext.class); |
| 329 | - | |
| 330 | - if (requestContext.isActive()){ | |
| 331 | - logger.debug(bundle.getString("management-debug-stoping-custom-context", | |
| 332 | - requestContext.getClass().getCanonicalName(), managedType.getCanonicalName())); | |
| 333 | - | |
| 335 | + | |
| 336 | + if (requestContext.isActive()) { | |
| 337 | + logger.fine(bundle.getString("management-debug-stoping-custom-context", requestContext.getClass() | |
| 338 | + .getCanonicalName(), managedType.getCanonicalName())); | |
| 339 | + | |
| 334 | 340 | requestContext.deactivate(); |
| 335 | 341 | } |
| 336 | - | |
| 337 | - if (conversationContext.isActive()){ | |
| 338 | - logger.debug(bundle.getString("management-debug-stoping-custom-context", | |
| 339 | - conversationContext.getClass().getCanonicalName(), managedType.getCanonicalName())); | |
| 340 | - | |
| 342 | + | |
| 343 | + if (conversationContext.isActive()) { | |
| 344 | + logger.fine(bundle.getString("management-debug-stoping-custom-context", conversationContext.getClass() | |
| 345 | + .getCanonicalName(), managedType.getCanonicalName())); | |
| 346 | + | |
| 341 | 347 | conversationContext.deactivate(); |
| 342 | 348 | } |
| 343 | 349 | } |
| ... | ... | @@ -347,7 +353,7 @@ public class Management implements Serializable { |
| 347 | 353 | |
| 348 | 354 | ManagementExtension monitoringExtension = Beans.getReference(monitoringExtensionClass); |
| 349 | 355 | monitoringExtension.shutdown(this.getManagedTypes()); |
| 350 | - logger.debug(bundle.getString("management-debug-removing-management-extension", monitoringExtension | |
| 356 | + logger.fine(bundle.getString("management-debug-removing-management-extension", monitoringExtension | |
| 351 | 357 | .getClass().getCanonicalName())); |
| 352 | 358 | |
| 353 | 359 | } |
| ... | ... | @@ -357,7 +363,7 @@ public class Management implements Serializable { |
| 357 | 363 | for (Class<? extends ManagementExtension> monitoringExtensionClass : monitoringExtensions) { |
| 358 | 364 | ManagementExtension monitoringExtension = Beans.getReference(monitoringExtensionClass); |
| 359 | 365 | |
| 360 | - logger.debug(bundle.getString("management-debug-processing-management-extension", monitoringExtension | |
| 366 | + logger.fine(bundle.getString("management-debug-processing-management-extension", monitoringExtension | |
| 361 | 367 | .getClass().getCanonicalName())); |
| 362 | 368 | |
| 363 | 369 | monitoringExtension.initialize(this.getManagedTypes()); |
| ... | ... | @@ -375,6 +381,4 @@ public class Management implements Serializable { |
| 375 | 381 | |
| 376 | 382 | return this.validator; |
| 377 | 383 | } |
| 378 | - | |
| 379 | - | |
| 380 | 384 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MessageContextImpl.java
| ... | ... | @@ -37,14 +37,10 @@ |
| 37 | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
| 38 | 38 | |
| 39 | 39 | import java.io.Serializable; |
| 40 | -import java.util.List; | |
| 40 | +import java.util.logging.Logger; | |
| 41 | 41 | |
| 42 | -import org.slf4j.Logger; | |
| 43 | - | |
| 44 | -import br.gov.frameworkdemoiselle.DemoiselleException; | |
| 45 | 42 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
| 46 | 43 | import br.gov.frameworkdemoiselle.message.DefaultMessage; |
| 47 | -import br.gov.frameworkdemoiselle.message.Message; | |
| 48 | 44 | import br.gov.frameworkdemoiselle.message.MessageAppender; |
| 49 | 45 | import br.gov.frameworkdemoiselle.message.MessageContext; |
| 50 | 46 | import br.gov.frameworkdemoiselle.message.SeverityType; |
| ... | ... | @@ -61,30 +57,9 @@ public class MessageContextImpl implements Serializable, MessageContext { |
| 61 | 57 | |
| 62 | 58 | private static final long serialVersionUID = 1L; |
| 63 | 59 | |
| 64 | - private transient ResourceBundle bundle; | |
| 65 | - | |
| 66 | - private transient Logger logger; | |
| 60 | + private transient ResourceBundle bundle; | |
| 67 | 61 | |
| 68 | - @Override | |
| 69 | - @Deprecated | |
| 70 | - public void add(final Message message, Object... params) { | |
| 71 | - | |
| 72 | - getLogger().debug(getBundle().getString("adding-message-to-context", message.toString())); | |
| 73 | - if (params == null || params.length == 0) { | |
| 74 | - getAppender().append(message); | |
| 75 | - } else { | |
| 76 | - getLogger().warn("Atualmente, ao chamar o método add do MessageContext passando um objeto" | |
| 77 | - + " do tipo Message e mais parâmetros, será recriando um objeto" +"\n" | |
| 78 | - + " Message, na implementação DefaultMessage para que os parâmetros sejam utilizados." | |
| 79 | - + " Note que isso poderá trazer problemas para sua aplicação, caso" +"\n" | |
| 80 | - + " a implementação de Message utilizada não seja a DefaultMessage. Para evitar esse tipo de problema" | |
| 81 | - + " e garantir compatibilidade com versões futuras, recomendamos que" +"\n" | |
| 82 | - + " o objeto message seja criado com os parâmetros, e que para o método add apenas seja passado" | |
| 83 | - + " esse objeto como parâmetro."); | |
| 84 | - | |
| 85 | - getAppender().append(new DefaultMessage(message.getText(), message.getSeverity(), params)); | |
| 86 | - } | |
| 87 | - } | |
| 62 | + private transient Logger logger; | |
| 88 | 63 | |
| 89 | 64 | private MessageAppender getAppender() { |
| 90 | 65 | Class<? extends MessageAppender> appenderClass = StrategySelector.selectClass(MessageAppender.class); |
| ... | ... | @@ -99,26 +74,10 @@ public class MessageContextImpl implements Serializable, MessageContext { |
| 99 | 74 | |
| 100 | 75 | @Override |
| 101 | 76 | public void add(String text, SeverityType severity, Object... params) { |
| 102 | - add(new DefaultMessage(text, severity, params)); | |
| 103 | - } | |
| 104 | - | |
| 105 | - @Override | |
| 106 | - @Deprecated | |
| 107 | - public List<Message> getMessages() { | |
| 108 | - throw new DemoiselleException( | |
| 109 | - "Este método não é mais suportado desde a versão 2.4.0 do Demoiselle Framework. Considere atualizar a sua aplicação ou o componente com uma nova versão que faça uso do " | |
| 110 | - + MessageAppender.class.getCanonicalName() + "."); | |
| 111 | - } | |
| 112 | - | |
| 113 | - @Override | |
| 114 | - @Deprecated | |
| 115 | - public void clear() { | |
| 116 | - throw new DemoiselleException( | |
| 117 | - "Este método não é mais suportado desde a versão 2.4.0 do Demoiselle Framework. Considere atualizar a sua aplicação ou o componente com uma nova versão que faça uso do " | |
| 118 | - + MessageAppender.class.getCanonicalName() + "."); | |
| 77 | + getAppender().append(new DefaultMessage(text, severity, params)); | |
| 119 | 78 | } |
| 120 | 79 | |
| 121 | - private ResourceBundle getBundle() { | |
| 80 | + private ResourceBundle getBundle() { | |
| 122 | 81 | if (bundle == null) { |
| 123 | 82 | bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle")); |
| 124 | 83 | } |
| ... | ... | @@ -126,9 +85,9 @@ public class MessageContextImpl implements Serializable, MessageContext { |
| 126 | 85 | return bundle; |
| 127 | 86 | } |
| 128 | 87 | |
| 129 | - private Logger getLogger() { | |
| 88 | + private Logger getLogger() { | |
| 130 | 89 | if (logger == null) { |
| 131 | - logger = LoggerProducer.create(MessageContext.class); | |
| 90 | + logger = LoggerProducer.create("br.gov.frameworkdemoiselle.message"); | |
| 132 | 91 | } |
| 133 | 92 | |
| 134 | 93 | return logger; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/LoggerProducer.java
| ... | ... | @@ -49,17 +49,14 @@ |
| 49 | 49 | package br.gov.frameworkdemoiselle.internal.producer; |
| 50 | 50 | |
| 51 | 51 | import java.io.Serializable; |
| 52 | +import java.util.logging.Logger; | |
| 52 | 53 | |
| 53 | 54 | import javax.enterprise.inject.Default; |
| 54 | 55 | import javax.enterprise.inject.Produces; |
| 55 | 56 | import javax.enterprise.inject.spi.InjectionPoint; |
| 56 | 57 | |
| 57 | -import org.slf4j.Logger; | |
| 58 | - | |
| 59 | -import br.gov.frameworkdemoiselle.DemoiselleException; | |
| 60 | 58 | import br.gov.frameworkdemoiselle.annotation.Name; |
| 61 | -import br.gov.frameworkdemoiselle.internal.proxy.Slf4jLoggerProxy; | |
| 62 | -import br.gov.frameworkdemoiselle.util.Reflections; | |
| 59 | +import br.gov.frameworkdemoiselle.internal.proxy.LoggerProxy; | |
| 63 | 60 | |
| 64 | 61 | public class LoggerProducer implements Serializable { |
| 65 | 62 | |
| ... | ... | @@ -68,36 +65,25 @@ public class LoggerProducer implements Serializable { |
| 68 | 65 | @Default |
| 69 | 66 | @Produces |
| 70 | 67 | public Logger create(final InjectionPoint ip) { |
| 71 | - Class<?> type; | |
| 68 | + String name; | |
| 72 | 69 | |
| 73 | 70 | if (ip != null && ip.getMember() != null) { |
| 74 | - type = ip.getMember().getDeclaringClass(); | |
| 71 | + name = ip.getMember().getDeclaringClass().getName(); | |
| 75 | 72 | } else { |
| 76 | - type = LoggerProducer.class; | |
| 73 | + name = "not.categorized"; | |
| 77 | 74 | } |
| 78 | 75 | |
| 79 | - return create(type); | |
| 76 | + return create(name); | |
| 80 | 77 | } |
| 81 | 78 | |
| 82 | 79 | @Name("") |
| 83 | 80 | @Produces |
| 84 | 81 | public Logger createNamed(final InjectionPoint ip) throws ClassNotFoundException { |
| 85 | - Class<?> type; | |
| 86 | - | |
| 87 | - try { | |
| 88 | - String canonicalName = ip.getAnnotated().getAnnotation(Name.class).value(); | |
| 89 | - type = Reflections.forName(canonicalName); | |
| 90 | - | |
| 91 | - } catch (ClassCastException cause) { | |
| 92 | - // TODO Colocar a mensgaem apropriada mostrando como utilizar a anotação @AmbiguousQualifier corretamente com a injeção de | |
| 93 | - // Logger. | |
| 94 | - throw new DemoiselleException(null, cause); | |
| 95 | - } | |
| 96 | - | |
| 97 | - return create(type); | |
| 82 | + String name = ip.getAnnotated().getAnnotation(Name.class).value(); | |
| 83 | + return create(name); | |
| 98 | 84 | } |
| 99 | 85 | |
| 100 | - public static <T> Logger create(Class<T> type) { | |
| 101 | - return new Slf4jLoggerProxy(type); | |
| 86 | + public static Logger create(String name) { | |
| 87 | + return new LoggerProxy(name); | |
| 102 | 88 | } |
| 103 | 89 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/LoggerProxy.java
0 → 100644
| ... | ... | @@ -0,0 +1,206 @@ |
| 1 | +package br.gov.frameworkdemoiselle.internal.proxy; | |
| 2 | + | |
| 3 | +import java.util.ResourceBundle; | |
| 4 | +import java.util.logging.Filter; | |
| 5 | +import java.util.logging.Handler; | |
| 6 | +import java.util.logging.Level; | |
| 7 | +import java.util.logging.LogRecord; | |
| 8 | +import java.util.logging.Logger; | |
| 9 | + | |
| 10 | +public class LoggerProxy extends Logger { | |
| 11 | + | |
| 12 | + private String name; | |
| 13 | + | |
| 14 | + private transient Logger delegate; | |
| 15 | + | |
| 16 | + public LoggerProxy(String name) { | |
| 17 | + super(name, null); | |
| 18 | + this.name = name; | |
| 19 | + } | |
| 20 | + | |
| 21 | + public Logger getDelegate() { | |
| 22 | + if (this.delegate == null) { | |
| 23 | + this.delegate = Logger.getLogger(this.name); | |
| 24 | + } | |
| 25 | + | |
| 26 | + return this.delegate; | |
| 27 | + } | |
| 28 | + | |
| 29 | + public int hashCode() { | |
| 30 | + return getDelegate().hashCode(); | |
| 31 | + } | |
| 32 | + | |
| 33 | + public boolean equals(Object obj) { | |
| 34 | + return getDelegate().equals(obj); | |
| 35 | + } | |
| 36 | + | |
| 37 | + public String toString() { | |
| 38 | + return getDelegate().toString(); | |
| 39 | + } | |
| 40 | + | |
| 41 | + public ResourceBundle getResourceBundle() { | |
| 42 | + return getDelegate().getResourceBundle(); | |
| 43 | + } | |
| 44 | + | |
| 45 | + public String getResourceBundleName() { | |
| 46 | + return getDelegate().getResourceBundleName(); | |
| 47 | + } | |
| 48 | + | |
| 49 | + public void setFilter(Filter newFilter) throws SecurityException { | |
| 50 | + getDelegate().setFilter(newFilter); | |
| 51 | + } | |
| 52 | + | |
| 53 | + public Filter getFilter() { | |
| 54 | + return getDelegate().getFilter(); | |
| 55 | + } | |
| 56 | + | |
| 57 | + public void log(LogRecord record) { | |
| 58 | + getDelegate().log(record); | |
| 59 | + } | |
| 60 | + | |
| 61 | + public void log(Level level, String msg) { | |
| 62 | + getDelegate().log(level, msg); | |
| 63 | + } | |
| 64 | + | |
| 65 | + public void log(Level level, String msg, Object param1) { | |
| 66 | + getDelegate().log(level, msg, param1); | |
| 67 | + } | |
| 68 | + | |
| 69 | + public void log(Level level, String msg, Object[] params) { | |
| 70 | + getDelegate().log(level, msg, params); | |
| 71 | + } | |
| 72 | + | |
| 73 | + public void log(Level level, String msg, Throwable thrown) { | |
| 74 | + getDelegate().log(level, msg, thrown); | |
| 75 | + } | |
| 76 | + | |
| 77 | + public void logp(Level level, String sourceClass, String sourceMethod, String msg) { | |
| 78 | + getDelegate().logp(level, sourceClass, sourceMethod, msg); | |
| 79 | + } | |
| 80 | + | |
| 81 | + public void logp(Level level, String sourceClass, String sourceMethod, String msg, Object param1) { | |
| 82 | + getDelegate().logp(level, sourceClass, sourceMethod, msg, param1); | |
| 83 | + } | |
| 84 | + | |
| 85 | + public void logp(Level level, String sourceClass, String sourceMethod, String msg, Object[] params) { | |
| 86 | + getDelegate().logp(level, sourceClass, sourceMethod, msg, params); | |
| 87 | + } | |
| 88 | + | |
| 89 | + public void logp(Level level, String sourceClass, String sourceMethod, String msg, Throwable thrown) { | |
| 90 | + getDelegate().logp(level, sourceClass, sourceMethod, msg, thrown); | |
| 91 | + } | |
| 92 | + | |
| 93 | + public void logrb(Level level, String sourceClass, String sourceMethod, String bundleName, String msg) { | |
| 94 | + getDelegate().logrb(level, sourceClass, sourceMethod, bundleName, msg); | |
| 95 | + } | |
| 96 | + | |
| 97 | + public void logrb(Level level, String sourceClass, String sourceMethod, String bundleName, String msg, Object param1) { | |
| 98 | + getDelegate().logrb(level, sourceClass, sourceMethod, bundleName, msg, param1); | |
| 99 | + } | |
| 100 | + | |
| 101 | + public void logrb(Level level, String sourceClass, String sourceMethod, String bundleName, String msg, | |
| 102 | + Object[] params) { | |
| 103 | + getDelegate().logrb(level, sourceClass, sourceMethod, bundleName, msg, params); | |
| 104 | + } | |
| 105 | + | |
| 106 | + public void logrb(Level level, String sourceClass, String sourceMethod, String bundleName, String msg, | |
| 107 | + Throwable thrown) { | |
| 108 | + getDelegate().logrb(level, sourceClass, sourceMethod, bundleName, msg, thrown); | |
| 109 | + } | |
| 110 | + | |
| 111 | + public void entering(String sourceClass, String sourceMethod) { | |
| 112 | + getDelegate().entering(sourceClass, sourceMethod); | |
| 113 | + } | |
| 114 | + | |
| 115 | + public void entering(String sourceClass, String sourceMethod, Object param1) { | |
| 116 | + getDelegate().entering(sourceClass, sourceMethod, param1); | |
| 117 | + } | |
| 118 | + | |
| 119 | + public void entering(String sourceClass, String sourceMethod, Object[] params) { | |
| 120 | + getDelegate().entering(sourceClass, sourceMethod, params); | |
| 121 | + } | |
| 122 | + | |
| 123 | + public void exiting(String sourceClass, String sourceMethod) { | |
| 124 | + getDelegate().exiting(sourceClass, sourceMethod); | |
| 125 | + } | |
| 126 | + | |
| 127 | + public void exiting(String sourceClass, String sourceMethod, Object result) { | |
| 128 | + getDelegate().exiting(sourceClass, sourceMethod, result); | |
| 129 | + } | |
| 130 | + | |
| 131 | + public void throwing(String sourceClass, String sourceMethod, Throwable thrown) { | |
| 132 | + getDelegate().throwing(sourceClass, sourceMethod, thrown); | |
| 133 | + } | |
| 134 | + | |
| 135 | + public void severe(String msg) { | |
| 136 | + getDelegate().severe(msg); | |
| 137 | + } | |
| 138 | + | |
| 139 | + public void warning(String msg) { | |
| 140 | + getDelegate().warning(msg); | |
| 141 | + } | |
| 142 | + | |
| 143 | + public void info(String msg) { | |
| 144 | + getDelegate().info(msg); | |
| 145 | + } | |
| 146 | + | |
| 147 | + public void config(String msg) { | |
| 148 | + getDelegate().config(msg); | |
| 149 | + } | |
| 150 | + | |
| 151 | + public void fine(String msg) { | |
| 152 | + getDelegate().fine(msg); | |
| 153 | + } | |
| 154 | + | |
| 155 | + public void finer(String msg) { | |
| 156 | + getDelegate().finer(msg); | |
| 157 | + } | |
| 158 | + | |
| 159 | + public void finest(String msg) { | |
| 160 | + getDelegate().finest(msg); | |
| 161 | + } | |
| 162 | + | |
| 163 | + public void setLevel(Level newLevel) throws SecurityException { | |
| 164 | + getDelegate().setLevel(newLevel); | |
| 165 | + } | |
| 166 | + | |
| 167 | + public Level getLevel() { | |
| 168 | + return getDelegate().getLevel(); | |
| 169 | + } | |
| 170 | + | |
| 171 | + public boolean isLoggable(Level level) { | |
| 172 | + return getDelegate().isLoggable(level); | |
| 173 | + } | |
| 174 | + | |
| 175 | + public String getName() { | |
| 176 | + return getDelegate().getName(); | |
| 177 | + } | |
| 178 | + | |
| 179 | + public void addHandler(Handler handler) throws SecurityException { | |
| 180 | + getDelegate().addHandler(handler); | |
| 181 | + } | |
| 182 | + | |
| 183 | + public void removeHandler(Handler handler) throws SecurityException { | |
| 184 | + getDelegate().removeHandler(handler); | |
| 185 | + } | |
| 186 | + | |
| 187 | + public Handler[] getHandlers() { | |
| 188 | + return getDelegate().getHandlers(); | |
| 189 | + } | |
| 190 | + | |
| 191 | + public void setUseParentHandlers(boolean useParentHandlers) { | |
| 192 | + getDelegate().setUseParentHandlers(useParentHandlers); | |
| 193 | + } | |
| 194 | + | |
| 195 | + public boolean getUseParentHandlers() { | |
| 196 | + return getDelegate().getUseParentHandlers(); | |
| 197 | + } | |
| 198 | + | |
| 199 | + public Logger getParent() { | |
| 200 | + return getDelegate().getParent(); | |
| 201 | + } | |
| 202 | + | |
| 203 | + public void setParent(Logger parent) { | |
| 204 | + getDelegate().setParent(parent); | |
| 205 | + } | |
| 206 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/message/MessageContext.java
| ... | ... | @@ -36,8 +36,6 @@ |
| 36 | 36 | */ |
| 37 | 37 | package br.gov.frameworkdemoiselle.message; |
| 38 | 38 | |
| 39 | -import java.util.List; | |
| 40 | - | |
| 41 | 39 | /** |
| 42 | 40 | * Context interface reserved for messaging purposes. |
| 43 | 41 | * <p> |
| ... | ... | @@ -51,27 +49,20 @@ import java.util.List; |
| 51 | 49 | public interface MessageContext { |
| 52 | 50 | |
| 53 | 51 | /** |
| 54 | - * Saves a message into the context. | |
| 52 | + * Deliver a message to the MessageAppender. | |
| 55 | 53 | * |
| 54 | + * @see MessageAppender | |
| 56 | 55 | * @param message |
| 57 | 56 | */ |
| 58 | - @Deprecated | |
| 59 | - void add(Message message, Object... params); | |
| 60 | - | |
| 61 | - void add(String text, Object... params); | |
| 62 | - | |
| 63 | - void add(String text, SeverityType severity, Object... params); | |
| 57 | + void add(String message, Object... params); | |
| 64 | 58 | |
| 65 | 59 | /** |
| 66 | - * Returns all messages in the context. | |
| 67 | - */ | |
| 68 | - @Deprecated | |
| 69 | - List<Message> getMessages(); | |
| 70 | - | |
| 71 | - /** | |
| 72 | - * Clears the list of messages in the context. | |
| 60 | + * Deliver a message to the MessageAppender. | |
| 61 | + * | |
| 62 | + * @see MessageAppender | |
| 63 | + * @param message | |
| 64 | + * @param severity | |
| 65 | + * @param params | |
| 73 | 66 | */ |
| 74 | - @Deprecated | |
| 75 | - void clear(); | |
| 76 | - | |
| 67 | + void add(String message, SeverityType severity, Object... params); | |
| 77 | 68 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/security/RequiredPermissionInterceptor.java
| ... | ... | @@ -37,13 +37,12 @@ |
| 37 | 37 | package br.gov.frameworkdemoiselle.security; |
| 38 | 38 | |
| 39 | 39 | import java.io.Serializable; |
| 40 | +import java.util.logging.Logger; | |
| 40 | 41 | |
| 41 | 42 | import javax.interceptor.AroundInvoke; |
| 42 | 43 | import javax.interceptor.Interceptor; |
| 43 | 44 | import javax.interceptor.InvocationContext; |
| 44 | 45 | |
| 45 | -import org.slf4j.Logger; | |
| 46 | - | |
| 47 | 46 | import br.gov.frameworkdemoiselle.annotation.Name; |
| 48 | 47 | import br.gov.frameworkdemoiselle.util.Beans; |
| 49 | 48 | import br.gov.frameworkdemoiselle.util.NameQualifier; |
| ... | ... | @@ -86,15 +85,15 @@ public class RequiredPermissionInterceptor implements Serializable { |
| 86 | 85 | |
| 87 | 86 | if (getSecurityContext().isLoggedIn()) { |
| 88 | 87 | username = getSecurityContext().getUser().getName(); |
| 89 | - getLogger().trace(getBundle().getString("access-checking", username, operation, resource)); | |
| 88 | + getLogger().finest(getBundle().getString("access-checking", username, operation, resource)); | |
| 90 | 89 | } |
| 91 | 90 | |
| 92 | 91 | if (!getSecurityContext().hasPermission(resource, operation)) { |
| 93 | - getLogger().error(getBundle().getString("access-denied", username, operation, resource)); | |
| 92 | + getLogger().severe(getBundle().getString("access-denied", username, operation, resource)); | |
| 94 | 93 | throw new AuthorizationException(getBundle().getString("access-denied-ui", resource, operation)); |
| 95 | 94 | } |
| 96 | 95 | |
| 97 | - getLogger().debug(getBundle().getString("access-allowed", username, operation, resource)); | |
| 96 | + getLogger().fine(getBundle().getString("access-allowed", username, operation, resource)); | |
| 98 | 97 | return ic.proceed(); |
| 99 | 98 | } |
| 100 | 99 | |
| ... | ... | @@ -110,8 +109,8 @@ public class RequiredPermissionInterceptor implements Serializable { |
| 110 | 109 | private String getResource(InvocationContext ic) { |
| 111 | 110 | RequiredPermission requiredPermission; |
| 112 | 111 | requiredPermission = ic.getMethod().getAnnotation(RequiredPermission.class); |
| 113 | - | |
| 114 | - if(requiredPermission == null){ | |
| 112 | + | |
| 113 | + if (requiredPermission == null) { | |
| 115 | 114 | requiredPermission = ic.getTarget().getClass().getAnnotation(RequiredPermission.class); |
| 116 | 115 | } |
| 117 | 116 | |
| ... | ... | @@ -138,11 +137,11 @@ public class RequiredPermissionInterceptor implements Serializable { |
| 138 | 137 | private String getOperation(InvocationContext ic) { |
| 139 | 138 | RequiredPermission requiredPermission; |
| 140 | 139 | requiredPermission = ic.getMethod().getAnnotation(RequiredPermission.class); |
| 141 | - | |
| 142 | - if(requiredPermission == null){ | |
| 140 | + | |
| 141 | + if (requiredPermission == null) { | |
| 143 | 142 | requiredPermission = ic.getTarget().getClass().getAnnotation(RequiredPermission.class); |
| 144 | 143 | } |
| 145 | - | |
| 144 | + | |
| 146 | 145 | if (Strings.isEmpty(requiredPermission.operation())) { |
| 147 | 146 | if (ic.getMethod().getAnnotation(Name.class) == null) { |
| 148 | 147 | return ic.getMethod().getName(); | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/security/RequiredRoleInterceptor.java
| ... | ... | @@ -40,13 +40,12 @@ import java.io.Serializable; |
| 40 | 40 | import java.util.ArrayList; |
| 41 | 41 | import java.util.Arrays; |
| 42 | 42 | import java.util.List; |
| 43 | +import java.util.logging.Logger; | |
| 43 | 44 | |
| 44 | 45 | import javax.interceptor.AroundInvoke; |
| 45 | 46 | import javax.interceptor.Interceptor; |
| 46 | 47 | import javax.interceptor.InvocationContext; |
| 47 | 48 | |
| 48 | -import org.slf4j.Logger; | |
| 49 | - | |
| 50 | 49 | import br.gov.frameworkdemoiselle.util.Beans; |
| 51 | 50 | import br.gov.frameworkdemoiselle.util.NameQualifier; |
| 52 | 51 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| ... | ... | @@ -84,8 +83,7 @@ public class RequiredRoleInterceptor implements Serializable { |
| 84 | 83 | |
| 85 | 84 | if (getSecurityContext().isLoggedIn()) { |
| 86 | 85 | getLogger().info( |
| 87 | - getBundle().getString("has-role-verification", getSecurityContext().getUser().getName(), | |
| 88 | - roles)); | |
| 86 | + getBundle().getString("has-role-verification", getSecurityContext().getUser().getName(), roles)); | |
| 89 | 87 | } |
| 90 | 88 | |
| 91 | 89 | List<String> userRoles = new ArrayList<String>(); |
| ... | ... | @@ -97,15 +95,13 @@ public class RequiredRoleInterceptor implements Serializable { |
| 97 | 95 | } |
| 98 | 96 | |
| 99 | 97 | if (userRoles.isEmpty()) { |
| 100 | - getLogger() | |
| 101 | - .error(getBundle().getString("does-not-have-role", getSecurityContext().getUser().getName(), | |
| 102 | - roles)); | |
| 98 | + getLogger().severe( | |
| 99 | + getBundle().getString("does-not-have-role", getSecurityContext().getUser().getName(), roles)); | |
| 103 | 100 | |
| 104 | 101 | throw new AuthorizationException(getBundle().getString("does-not-have-role-ui", roles)); |
| 105 | 102 | } |
| 106 | 103 | |
| 107 | - getLogger().debug( | |
| 108 | - getBundle().getString("user-has-role", getSecurityContext().getUser().getName(), userRoles)); | |
| 104 | + getLogger().fine(getBundle().getString("user-has-role", getSecurityContext().getUser().getName(), userRoles)); | |
| 109 | 105 | |
| 110 | 106 | return ic.proceed(); |
| 111 | 107 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/transaction/TransactionalInterceptor.java
| ... | ... | @@ -37,6 +37,7 @@ |
| 37 | 37 | package br.gov.frameworkdemoiselle.transaction; |
| 38 | 38 | |
| 39 | 39 | import java.io.Serializable; |
| 40 | +import java.util.logging.Logger; | |
| 40 | 41 | |
| 41 | 42 | import javax.enterprise.context.ContextNotActiveException; |
| 42 | 43 | import javax.enterprise.context.RequestScoped; |
| ... | ... | @@ -45,8 +46,6 @@ import javax.interceptor.AroundInvoke; |
| 45 | 46 | import javax.interceptor.Interceptor; |
| 46 | 47 | import javax.interceptor.InvocationContext; |
| 47 | 48 | |
| 48 | -import org.slf4j.Logger; | |
| 49 | - | |
| 50 | 49 | import br.gov.frameworkdemoiselle.exception.ApplicationException; |
| 51 | 50 | import br.gov.frameworkdemoiselle.util.Beans; |
| 52 | 51 | import br.gov.frameworkdemoiselle.util.NameQualifier; |
| ... | ... | @@ -115,7 +114,7 @@ public class TransactionalInterceptor implements Serializable { |
| 115 | 114 | |
| 116 | 115 | Object result = null; |
| 117 | 116 | try { |
| 118 | - getLogger().debug(getBundle().getString("transactional-execution", ic.getMethod().toGenericString())); | |
| 117 | + getLogger().fine(getBundle().getString("transactional-execution", ic.getMethod().toGenericString())); | |
| 119 | 118 | result = ic.proceed(); |
| 120 | 119 | |
| 121 | 120 | } catch (Exception cause) { |
| ... | ... | @@ -195,7 +194,7 @@ public class TransactionalInterceptor implements Serializable { |
| 195 | 194 | |
| 196 | 195 | private Logger getLogger() { |
| 197 | 196 | if (logger == null) { |
| 198 | - logger = Beans.getReference(Logger.class, new NameQualifier(TransactionalInterceptor.class.getName())); | |
| 197 | + logger = Beans.getReference(Logger.class, new NameQualifier("br.gov.frameworkdemoiselle.transaction")); | |
| 199 | 198 | } |
| 200 | 199 | |
| 201 | 200 | return logger; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/NameQualifier.java
impl/core/src/test/java/context/staticcontext/ConversationBean.java
impl/core/src/test/java/context/staticcontext/StaticContextTest.java
| ... | ... | @@ -45,10 +45,10 @@ import org.junit.Assert; |
| 45 | 45 | import org.junit.Test; |
| 46 | 46 | import org.junit.runner.RunWith; |
| 47 | 47 | |
| 48 | +import test.Tests; | |
| 48 | 49 | import br.gov.frameworkdemoiselle.context.ConversationContext; |
| 49 | 50 | import br.gov.frameworkdemoiselle.context.SessionContext; |
| 50 | 51 | import br.gov.frameworkdemoiselle.util.Beans; |
| 51 | -import test.Tests; | |
| 52 | 52 | |
| 53 | 53 | @RunWith(Arquillian.class) |
| 54 | 54 | public class StaticContextTest { | ... | ... |
impl/core/src/test/java/logger/LoggerTest.java
| ... | ... | @@ -36,48 +36,74 @@ |
| 36 | 36 | */ |
| 37 | 37 | package logger; |
| 38 | 38 | |
| 39 | -import static junit.framework.Assert.assertTrue; | |
| 39 | +import static junit.framework.Assert.assertEquals; | |
| 40 | + | |
| 41 | +import java.util.logging.Logger; | |
| 40 | 42 | |
| 41 | 43 | import javax.inject.Inject; |
| 42 | 44 | |
| 43 | -import logger.appender.LoggerMemory; | |
| 45 | +import logger.appender.FakeHandler; | |
| 44 | 46 | |
| 45 | 47 | import org.jboss.arquillian.container.test.api.Deployment; |
| 46 | 48 | import org.jboss.arquillian.junit.Arquillian; |
| 47 | 49 | import org.jboss.shrinkwrap.api.spec.JavaArchive; |
| 48 | 50 | import org.junit.Test; |
| 49 | 51 | import org.junit.runner.RunWith; |
| 50 | -import org.slf4j.Logger; | |
| 51 | 52 | |
| 52 | 53 | import test.Tests; |
| 54 | +import br.gov.frameworkdemoiselle.annotation.Name; | |
| 55 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 53 | 56 | |
| 54 | 57 | @RunWith(Arquillian.class) |
| 55 | 58 | public class LoggerTest { |
| 56 | 59 | |
| 57 | - private static final String LOGGER_MESSAGE = "Testing log4j proxy"; | |
| 58 | - | |
| 59 | 60 | @Inject |
| 60 | - private Logger logger; | |
| 61 | + private Logger unnamedLogger; | |
| 61 | 62 | |
| 62 | 63 | @Inject |
| 63 | - private LoggerMemory loggerMemory; | |
| 64 | + @Name("just.another.test") | |
| 65 | + private Logger namedLogger; | |
| 64 | 66 | |
| 65 | 67 | @Deployment |
| 66 | 68 | public static JavaArchive createDeployment() { |
| 67 | - | |
| 68 | 69 | JavaArchive deployment = Tests.createDeployment(LoggerTest.class); |
| 69 | - | |
| 70 | 70 | return deployment; |
| 71 | - | |
| 72 | 71 | } |
| 73 | 72 | |
| 74 | 73 | @Test |
| 75 | - public void testLoggerProducer() { | |
| 74 | + public void unnamedLoggerProducer() { | |
| 75 | + String message = "unnamed producer"; | |
| 76 | + | |
| 77 | + FakeHandler handler = new FakeHandler(); | |
| 78 | + unnamedLogger.addHandler(handler); | |
| 79 | + unnamedLogger.info(message); | |
| 80 | + | |
| 81 | + assertEquals(message, handler.getMessage()); | |
| 82 | + assertEquals(LoggerTest.class.getName(), handler.getName()); | |
| 83 | + } | |
| 76 | 84 | |
| 77 | - logger.info(LOGGER_MESSAGE); | |
| 85 | + @Test | |
| 86 | + public void namedLoggerProducer() { | |
| 87 | + String message = "named producer"; | |
| 78 | 88 | |
| 79 | - assertTrue(loggerMemory.checkMessage(LOGGER_MESSAGE)); | |
| 89 | + FakeHandler handler = new FakeHandler(); | |
| 90 | + namedLogger.addHandler(handler); | |
| 91 | + namedLogger.info(message); | |
| 80 | 92 | |
| 93 | + assertEquals(message, handler.getMessage()); | |
| 94 | + assertEquals("just.another.test", handler.getName()); | |
| 81 | 95 | } |
| 82 | 96 | |
| 97 | + @Test | |
| 98 | + public void loggerProducedByBeansGetReference() { | |
| 99 | + String message = "beans reference producer"; | |
| 100 | + | |
| 101 | + FakeHandler handler = new FakeHandler(); | |
| 102 | + Logger logger = Beans.getReference(Logger.class); | |
| 103 | + logger.addHandler(handler); | |
| 104 | + logger.info(message); | |
| 105 | + | |
| 106 | + assertEquals(message, handler.getMessage()); | |
| 107 | + assertEquals("not.categorized", handler.getName()); | |
| 108 | + } | |
| 83 | 109 | } | ... | ... |
impl/core/src/test/java/logger/appender/FakeHandler.java
0 → 100644
| ... | ... | @@ -0,0 +1,41 @@ |
| 1 | +package logger.appender; | |
| 2 | + | |
| 3 | +import java.util.logging.Handler; | |
| 4 | +import java.util.logging.LogRecord; | |
| 5 | + | |
| 6 | +public class FakeHandler extends Handler { | |
| 7 | + | |
| 8 | + private String name; | |
| 9 | + | |
| 10 | + private String message; | |
| 11 | + | |
| 12 | + public String getName() { | |
| 13 | + return name; | |
| 14 | + } | |
| 15 | + | |
| 16 | + public void setName(String name) { | |
| 17 | + this.name = name; | |
| 18 | + } | |
| 19 | + | |
| 20 | + public String getMessage() { | |
| 21 | + return message; | |
| 22 | + } | |
| 23 | + | |
| 24 | + public void setMessage(String message) { | |
| 25 | + this.message = message; | |
| 26 | + } | |
| 27 | + | |
| 28 | + @Override | |
| 29 | + public void publish(LogRecord record) { | |
| 30 | + this.name = record.getLoggerName(); | |
| 31 | + this.message = record.getMessage(); | |
| 32 | + } | |
| 33 | + | |
| 34 | + @Override | |
| 35 | + public void flush() { | |
| 36 | + } | |
| 37 | + | |
| 38 | + @Override | |
| 39 | + public void close() throws SecurityException { | |
| 40 | + } | |
| 41 | +} | ... | ... |
impl/core/src/test/java/logger/appender/LoggerMemory.java
| ... | ... | @@ -1,56 +0,0 @@ |
| 1 | -package logger.appender; | |
| 2 | - | |
| 3 | -import java.util.ArrayList; | |
| 4 | -import java.util.List; | |
| 5 | - | |
| 6 | -import javax.inject.Inject; | |
| 7 | - | |
| 8 | -import org.slf4j.Logger; | |
| 9 | - | |
| 10 | -public class LoggerMemory { | |
| 11 | - | |
| 12 | - @Inject | |
| 13 | - private Logger logger; | |
| 14 | - | |
| 15 | - private static List<String> messages = new ArrayList<String>(); | |
| 16 | - | |
| 17 | - public boolean checkMessage(String loggerMessage) { | |
| 18 | - | |
| 19 | - logger.info("Verificando a mensagem [" + loggerMessage + "]"); | |
| 20 | - this.showMessages(); | |
| 21 | - | |
| 22 | - for (String mensagem : messages) { | |
| 23 | - | |
| 24 | - if (mensagem.equals(loggerMessage)) { | |
| 25 | - | |
| 26 | - logger.info("Mensagem encontrada"); | |
| 27 | - return true; | |
| 28 | - | |
| 29 | - } | |
| 30 | - | |
| 31 | - } | |
| 32 | - | |
| 33 | - logger.info("Mensagem não encontrada"); | |
| 34 | - return false; | |
| 35 | - | |
| 36 | - } | |
| 37 | - | |
| 38 | - private void showMessages() { | |
| 39 | - | |
| 40 | - logger.debug("Inicio da listagem de mensagens armazenadas..."); | |
| 41 | - for (String message : messages) { | |
| 42 | - | |
| 43 | - logger.debug("\"" + message + "\""); | |
| 44 | - | |
| 45 | - } | |
| 46 | - logger.debug("Fim da listagem de mensagens armazenadas..."); | |
| 47 | - | |
| 48 | - } | |
| 49 | - | |
| 50 | - public static void addMessage(String mensagem) { | |
| 51 | - | |
| 52 | - messages.add(mensagem); | |
| 53 | - | |
| 54 | - } | |
| 55 | - | |
| 56 | -} |
impl/core/src/test/java/logger/appender/MemoryAppender.java
| ... | ... | @@ -1,28 +0,0 @@ |
| 1 | -package logger.appender; | |
| 2 | - | |
| 3 | -import org.apache.log4j.AppenderSkeleton; | |
| 4 | -import org.apache.log4j.spi.LoggingEvent; | |
| 5 | - | |
| 6 | -public class MemoryAppender extends AppenderSkeleton { | |
| 7 | - | |
| 8 | - @Override | |
| 9 | - public void close() { | |
| 10 | - } | |
| 11 | - | |
| 12 | - @Override | |
| 13 | - public boolean requiresLayout() { | |
| 14 | - return false; | |
| 15 | - } | |
| 16 | - | |
| 17 | - @Override | |
| 18 | - protected void append(LoggingEvent loggingEvent) { | |
| 19 | - | |
| 20 | - if (!LoggerMemory.class.getName().equals(loggingEvent.getLoggerName())) { | |
| 21 | - | |
| 22 | - LoggerMemory.addMessage(loggingEvent.getMessage().toString()); | |
| 23 | - | |
| 24 | - } | |
| 25 | - | |
| 26 | - } | |
| 27 | - | |
| 28 | -} |
impl/core/src/test/java/message/MessageContextTest.java
| ... | ... | @@ -36,7 +36,6 @@ |
| 36 | 36 | */ |
| 37 | 37 | package message; |
| 38 | 38 | |
| 39 | -import static junit.framework.Assert.assertEquals; | |
| 40 | 39 | import static junit.framework.Assert.assertTrue; |
| 41 | 40 | |
| 42 | 41 | import javax.inject.Inject; |
| ... | ... | @@ -54,7 +53,6 @@ import br.gov.frameworkdemoiselle.context.RequestContext; |
| 54 | 53 | import br.gov.frameworkdemoiselle.message.DefaultMessage; |
| 55 | 54 | import br.gov.frameworkdemoiselle.message.Message; |
| 56 | 55 | import br.gov.frameworkdemoiselle.message.MessageContext; |
| 57 | -import br.gov.frameworkdemoiselle.message.SeverityType; | |
| 58 | 56 | import br.gov.frameworkdemoiselle.util.Beans; |
| 59 | 57 | |
| 60 | 58 | @RunWith(Arquillian.class) |
| ... | ... | @@ -77,76 +75,6 @@ public class MessageContextTest { |
| 77 | 75 | } |
| 78 | 76 | |
| 79 | 77 | @Test |
| 80 | - @Deprecated | |
| 81 | - public void testAddMessageWithoutParams() { | |
| 82 | - RequestContext context = Beans.getReference(RequestContext.class); | |
| 83 | - | |
| 84 | - context.activate(); | |
| 85 | - Message message = new DefaultMessage("Menssage without param"); | |
| 86 | - DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | |
| 87 | - | |
| 88 | - messageContext.add(message); | |
| 89 | - assertEquals(appender.getMessages().size(), 1); | |
| 90 | - context.deactivate(); | |
| 91 | - } | |
| 92 | - | |
| 93 | - @Test | |
| 94 | - @Deprecated | |
| 95 | - public void testAddMessageWithoutParamsIfSeverityIsInfo() { | |
| 96 | - RequestContext context = Beans.getReference(RequestContext.class); | |
| 97 | - | |
| 98 | - context.activate(); | |
| 99 | - Message message = new DefaultMessage("Menssage without param"); | |
| 100 | - DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | |
| 101 | - | |
| 102 | - messageContext.add(message); | |
| 103 | - assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.INFO); | |
| 104 | - context.deactivate(); | |
| 105 | - } | |
| 106 | - | |
| 107 | - @Test | |
| 108 | - @Deprecated | |
| 109 | - public void testAddMessageWitSeverityInfo() { | |
| 110 | - RequestContext context = Beans.getReference(RequestContext.class); | |
| 111 | - | |
| 112 | - context.activate(); | |
| 113 | - Message message = new DefaultMessage("Menssage without param", SeverityType.INFO); | |
| 114 | - DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | |
| 115 | - | |
| 116 | - messageContext.add(message); | |
| 117 | - assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.INFO); | |
| 118 | - context.deactivate(); | |
| 119 | - } | |
| 120 | - | |
| 121 | - @Test | |
| 122 | - @Deprecated | |
| 123 | - public void testAddMessageWitSeverityWarn() { | |
| 124 | - RequestContext context = Beans.getReference(RequestContext.class); | |
| 125 | - | |
| 126 | - context.activate(); | |
| 127 | - Message message = new DefaultMessage("Menssage without param", SeverityType.WARN); | |
| 128 | - DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | |
| 129 | - | |
| 130 | - messageContext.add(message); | |
| 131 | - assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.WARN); | |
| 132 | - context.deactivate(); | |
| 133 | - } | |
| 134 | - | |
| 135 | - @Test | |
| 136 | - @Deprecated | |
| 137 | - public void testAddMessageWitSeverityErro() { | |
| 138 | - RequestContext context = Beans.getReference(RequestContext.class); | |
| 139 | - | |
| 140 | - context.activate(); | |
| 141 | - Message message = new DefaultMessage("Menssage without param", SeverityType.ERROR); | |
| 142 | - DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | |
| 143 | - | |
| 144 | - messageContext.add(message); | |
| 145 | - assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.ERROR); | |
| 146 | - context.deactivate(); | |
| 147 | - } | |
| 148 | - | |
| 149 | - @Test | |
| 150 | 78 | public void testRecoverStringMessageWithParams() { |
| 151 | 79 | RequestContext context = Beans.getReference(RequestContext.class); |
| 152 | 80 | |
| ... | ... | @@ -159,20 +87,6 @@ public class MessageContextTest { |
| 159 | 87 | } |
| 160 | 88 | |
| 161 | 89 | @Test |
| 162 | - @Deprecated | |
| 163 | - public void testRecoverMessageWithParams() { | |
| 164 | - RequestContext context = Beans.getReference(RequestContext.class); | |
| 165 | - | |
| 166 | - context.activate(); | |
| 167 | - Message message = new DefaultMessage("Message with {0} param"); | |
| 168 | - DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | |
| 169 | - | |
| 170 | - messageContext.add(message, 1); | |
| 171 | - assertTrue(appender.getMessages().get(0).getText().equals("Message with 1 param")); | |
| 172 | - context.deactivate(); | |
| 173 | - } | |
| 174 | - | |
| 175 | - @Test | |
| 176 | 90 | public void testMessageWithResourceBundle() { |
| 177 | 91 | bundleCustom = Beans.getReference(MessageWithResourceBundle.class); |
| 178 | 92 | String expected = "Mensagem sem parâmetro"; | ... | ... |