1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * 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.mx.server;
23
24 import java.util.Arrays;
25
26 import org.jboss.mx.interceptor.AbstractInterceptor;
27
28
29 /**
30 *
31 * @author <a href="mailto:juha@jboss.org">Juha Lindfors</a>.
32 * @version $Revision: 37459 $
33 *
34 */
35 public class Invocation
36 extends InvocationContext
37 {
38 private Object[] args;
39
40 private InvocationContext ctx;
41
42 // Constructors --------------------------------------------------
43 public Invocation() {}
44
45 public Invocation(InvocationContext ic)
46 {
47 addContext(ic);
48 }
49
50
51 // Public --------------------------------------------------------
52
53 public void addContext(final InvocationContext ctx)
54 {
55 super.copy(ctx);
56 this.ctx = ctx;
57 }
58
59 public void setArgs(Object[] args)
60 {
61 this.args = args;
62 }
63
64 public Object[] getArgs()
65 {
66 return args;
67 }
68
69 int ic_counter = 0;
70
71 public AbstractInterceptor nextInterceptor()
72 {
73 if (interceptors == null)
74 return null;
75
76 if (ic_counter < interceptors.size())
77 return (AbstractInterceptor)interceptors.get(ic_counter++);
78 else
79 return null;
80 }
81
82
83 public Object invoke() throws Throwable
84 {
85 AbstractInterceptor ic = nextInterceptor();
86
87 if (ic == null)
88 return dispatch();
89 else
90 return ic.invoke(this);
91
92 }
93
94 public Object dispatch() throws Throwable
95 {
96 return dispatcher.invoke(this);
97 }
98
99 Object retVal = null;
100
101
102
103 public String toString()
104 {
105 StringBuffer buffer = new StringBuffer();
106 buffer.append(getName());
107 String[] sig = getSignature();
108 if (sig != null)
109 buffer.append(Arrays.asList(sig));
110 buffer.append(' ').append(getType());
111 return buffer.toString();
112 }
113
114 public Class getAttributeTypeClass() throws ClassNotFoundException
115 {
116 return ctx.getAttributeTypeClass();
117 }
118
119 public Class getReturnTypeClass() throws ClassNotFoundException
120 {
121 return ctx.getReturnTypeClass();
122 }
123
124 public Class[] getSignatureClasses() throws ClassNotFoundException
125 {
126 return ctx.getSignatureClasses();
127 }
128 }
129
130
131
132