KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jms > container > ContainerObjectOverridesInterceptor


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

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 /**
14  * An interceptor for providing standard object methods
15  *
16  * @author <a HREF="mailto:adrian@jboss.org>Adrian Brock</a>
17  * @version $Revision: 1.4 $
18  */

19 public class ContainerObjectOverridesInterceptor
20    implements Interceptor
21 {
22    // Constants -----------------------------------------------------
23

24    // Attributes ----------------------------------------------------
25

26    // Static --------------------------------------------------------
27

28    public static ContainerObjectOverridesInterceptor singleton = new ContainerObjectOverridesInterceptor();
29
30    // Constructors --------------------------------------------------
31

32    // Public --------------------------------------------------------
33

34    // Interceptor implementation -----------------------------------
35

36    public String JavaDoc getName()
37    {
38       return "ContainerObjectOverridesInterceptor";
39    }
40
41    public Object JavaDoc invoke(Invocation invocation) throws Throwable JavaDoc
42    {
43       MethodInvocation mi = (MethodInvocation) invocation;
44       String JavaDoc 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    // Protected ------------------------------------------------------
56

57    protected String JavaDoc toString(MethodInvocation mi)
58    {
59       Object JavaDoc proxy = Container.getProxy(mi);
60       String JavaDoc className = proxy.getClass().getInterfaces()[0].getName();
61       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(20);
62       buffer.append(className).append('@').append(System.identityHashCode(proxy));
63       return buffer.toString();
64    }
65
66    protected Boolean JavaDoc equals(MethodInvocation mi)
67    {
68       return new Boolean JavaDoc(Container.getProxy(mi).equals(mi.getArguments()[0]));
69    }
70
71    protected Integer JavaDoc hashCode(MethodInvocation mi)
72    {
73       return new Integer JavaDoc(System.identityHashCode(Container.getProxy(mi)));
74    }
75    
76    // Package Private ------------------------------------------------
77

78    // Private --------------------------------------------------------
79

80    // Inner Classes --------------------------------------------------
81

82 }
83
Popular Tags