Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] How to build a Dirty Flag ?

Jan,
 
You can use before advice with reflection to achieve your goal. Here's a simple example where the field is public and is not a static member. Generalizing to handling private fields and static members is left as an exercise for the reader :-)
 
before(int newVal, Object container) : set(int ModelClass.*) && args(newVal) && this(container) {
  try {
    Class inClass = thisJoinPoint.getSignature().getDeclaringType();
    String fieldName = thisJoinPoint.getSignature().getName();
    Field field = inClass.getField(fieldName);
    int oldVal = field.getInt(container);
    //System.out.println("change "+oldVal+" to "+newVal);
    if (oldVal != newVal) {
        dirty=true;
    }
  } catch (Exception e) { e.printStackTrace(); } // handle properly
}
 
Ron Bodkin
Chief Technology Officer
New Aspects of Security
m: (415) 509-2895
 
 
------------Original Message-------------
From: "Jan Kerssenfischer" <aspectj@xxxxxxxxxxxxxxxxx>
To: <aspectj-users@xxxxxxxxxxx>
Date: Thu, Jul-31-2003 9:50 AM
Subject: [aspectj-users] How to build a Dirty Flag ?

Hello,

 

I have the following Problem:

If have some classes representing a data structure. I want to write an aspect, that adds a dirty flag to a class, that turns true, if one of the values changed. So far the adding of the Flag is not the problem. My Problem is to find out, if any of the classvariables is set with a new value. New means in that case that it is not the old value written again (what my Gui does). To get the new Value is no problem with a combination of set und args. My Problem is how to find out the previous value of the variable witch is written. Target returns the target instance and not the Variable. Are there any solutions to this problem?

 

Best regards,

Jan Kerssenfischer

 


Back to the top