KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > EJBInvocation


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.ejb3;
23
24 import java.lang.reflect.InvocationTargetException JavaDoc;
25 import java.lang.reflect.Method JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Map JavaDoc;
28 import org.jboss.aop.advice.Interceptor;
29 import org.jboss.aop.joinpoint.Invocation;
30 import org.jboss.aop.metadata.SimpleMetaData;
31 import org.jboss.aop.metadata.ThreadMetaData;
32 import org.jboss.logging.Logger;
33
34 /**
35  * Comment
36  *
37  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
38  * @version $Revision: 37459 $
39  */

40 public abstract class EJBInvocation implements Invocation
41 {
42    private static final Logger log = Logger.getLogger(EJBInvocation.class);
43    
44    protected transient Interceptor[] interceptors;
45    protected long methodHash;
46    protected transient int currentInterceptor = 0;
47    protected transient Method JavaDoc method;
48    protected Object JavaDoc[] arguments;
49    protected SimpleMetaData metadata = null;
50    protected transient Map JavaDoc responseContextInfo = null;
51
52    protected EJBInvocation(Method JavaDoc method, long methodHash, Object JavaDoc[] arguments, Interceptor[] interceptors)
53    {
54       this.method = method;
55       this.methodHash = methodHash;
56       this.arguments = arguments;
57       this.interceptors = interceptors;
58    }
59
60    protected EJBInvocation()
61    {
62    }
63
64    public Object JavaDoc invokeNext() throws Throwable JavaDoc
65    {
66       if (currentInterceptor < interceptors.length)
67       {
68          try
69          {
70             return interceptors[currentInterceptor++].invoke(this);
71          }
72          finally
73          {
74             // so that interceptors like clustering can reinvoke down the chain
75
currentInterceptor--;
76          }
77       }
78       try
79       {
80          return method.invoke(getTargetObject(), getArguments());
81       }
82       catch (InvocationTargetException JavaDoc e)
83       {
84          throw e.getTargetException();
85       }
86    }
87
88    public Method JavaDoc getMethod()
89    {
90       return method;
91    }
92
93    public long getMethodHash()
94    {
95       return methodHash;
96    }
97
98    public Interceptor[] getInterceptors()
99    {
100       return interceptors;
101    }
102
103    public void setInterceptors(Interceptor[] interceptors)
104    {
105       this.interceptors = interceptors;
106    }
107
108    public Object JavaDoc[] getArguments()
109    {
110       return arguments;
111    }
112
113    public void setArguments(Object JavaDoc[] args)
114    {
115       this.arguments = args;
116    }
117
118    public Object JavaDoc getMetaData(Object JavaDoc key, Object JavaDoc attr)
119    {
120       // todo: set up the chain for metadata resolving
121
Object JavaDoc value = null;
122       if (metadata != null) value = metadata.getMetaData(key, attr);
123       if (value != null) return value;
124       value = ThreadMetaData.instance().getMetaData(key, attr);
125       return value;
126    }
127
128    public Map JavaDoc getResponseContextInfo()
129    {
130       return responseContextInfo;
131    }
132
133    public void setResponseContextInfo(Map JavaDoc responseContextInfo)
134    {
135       this.responseContextInfo = responseContextInfo;
136    }
137
138    public void addResponseAttachment(Object JavaDoc key, Object JavaDoc val)
139    {
140       if (responseContextInfo == null) responseContextInfo = new HashMap JavaDoc();
141       responseContextInfo.put(key, val);
142    }
143
144    public Object JavaDoc getResponseAttachment(Object JavaDoc key)
145    {
146       if (responseContextInfo == null) return null;
147       return responseContextInfo.get(key);
148    }
149
150    public SimpleMetaData getMetaData()
151    {
152       if (metadata == null) metadata = new SimpleMetaData();
153       return metadata;
154    }
155
156    public void setMetaData(SimpleMetaData data)
157    {
158       this.metadata = data;
159    }
160
161    public Object JavaDoc invokeNext(Interceptor[] newInterceptors) throws Throwable JavaDoc
162    {
163       throw new RuntimeException JavaDoc("NOT IMPLEMENTED");
164    }
165 }
166
Popular Tags