Search in sources :

Example 6 with ProxettaException

use of jodd.proxetta.ProxettaException in project jodd by oblac.

the class DelegateAdviceUtil method applyAdvice.

/**
	 * Applies advice on given target class and returns proxy instance.
	 */
public static <T> T applyAdvice(Class<T> targetClass) {
    Class adviceClass = advicesMap.get(targetClass);
    if (adviceClass == null) {
        // advice not yet created
        adviceClass = PROXY_PROXETTA.builder(targetClass).define();
        advicesMap.put(targetClass, adviceClass);
    }
    try {
        Object advice = adviceClass.newInstance();
        Field field = adviceClass.getField("$___target$0");
        field.set(advice, targetClass);
        return (T) advice;
    } catch (Exception ex) {
        throw new ProxettaException(ex);
    }
}
Also used : Field(java.lang.reflect.Field) ProxettaException(jodd.proxetta.ProxettaException) ProxettaException(jodd.proxetta.ProxettaException)

Aggregations

ProxettaException (jodd.proxetta.ProxettaException)6 Field (java.lang.reflect.Field)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 EmptyClassVisitor (jodd.asm.EmptyClassVisitor)1 EmptyMethodVisitor (jodd.asm.EmptyMethodVisitor)1 MethodAdapter (jodd.asm.MethodAdapter)1 ClassReader (jodd.asm5.ClassReader)1 FieldVisitor (jodd.asm5.FieldVisitor)1 Label (jodd.asm5.Label)1 MethodVisitor (jodd.asm5.MethodVisitor)1 JtxTransactionMode (jodd.jtx.JtxTransactionMode)1 TransactionAnnotationData (jodd.jtx.meta.TransactionAnnotationData)1 AnnotationInfo (jodd.proxetta.AnnotationInfo)1 InvokeAspect (jodd.proxetta.InvokeAspect)1 InvokeInfo (jodd.proxetta.InvokeInfo)1 InvokeReplacer (jodd.proxetta.InvokeReplacer)1