1 15 package hivemind.test.services.impl; 16 17 import java.lang.reflect.InvocationHandler ; 18 import java.lang.reflect.Method ; 19 import java.lang.reflect.Proxy ; 20 import java.util.ArrayList ; 21 import java.util.List ; 22 23 import org.apache.hivemind.InterceptorStack; 24 import org.apache.hivemind.internal.Module; 25 import org.apache.hivemind.service.ClassFabUtils; 26 27 32 public class TrackerFactory 33 { 34 private static final List _list = new ArrayList (); 35 36 private String _name; 37 38 private class TrackerHandler implements InvocationHandler 39 { 40 private TrackerHandler(Object inner) 41 { 42 _inner = inner; 43 } 44 45 private Object _inner; 46 47 public Object invoke(Object proxy, Method method, Object [] args) throws Throwable 48 { 49 53 if (!ClassFabUtils.isToString(method)) 54 _list.add(_name + ":" + method.getName()); 55 56 return method.invoke(_inner, args); 57 } 58 59 } 60 61 public static void reset() 62 { 63 _list.clear(); 64 } 65 66 public static List getInvocations() 67 { 68 return _list; 69 } 70 71 public void createInterceptor( 72 InterceptorStack stack, 73 Module contributingModule, 74 Object parameters) 75 { 76 Class interfaceClass = stack.getServiceInterface(); 77 ClassLoader loader = contributingModule.getClassResolver().getClassLoader(); 78 79 Object top = stack.peek(); 80 81 Object interceptor = 82 Proxy.newProxyInstance(loader, new Class [] { interfaceClass }, new TrackerHandler(top)); 83 84 stack.push(interceptor); 85 } 86 87 public String getName() 88 { 89 return _name; 90 } 91 92 public void setName(String string) 93 { 94 _name = string; 95 } 96 97 } 98 | Popular Tags |