public static Constructor findProxyConstructor(ClassLoader proxyClassLoader, Class[] interfaces) throws NoSuchMethodException { Class proxyCl = Proxy.getProxyClass(proxyClassLoader, interfaces); return proxyCl.getConstructor( PROXY_CTOR_ARGS ); }
private static void addParentInterfaces(Set set, Class cl) { Class[] intfcs = cl.getInterfaces(); for (int i = 0, len = intfcs.length; i < len; ++i) { set.add( intfcs[i] ); addParentInterfaces( set, intfcs[i] ); } }
public static Class findPublicParent( Class cl ) { do cl = cl.getSuperclass(); while (cl != null && ! isPublic(cl) ); return cl; }
if (! isPublic(m)) return null; Class origClass = m.getDeclaringClass(); if (isPublic( origClass )) return m; while ((cl = findPublicParent(cl)) != null) Iterator ii = traverseInterfaces( origClass ); while ( ii.hasNext() ) if ( isPublic( cl ) )
public static Connection wrap( Connection inner ) { try { Constructor ctor = ReflectUtils.findProxyConstructor( AfterCloseLoggingConnectionWrapper.class.getClassLoader(), Connection.class ); return (Connection) ctor.newInstance( new AfterCloseLoggingInvocationHandler( inner ) ); } catch ( Exception e ) { if ( logger.isLoggable( MLevel.SEVERE ) ) logger.log( MLevel.SEVERE, "An unexpected Exception occured while trying to instantiate a dynamic proxy.", e ); throw new RuntimeException( e ); } }
public static Iterator traverseInterfaces( Class cl ) { Set set = new HashSet(); if (cl.isInterface()) set.add( cl ); addParentInterfaces( set, cl ); return set.iterator(); }
public static Connection wrap( Connection inner ) { try { Constructor ctor = ReflectUtils.findProxyConstructor( AfterCloseLoggingConnectionWrapper.class.getClassLoader(), Connection.class ); return (Connection) ctor.newInstance( new AfterCloseLoggingInvocationHandler( inner ) ); } catch ( Exception e ) { if ( logger.isLoggable( MLevel.SEVERE ) ) logger.log( MLevel.SEVERE, "An unexpected Exception occured while trying to instantiate a dynamic proxy.", e ); throw new RuntimeException( e ); } }