KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > interceptor > TestInvocation


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.remoting.interceptor;
8
9 import org.jboss.aop.advice.Interceptor;
10 import org.jboss.aop.joinpoint.Invocation;
11 import org.jboss.aop.joinpoint.InvocationBase;
12
13 import java.io.Serializable JavaDoc;
14
15 /**
16  * Just extending InvocationBase and using implementation from
17  * MethodCallByMethodInvocation for the getWrapper() and copy() methods.
18  * Just need a simple invocation instance for testing.
19  *
20  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
21  */

22 public class TestInvocation extends InvocationBase implements Serializable JavaDoc
23 {
24    private Object JavaDoc arg;
25
26    public TestInvocation(Interceptor[] interceptorStack)
27    {
28       super(interceptorStack);
29    }
30
31    /**
32     * Get a wrapper invocation object that can insert a new chain of interceptors
33     * at runtime to the invocation flow. CFlow makes use of this.
34     * When the wrapper object finishes its invocation chain it delegates back to
35     * the wrapped invocation.
36     *
37     * @param newchain
38     * @return
39     */

40    public Invocation getWrapper(Interceptor[] newchain)
41    {
42       int size = interceptors.length + newchain.length;
43       Interceptor[] newInterceptors = new Interceptor[size];
44       size = 0;
45       for(int i = 0; i < interceptors.length; i++, size++)
46       {
47          newInterceptors[i] = interceptors[i];
48       }
49       for(int x = 0; x < newchain.length; x++, size++)
50       {
51          newInterceptors[x] = newchain[x];
52       }
53       TestInvocation newInvocation = new TestInvocation(newInterceptors);
54       newInvocation.setMetaData(getMetaData());
55       newInvocation.setArgument(getArgument());
56       return newInvocation;
57    }
58
59    /**
60     * Copies complete state of Invocation object so that it could possibly
61     * be reused in a spawned thread.
62     *
63     * @return
64     */

65    public Invocation copy()
66    {
67       return getWrapper(new Interceptor[0]);
68    }
69
70    public void setArgument(Object JavaDoc testTarget)
71    {
72       this.arg = testTarget;
73    }
74
75    public Object JavaDoc getArgument()
76    {
77       return arg;
78    }
79 }
80
Popular Tags