Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] String Trimming anyone???

Hi Ron!

Ron DiFrango schrieb:

All,

I am working with a database [DB2] where the fields are padded with spaces and I want to strip them on when I set the values in my DTO.  So I created the following aspect:

privileged aspect CaptureStringSets {
before(String val): set(* dto..*.*) && args(val) {
       System.out.println("Before[" + val + "]");
       val = val.trim();
       System.out.println("After[" + val + "]");
   }
}
This is not how before advice works - you can't assign a new Object here. Basically what you do is assign a new Object to a _copy_ of the reference passes to the setter method (Java's call by value semantics).

Therefore you would need around advice, using proceed you can pass a new Object - that should work.

Regards,
   Max


Back to the top