[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] DirtinessAspect
|
Hi all,
I wrote the aspect below to keep track of modification of entities' state
(assuming all entity attributes have corresponding getter and setter method)
public aspect EntityAspect
{
private boolean Entity.dirty = false;
private Class[] argTypes = new Class[]{};
private Object[] args = new Object[] {};
void around(Entity entity, Object newValue) throws
IllegalArgumentException:
target(entity) && args(newValue) && execution(* Entity+.set*(..))
{
try
{
String m = "g" +
thisJoinPoint.getSignature().getName().substring(1);
Object value = entity.getClass().getMethod(m,
argTypes).invoke(entity, args);
boolean clean = (newValue==null)? value==null :
newValue.equals(value);
if (!clean)
{
proceed(entity, newValue);
entity.dirty = true;
}
}
catch(Exception ex)
{
throw new IllegalArgumentException(ex.getMessage());
}
}
}
Just wondering if it is possible to accomplish the same without using
reflection (without invoking the getter to get the current value).
Thanks in advance,
Ricardo.