static Object newInstance ( DTPPooledConnection pc , java.sql.Connection c , TransactionalResource resource ) throws SQLException { Object ret = null; ConnectionProxy proxy = new ConnectionProxy ( c, resource, pc ); Set interfaces = getAllImplementedInterfaces ( c.getClass() ); Class[] interfaceClasses = ( Class[] ) interfaces.toArray ( new Class[0] ); ret = java.lang.reflect.Proxy.newProxyInstance ( c.getClass () .getClassLoader (), interfaceClasses, proxy ); return ret; }
static Set getAllImplementedInterfaces ( Class clazz ) { Set ret = null; if ( clazz.getSuperclass() != null ) { //if superclass exists: first add the superclass interfaces!!! ret = getAllImplementedInterfaces ( clazz.getSuperclass() ); } else { //no superclass: start with empty set ret = new HashSet(); } //add the interfaces in this class Class[] interfaces = clazz.getInterfaces(); for ( int i = 0 ; i < interfaces.length ; i++ ) { ret.add ( interfaces[i] ); } return ret; }
/** * @see com.atomikos.jdbc.DTPPooledConnection#getConnection(com.atomikos.icatch.HeuristicMessage) */ public Connection getConnection ( HeuristicMessage msg ) throws SQLException { msg_ = msg; discarded_ = false; if ( connectionProxy_ == null ) { connectionProxy_ = (java.sql.Connection) ConnectionProxy .newInstance ( this, myConn_.getConnection (), resource_ ); } return connectionProxy_; }