1 17 package org.apache.geronimo.connector.outbound; 18 19 import javax.resource.ResourceException ; 20 21 24 public class TCCLInterceptor implements ConnectionInterceptor{ 25 private final ConnectionInterceptor next; 26 private final ClassLoader classLoader; 27 28 public TCCLInterceptor(ConnectionInterceptor next, ClassLoader classLoader) { 29 this.next = next; 30 this.classLoader = classLoader; 31 } 32 33 34 public void getConnection(ConnectionInfo connectionInfo) throws ResourceException { 35 Thread currentThread = Thread.currentThread(); 36 ClassLoader oldClassLoader = currentThread.getContextClassLoader(); 37 try { 38 currentThread.setContextClassLoader(classLoader); 39 next.getConnection(connectionInfo); 40 } finally { 41 currentThread.setContextClassLoader(oldClassLoader); 42 } 43 } 44 45 public void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) { 46 Thread currentThread = Thread.currentThread(); 47 ClassLoader oldClassLoader = currentThread.getContextClassLoader(); 48 try { 49 currentThread.setContextClassLoader(classLoader); 50 next.returnConnection(connectionInfo, connectionReturnAction); 51 } finally { 52 currentThread.setContextClassLoader(oldClassLoader); 53 } 54 } 55 56 public void destroy() { 57 this.next.destroy(); 58 } 59 } 60 | Popular Tags |