Skip to main content

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

That´s a fast answer. Thank you. To get this code work on private variables I only have to declare the aspect as privileged, do I. There are different types of variables to check. I think I can also use an Object and compare it with the .equals method? I try to find out tomorrow, thank you again.

 

Jan Kerssenfischer

 

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

 

 

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