KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.reflect.InvocationTargetException JavaDoc;
10
11 import org.jboss.aop.advice.Interceptor;
12 import org.jboss.aop.joinpoint.Invocation;
13 import org.jboss.aop.joinpoint.MethodInvocation;
14
15 /**
16  * An interceptor for dispatching invocations.
17  *
18  * @author <a HREF="mailto:adrian@jboss.org>Adrian Brock</a>
19  * @version $Revision: 1.3 $
20  */

21 public class DispatchInterceptor
22    implements Interceptor
23 {
24    // Constants -----------------------------------------------------
25

26    // Attributes ----------------------------------------------------
27

28    /** The target object */
29    private Object JavaDoc target;
30
31    // Static --------------------------------------------------------
32

33    // Constructors --------------------------------------------------
34

35    /**
36     * Create a new dispatch interceptor
37     *
38     * @param target the target object
39     */

40    public DispatchInterceptor(Object JavaDoc target)
41    {
42       this.target = target;
43    }
44
45    // Public --------------------------------------------------------
46

47    // Interceptor implementation -----------------------------------
48

49    public String JavaDoc getName()
50    {
51       return "DispatchInterceptor";
52    }
53
54    public Object JavaDoc invoke(Invocation invocation) throws Throwable JavaDoc
55    {
56       MethodInvocation mi = (MethodInvocation) invocation;
57       try
58       {
59          return mi.getMethod().invoke(target, mi.getArguments());
60       }
61       catch (Throwable JavaDoc t)
62       {
63          if (t instanceof InvocationTargetException JavaDoc)
64             throw ((InvocationTargetException JavaDoc) t).getTargetException();
65          throw t;
66       }
67    }
68
69    // Protected ------------------------------------------------------
70

71    // Package Private ------------------------------------------------
72

73    // Private --------------------------------------------------------
74

75    // Inner Classes --------------------------------------------------
76

77 }
78
Popular Tags