001 /* 002 Copyright (C) 2001 Renaud Pawlak 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public License 015 along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 017 018 package org.objectweb.jac.aspects.tracing; 019 020 import org.aopalliance.intercept.ConstructorInvocation; 021 import org.aopalliance.intercept.MethodInvocation; 022 import org.objectweb.jac.core.*; 023 import java.util.*; 024 import org.objectweb.jac.core.dist.*; 025 026 /** 027 * This wrapper upcalls the debugger when a method that have to be 028 * debugged is called and returns. 029 * 030 * @see Debugger */ 031 032 public class DebuggingWrapper extends Wrapper { 033 034 /** The actual debugger. */ 035 public Debugger debugger = null; 036 037 /** 038 * The wrapper constructor. 039 * 040 * @param ac the aspect that manages this wrapper 041 */ 042 public DebuggingWrapper(AspectComponent ac) { 043 super(ac); 044 debugger = (Debugger) NameRepository.get().getObject("debugger0"); 045 if (debugger == null) { 046 debugger = new Debugger(); 047 } 048 } 049 050 /** 051 * This wrapping method is used to upcall the debugger at each 052 * method call. 053 * 054 * @return the return value of the orginal method 055 * 056 * @see Debugger#startOfMethod(String,String,String,Object[]) 057 * @see Debugger#endOfMethod(String,String,String,Object[],Object,long) */ 058 059 public Object step(Interaction interaction) { 060 061 String wrappeeName = 062 (String) NameRepository.get().getName(interaction.wrappee); 063 debugger.startOfMethod( 064 Distd.getLocalContainerName(), 065 wrappeeName, 066 interaction.method.getName(), 067 interaction.args); 068 Date d1 = new Date(); 069 Object ret = proceed(interaction); 070 Date d2 = new Date(); 071 072 debugger.endOfMethod( 073 Distd.getLocalContainerName(), 074 wrappeeName, 075 interaction.method.getName(), 076 interaction.args, 077 ret, 078 d2.getTime() - d1.getTime()); 079 080 return ret; 081 } 082 083 public Object invoke(MethodInvocation invocation) throws Throwable { 084 return step((Interaction) invocation); 085 } 086 087 public Object construct(ConstructorInvocation invocation) 088 throws Throwable { 089 return step((Interaction) invocation); 090 } 091 092 }