KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > joinpoint > MethodInvocationWrapper


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.aop.joinpoint;
23
24 import org.jboss.aop.Advisor;
25 import org.jboss.aop.metadata.MetaDataResolver;
26 import org.jboss.aop.metadata.SimpleMetaData;
27
28 import java.lang.reflect.Method JavaDoc;
29 import java.util.Map JavaDoc;
30
31 /**
32  * This wrapper class allows you to insert a chain of interceptors into the middle of a call stack.
33  *
34  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
35  * @version $Revision: 37406 $
36  *
37  **/

38 public class MethodInvocationWrapper extends MethodInvocation
39 {
40    private static final long serialVersionUID = 6399861718513077210L;
41
42    MethodInvocation wrapped;
43
44    public MethodInvocationWrapper(MethodInvocation wrapped, org.jboss.aop.advice.Interceptor[] interceptors)
45    {
46       super(interceptors);
47       this.wrapped = wrapped;
48    }
49
50    public Object JavaDoc getMetaData(Object JavaDoc group, Object JavaDoc attr)
51    {
52       return wrapped.getMetaData(group, attr);
53    }
54
55    public Object JavaDoc invokeNext() throws Throwable JavaDoc
56    {
57       if (interceptors != null && currentInterceptor < interceptors.length)
58       {
59          try
60          {
61             return interceptors[currentInterceptor++].invoke(this);
62          }
63          finally
64          {
65             // so that interceptors like clustering can reinvoke down the chain
66
currentInterceptor--;
67          }
68       }
69       try
70       {
71          return wrapped.invokeNext();
72       }
73       finally
74       {
75          responseContextInfo = wrapped.getResponseContextInfo();
76       }
77    }
78
79    public MetaDataResolver getInstanceResolver()
80    {
81       return wrapped.getInstanceResolver();
82    }
83
84    public Object JavaDoc[] getArguments()
85    {
86       return wrapped.getArguments();
87    }
88
89    public void setArguments(Object JavaDoc[] args)
90    {
91       wrapped.setArguments(args);
92    }
93    public Object JavaDoc getTargetObject()
94    {
95       return wrapped.getTargetObject();
96    }
97
98    public Invocation copy()
99    {
100       MethodInvocationWrapper invocation = new MethodInvocationWrapper((MethodInvocation)wrapped.copy(), interceptors);
101       invocation.currentInterceptor = this.currentInterceptor;
102       return invocation;
103    }
104
105    public Method JavaDoc getMethod()
106    {
107       return wrapped.getMethod();
108    }
109
110    public Method JavaDoc getActualMethod()
111    {
112       return wrapped.getActualMethod();
113    }
114
115    public long getMethodHash()
116    {
117       return wrapped.getMethodHash();
118    }
119
120    public Advisor getAdvisor()
121    {
122       return wrapped.getAdvisor();
123    }
124
125    public Map JavaDoc getResponseContextInfo()
126    {
127       return wrapped.getResponseContextInfo();
128    }
129
130    public void setResponseContextInfo(Map JavaDoc responseContextInfo)
131    {
132       wrapped.setResponseContextInfo(responseContextInfo);
133    }
134
135    public Object JavaDoc getResponseAttachment(Object JavaDoc key)
136    {
137       return wrapped.getResponseAttachment(key);
138    }
139
140    public void addResponseAttachment(Object JavaDoc key, Object JavaDoc val)
141    {
142       wrapped.addResponseAttachment(key, val);
143    }
144
145    public SimpleMetaData getMetaData()
146    {
147       return wrapped.getMetaData();
148    }
149
150    public void setMetaData(SimpleMetaData data)
151    {
152       wrapped.setMetaData(data);
153    }
154
155    public void setTargetObject(Object JavaDoc targetObject)
156    {
157       wrapped.setTargetObject(targetObject);
158    }
159
160 }
161
Popular Tags