Source Code : Check Logic In AfterReturningAdvice
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Check Logic In AfterReturningAdvice
File: Main.java
import java.lang.reflect.Method;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.framework.ProxyFactory;
public class Main {
public static void main(String[] args) {
KeyGenerator target = new KeyGenerator();
ProxyFactory factory = new ProxyFactory();
factory.setTarget(target);
factory.addAdvice(new WeakKeyCheckAdvice());
KeyGenerator keyGen = (KeyGenerator) factory.getProxy();
System.out.println("Key: " + keyGen.getKey());
}
}
class KeyGenerator {
public static final long WEAK_KEY = 1L;
public static final long STRONG_KEY = 2L;
public long getKey() {
return WEAK_KEY;
// return STRONG_KEY;
}
}
class WeakKeyCheckAdvice implements AfterReturningAdvice {
public void afterReturning(Object returnValue, Method method, Object[] args, Object target)
throws Throwable {
if ((target instanceof KeyGenerator) && ("getKey".equals(method.getName()))) {
long key = (Long) returnValue;
if (key == KeyGenerator.WEAK_KEY) {
System.out.println("a weak key");
}
}
}
}
Thank with us