
org.bidib.wizard.api.aspect.PropertyChangeSupportAspect Maven / Gradle / Ivy
package org.bidib.wizard.api.aspect;
import java.lang.reflect.Method;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Aspect
public class PropertyChangeSupportAspect {
private static final Logger LOGGER = LoggerFactory.getLogger(PropertyChangeSupportAspect.class);
@Pointcut("execution(public * set*(..))")
private void anyPublicSetterOperation() {
}
@Before("anyPublicSetterOperation() && @annotation(org.bidib.wizard.api.annotation.PublishChange)")
public void before(JoinPoint jp) throws Exception {
LOGGER.info("Before was called.");
String prop = jp.getSignature().getName().substring(3);
Object target = jp.getTarget();
Method method = null;
try {
method = target.getClass().getMethod("get" + prop);
}
catch (NoSuchMethodException ex) {
method = target.getClass().getMethod("is" + prop);
}
Object before = method.invoke(target);
Object now = jp.getArgs()[0];
LOGGER.info(">>> Property '{}' changed from '{}' to '{}'", prop, before, now);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy