01: /* PAT: Persistent Applications Toolkit (patsystem.sf.net)
02: * Copyright (C) 2004, 2005 Tomasz Nazar, nthx at irc dot pl
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: * Full version of the license is /docs/LICENSE.txt
19: */
20: package org.nthx.util.jbossaop;
21:
22: import org.apache.log4j.Logger;
23: import org.jboss.aop.joinpoint.ConstructorInvocation;
24: import org.jboss.aop.joinpoint.Invocation;
25: import org.jboss.aop.joinpoint.MethodInvocation;
26:
27: /** Just for logging execution of interceptors.
28: *
29: * @version $Id: InterceptorLogger.java 3725 2005-06-09 23:57:03Z nthx $
30: * @author nthx@users.sourceforge.net
31: */
32: public class InterceptorLogger extends DefaultInterceptorImpl {
33: private transient static Logger log = Logger.getLogger("pat");
34:
35: public Object invoke(Invocation invocation) throws Throwable {
36: log.debug("------>>>: " + getInvocationName(invocation)
37: + " for :" + getInfo(invocation));
38: Object result = invocation.invokeNext();
39: log.debug(" **<<--|: " + getInvocationName(invocation));
40: return result;
41: }
42:
43: //-----------------------------------------------------------
44: private Invocation getBaseInvocation(Invocation invocation) {
45: return (Invocation) ((MethodInvocation) invocation)
46: .getArguments()[0];
47: }
48:
49: private String getInvocationName(Invocation invocation) {
50: return getBaseInvocation(invocation).toString().substring(
51: getBaseInvocation(invocation).toString().lastIndexOf(
52: ".") + 1);
53: }
54:
55: private String getInfo(Invocation invocation) {
56: String info;
57: Invocation baseInvocation = getBaseInvocation(invocation);
58: if (baseInvocation instanceof MethodInvocation) {
59: info = ((MethodInvocation) baseInvocation).getMethod()
60: .toString();
61: } else if (baseInvocation instanceof ConstructorInvocation)
62: info = ((ConstructorInvocation) baseInvocation)
63: .getConstructor().getName();
64: else
65: info = "unknown, TODO";
66: return info;
67: }
68:
69: }
|