01: /*
02: * JFox - The most lightweight Java EE Application Server!
03: * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
04: *
05: * JFox is licenced and re-distributable under GNU LGPL.
06: */
07: package org.jfox.ejb3.invocation;
08:
09: import java.util.Iterator;
10:
11: import org.jfox.ejb3.EJBInvocation;
12: import org.jfox.ejb3.EJBInvocationHandler;
13:
14: /**
15: * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>
16: */
17: public class ThreadContextEJBInvocationHandler extends
18: EJBInvocationHandler {
19:
20: public Object invoke(final EJBInvocation invocation,
21: final Iterator<EJBInvocationHandler> chain)
22: throws Exception {
23: ClassLoader oldLoader = Thread.currentThread()
24: .getContextClassLoader();
25: // 设置 ThreadContextClassLoader,以便执行 ejb 方法时,能æ£ç¡®è£…载需è¦?çš„ç±»
26: Thread.currentThread().setContextClassLoader(
27: invocation.getTarget().getClass().getClassLoader());
28: // 将 invocation 关�到 Thread,以便 EJBContainer�以 获得 java:comp/env
29: EJBInvocation.setCurrent(invocation);
30:
31: try {
32:
33: return super .next(invocation, chain);
34: } finally {
35: // 解决 invocation 和线程关�
36: EJBInvocation.remove();
37: // �� ThreadContextClassLoader
38: Thread.currentThread().setContextClassLoader(oldLoader);
39: }
40: }
41:
42: public static void main(String[] args) {
43:
44: }
45: }
|