public static < T > T applyAdvice ( final Class < T > targetClass ) { Class adviceClass = cache . get ( targetClass ) ; if ( adviceClass == null ) { // advice not yet created adviceClass = PROXY_PROXETTA . proxy ( ) . setTarget ( targetClass ) . define ( ) ; cache . put ( targetClass , adviceClass ) ; } // create new advice instance and injects target instance to it try { Object advice = ClassUtil . newInstance ( adviceClass ) ; Field field = adviceClass . getField ( "$___target$0" ) ; field . set ( advice , targetClass ) ; return ( T ) advice ; } catch ( Exception ex ) { throw new ProxettaException ( ex ) ; } }
Applies advice on given target class and returns proxy instance .