1 7 package org.jboss.jms.container; 8 9 import org.jboss.aop.advice.Interceptor; 10 import org.jboss.aop.joinpoint.Invocation; 11 import org.jboss.aop.joinpoint.MethodInvocation; 12 13 19 public class ContainerObjectOverridesInterceptor 20 implements Interceptor 21 { 22 24 26 28 public static ContainerObjectOverridesInterceptor singleton = new ContainerObjectOverridesInterceptor(); 29 30 32 34 36 public String getName() 37 { 38 return "ContainerObjectOverridesInterceptor"; 39 } 40 41 public Object invoke(Invocation invocation) throws Throwable 42 { 43 MethodInvocation mi = (MethodInvocation) invocation; 44 String methodName = mi.getMethod().getName(); 45 if (methodName.equals("equals")) 46 return equals(mi); 47 else if (methodName.equals("hashCode")) 48 return hashCode(mi); 49 else if (methodName.equals("toString")) 50 return toString(mi); 51 else 52 return invocation.invokeNext(); 53 } 54 55 57 protected String toString(MethodInvocation mi) 58 { 59 Object proxy = Container.getProxy(mi); 60 String className = proxy.getClass().getInterfaces()[0].getName(); 61 StringBuffer buffer = new StringBuffer (20); 62 buffer.append(className).append('@').append(System.identityHashCode(proxy)); 63 return buffer.toString(); 64 } 65 66 protected Boolean equals(MethodInvocation mi) 67 { 68 return new Boolean (Container.getProxy(mi).equals(mi.getArguments()[0])); 69 } 70 71 protected Integer hashCode(MethodInvocation mi) 72 { 73 return new Integer (System.identityHashCode(Container.getProxy(mi))); 74 } 75 76 78 80 82 } 83 | Popular Tags |