01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.test.remoting.interceptor;
23:
24: import java.io.Serializable;
25: import org.jboss.aop.advice.Interceptor;
26: import org.jboss.aop.joinpoint.Invocation;
27: import org.jboss.aop.joinpoint.InvocationBase;
28:
29: /**
30: * Just extending InvocationBase and using implementation from
31: * MethodCallByMethodInvocation for the getWrapper() and copy() methods.
32: * Just need a simple invocation instance for testing.
33: *
34: * @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
35: */
36: public class TestInvocation extends InvocationBase implements
37: Serializable {
38: private Object arg;
39:
40: public TestInvocation(Interceptor[] interceptorStack) {
41: super (interceptorStack);
42: }
43:
44: /**
45: * Get a wrapper invocation object that can insert a new chain of interceptors
46: * at runtime to the invocation flow. CFlow makes use of this.
47: * When the wrapper object finishes its invocation chain it delegates back to
48: * the wrapped invocation.
49: *
50: * @param newchain
51: * @return
52: */
53: public Invocation getWrapper(Interceptor[] newchain) {
54: int size = interceptors.length + newchain.length;
55: Interceptor[] newInterceptors = new Interceptor[size];
56: size = 0;
57: for (int i = 0; i < interceptors.length; i++, size++) {
58: newInterceptors[i] = interceptors[i];
59: }
60: for (int x = 0; x < newchain.length; x++, size++) {
61: newInterceptors[x] = newchain[x];
62: }
63: TestInvocation newInvocation = new TestInvocation(
64: newInterceptors);
65: newInvocation.setMetaData(getMetaData());
66: newInvocation.setArgument(getArgument());
67: return newInvocation;
68: }
69:
70: /**
71: * Copies complete state of Invocation object so that it could possibly
72: * be reused in a spawned thread.
73: *
74: * @return
75: */
76: public Invocation copy() {
77: return getWrapper(new Interceptor[0]);
78: }
79:
80: public void setArgument(Object testTarget) {
81: this .arg = testTarget;
82: }
83:
84: public Object getArgument() {
85: return arg;
86: }
87: }
|