KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > aspectj > AspectJWeaverMessageHandler


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.aop.aspectj;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.aspectj.bridge.AbortException;
22 import org.aspectj.bridge.IMessage;
23 import org.aspectj.bridge.IMessage.Kind;
24 import org.aspectj.bridge.IMessageHandler;
25
26 /**
27  * Implementation of AspectJ's IMessageHandler interface that routes
28  * AspectJ weaving messages through the same logging system as the
29  * regular Spring messages.
30  *
31  * Pass the option
32  * "-XmessageHandlerClass:org.springframework.aop.aspectj.AspectJWeaverMessageHandler"
33  * to the weaver (for example, using <weaver options="..."/&gt in a
34  * "META-INF/aop.xml" file).
35  *
36  * @author Adrian Colyer
37  * @author Juergen Hoeller
38  * @since 2.0
39  */

40 public class AspectJWeaverMessageHandler implements IMessageHandler {
41
42     private static final String JavaDoc AJ_ID = "[AspectJ] ";
43     
44     private static final Log logger = LogFactory.getLog("AspectJ Weaver");
45     
46
47     public boolean handleMessage(IMessage message) throws AbortException {
48         Kind messageKind = message.getKind();
49
50         if (logger.isDebugEnabled() || logger.isTraceEnabled()) {
51             if (messageKind == IMessage.DEBUG) {
52                 logger.debug(makeMessageFor(message));
53                 return true;
54             }
55         }
56         
57         if (logger.isInfoEnabled()) {
58             if ((messageKind == IMessage.INFO) || (messageKind == IMessage.WEAVEINFO)) {
59                 logger.info(makeMessageFor(message));
60                 return true;
61             }
62         }
63         
64         if (logger.isWarnEnabled()) {
65             if (messageKind == IMessage.WARNING) {
66                 logger.warn(makeMessageFor(message));
67                 return true;
68             }
69         }
70         
71         if (logger.isErrorEnabled()) {
72             if (messageKind == IMessage.ERROR) {
73                 logger.error(makeMessageFor(message));
74                 return true;
75             }
76         }
77         
78         if (logger.isFatalEnabled()) {
79             if (messageKind == IMessage.ABORT) {
80                 logger.fatal(makeMessageFor(message));
81                 return true;
82             }
83         }
84         
85         return false;
86     }
87     
88     private String JavaDoc makeMessageFor(IMessage aMessage) {
89         return AJ_ID + aMessage.getMessage();
90     }
91
92     public boolean isIgnoring(Kind messageKind) {
93         // We want to see everything, and allow configuration of log levels dynamically.
94
return false;
95     }
96
97     public void dontIgnore(Kind messageKind) {
98         // We weren't ignoring anything anyway...
99
}
100
101     public void ignore(Kind kind) {
102         // We weren't ignoring anything anyway...
103
}
104
105 }
106
Popular Tags