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);
}
}
Aggregations