KickJava   Java API By Example, From Geeks To Geeks.

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


1 /***************************************
2  * *
3  * JBoss: The OpenSource J2EE WebOS *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  ***************************************/

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

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

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

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