import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
public class LoggingInterceptor implements MethodInterceptor {
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
System.out.println("Method Before Execution: " + methodInvocation.getMethod().getName());
Object result = methodInvocation.proceed();
System.out.println("Method After Execution: " + methodInvocation.getMethod().getName());
return result;
}
}
public class MyService {
public void doSomething() {
System.out.println("Doing something...");
}
}
public class Main {
public static void main(String[] args) {
MyService myService = new MyService();
LoggingInterceptor interceptor = new LoggingInterceptor();
MyService proxy = (MyService) ProxyFactory.createProxy(myService, interceptor);
proxy.doSomething();
}
}