KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > tracing > DebuggingWrapper


1 /*
2   Copyright (C) 2001 Renaud Pawlak
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program 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
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.tracing;
19
20 import org.aopalliance.intercept.ConstructorInvocation;
21 import org.aopalliance.intercept.MethodInvocation;
22 import org.objectweb.jac.core.*;
23 import java.util.*;
24 import org.objectweb.jac.core.dist.*;
25
26 /**
27  * This wrapper upcalls the debugger when a method that have to be
28  * debugged is called and returns.
29  *
30  * @see Debugger */

31
32 public class DebuggingWrapper extends Wrapper {
33
34     /** The actual debugger. */
35     public Debugger debugger = null;
36
37     /**
38      * The wrapper constructor.
39      *
40      * @param ac the aspect that manages this wrapper
41      */

42     public DebuggingWrapper(AspectComponent ac) {
43         super(ac);
44         debugger = (Debugger) NameRepository.get().getObject("debugger0");
45         if (debugger == null) {
46             debugger = new Debugger();
47         }
48     }
49
50     /**
51      * This wrapping method is used to upcall the debugger at each
52      * method call.
53      *
54      * @return the return value of the orginal method
55      *
56      * @see Debugger#startOfMethod(String,String,String,Object[])
57      * @see Debugger#endOfMethod(String,String,String,Object[],Object,long) */

58
59     public Object JavaDoc step(Interaction interaction) {
60
61         String JavaDoc wrappeeName =
62             (String JavaDoc) NameRepository.get().getName(interaction.wrappee);
63         debugger.startOfMethod(
64             Distd.getLocalContainerName(),
65             wrappeeName,
66             interaction.method.getName(),
67             interaction.args);
68         Date d1 = new Date();
69         Object JavaDoc ret = proceed(interaction);
70         Date d2 = new Date();
71
72         debugger.endOfMethod(
73             Distd.getLocalContainerName(),
74             wrappeeName,
75             interaction.method.getName(),
76             interaction.args,
77             ret,
78             d2.getTime() - d1.getTime());
79
80         return ret;
81     }
82
83     public Object JavaDoc invoke(MethodInvocation invocation) throws Throwable JavaDoc {
84         return step((Interaction) invocation);
85     }
86
87     public Object JavaDoc construct(ConstructorInvocation invocation)
88         throws Throwable JavaDoc {
89         return step((Interaction) invocation);
90     }
91
92 }
93
Popular Tags