Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] set() capture oldvalue

This is a reasonable requirement. There are some potential complications 
in the implementation to support after advice, and the interface to 
provide access to the "before" value at a set join point is a little 
awkward: it really has to go on the JoinPoint interface alongside getThis, 
getTarget, and getArgs, even though it only applies to set join points. 

If we did something like that you could write:

after(Object newValue) returning : set( * *) && args(newValue)  {   // the 
pointcut would obviously be refined for a 'real' application...

  Object oldValue = 
thisJoinPoint.getOriginalFieldValueAtAFieldSetJoinPoint() ;  // would need 
a better name...
  if (!oldValue.equals(newValue) {
 firePropertyChangeEvent(oldValue,newValue,thisJoinPoint.getSignature());
   }
}

Please raise an enhancement request on bugzilla if you think something 
like this would be useful, and then I encourage others who have opinions 
(for or against) to comment there.

-- Adrian
Adrian_Colyer@xxxxxxxxxx



"Nitzan Volman" <nitzan@xxxxxxxxxxx> 
Sent by: aspectj-users-bounces@xxxxxxxxxxx
17/05/2005 15:34
Please respond to
aspectj-users@xxxxxxxxxxx


To
<aspectj-users@xxxxxxxxxxx>
cc

Subject
RE: [aspectj-users] set() capture oldvalue






Hi, 

I encountered the same problem, and I think what Tim suggested is needed 
in the language.
My use case is simple: I am trying to audit changes to an object by 
monitoring field modifications, on each field modification (set operation) 
I need to compare the previous and value of the field with the new value 
to make sure the value really changed, no point in auditing fields that 
are reset to the same value.
A typical scenario where this happens is when you submit web forms, most 
of the values are the same but the "set" is called anyway.

I can think of several solutions for this use case that would not require 
adding a feature to AspectJ... But doing this using AspectJ would be a 
great enhancement


/Nitzan Volman






-----Original Message-----
From: aspectj-users-bounces@xxxxxxxxxxx 
[mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Tim Schafer
Sent: Monday, May 16, 2005 5:39 PM
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] set() capture oldvalue


It's true in this particular application, the performance of reflection 
won't
kill the application.
But it's just something that I feel is missing from the language. I wanted 
to see what other use cases might exist. Performance could be a problem in 
some cases.


Tim Schafer
tschafer@xxxxxxxxxxx



----Original Message Follows----
From: Matthew Webster <matthew_webster@xxxxxxxxxx>
Reply-To: aspectj-users@xxxxxxxxxxx
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] set() capture oldvalue
Date: Mon, 16 May 2005 07:50:11 +0100
MIME-Version: 1.0
Received: from mail.eclipse.org ([206.191.52.53]) by mc4-f24.hotmail.com 
with Microsoft SMTPSVC(6.0.3790.211); Sun, 15 May 2005 23:50:49 -0700
Received: from node3.eclipse.org (localhost [127.0.0.1])by 
mail.eclipse.org 
(Postfix) with ESMTP id E1D40CB4D;Mon, 16 May 2005 02:52:44 -0400 (EDT)
Received: from mtagate2.uk.ibm.com (mtagate2.uk.ibm.com 
[195.212.29.135])by 
mail.eclipse.org (Postfix) with SMTP id E5C276AC0Ffor 
<aspectj-users@xxxxxxxxxxx>; Mon, 16 May 2005 02:51:44 -0400 (EDT)
Received: from 
d06nrmr1407.portsmouth.uk.ibm.com(d06nrmr1407.portsmouth.uk.ibm.com 
[9.149.38.185])by mtagate2.uk.ibm.com (8.12.10/8.12.10) with ESMTP id 
j4G6oD4G320918for <aspectj-users@xxxxxxxxxxx>; Mon, 16 May 2005 06:50:13 
GMT
Received: from d06av04.portsmouth.uk.ibm.com 
(d06av04.portsmouth.uk.ibm.com[9.149.37.216])by 
d06nrmr1407.portsmouth.uk.ibm.com (8.12.10/NCO/VER6.6) with ESMTP 
idj4G6oDhG282280for <aspectj-users@xxxxxxxxxxx>; Mon, 16 May 2005 07:50:13 

+0100
Received: from d06av04.portsmouth.uk.ibm.com (loopback [127.0.0.1])by 
d06av04.portsmouth.uk.ibm.com (8.12.11/8.13.3) with ESMTP 
idj4G6oDPY003034for <aspectj-users@xxxxxxxxxxx>; Mon, 16 May 2005 07:50:13 

+0100
Received: from d06ml067.portsmouth.uk.ibm.com 
(d06ml067.portsmouth.uk.ibm.com[9.149.38.140])by 
d06av04.portsmouth.uk.ibm.com (8.12.11/8.12.11) with ESMTP 
idj4G6oCZe003029for <aspectj-users@xxxxxxxxxxx>; Mon, 16 May 2005 07:50:12 

+0100
X-Message-Info: GQXpnklFM/ejFGBEcP5COAwEw6lHHLtKPmpYmPhOgiU=
X-Original-To: aspectj-users@xxxxxxxxxxx
Delivered-To: aspectj-users@xxxxxxxxxxx
Sensitivity:
X-Mailer: Lotus Notes Release 6.5.3 September 14, 2004
X-MIMETrack: Serialize by Router on D06ML067/06/M/IBM(Release 6.53HF247 
|January 6, 2005) at 16/05/2005 07:50:12
X-BeenThere: aspectj-users@xxxxxxxxxxx
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: aspectj-users.eclipse.org
List-Unsubscribe: 
<https://dev.eclipse.org/mailman/listinfo/aspectj-users>,<
mailto:aspectj-users-request@xxxxxxxxxxx?subject=unsubscribe>
List-Archive: <http://eclipse.org/pipermail/aspectj-users>
List-Post: <mailto:aspectj-users@xxxxxxxxxxx>
List-Help: <mailto:aspectj-users-request@xxxxxxxxxxx?subject=help>
List-Subscribe: 
<https://dev.eclipse.org/mailman/listinfo/aspectj-users>,<
mailto:aspectj-users-request@xxxxxxxxxxx?subject=subscribe>
Errors-To: aspectj-users-bounces@xxxxxxxxxxx
Return-Path: aspectj-users-bounces@xxxxxxxxxxx
X-OriginalArrivalTime: 16 May 2005 06:50:50.0047 (UTC) 
FILETIME=[98796CF0:01C559E3]





Tim,

If you have a concern about the performance of something measure it. Many 
frameworks use performance. I don't believe it's impact on overall 
application performance will be as bad as you think.

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx 
http://w3.hursley.ibm.com/~websterm/

"Tim Schafer" <tschafer@xxxxxxxxxxx>@eclipse.org on 13/05/2005 19:11:36

Please respond to aspectj-users@xxxxxxxxxxx

Sent by:    aspectj-users-bounces@xxxxxxxxxxx


To:    aspectj-users@xxxxxxxxxxx
cc:
Subject:    Re: [aspectj-users] set() capture oldvalue


That's exactly what I'm doing.
Using reflection.
I'm concerned about performance.
If I were using aspects I wouldn't use refelection in each setter to get 
the old value. The aspect compiler should be able to do this work for me. 
I believe it's a major defeciency that this isn't avaiblable. Are there 
already plans to fix this? Should I file a bug?

Tim Schafer
tschafer@xxxxxxxxxxx



----Original Message Follows----
From: Matthew Webster <matthew_webster@xxxxxxxxxx>
Reply-To: aspectj-users@xxxxxxxxxxx
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] set() capture oldvalue
Date: Fri, 13 May 2005 16:14:30 +0100
MIME-Version: 1.0
Received: from mail.eclipse.org ([206.191.52.53]) by mc7-f35.hotmail.com 
with Microsoft SMTPSVC(6.0.3790.211); Fri, 13 May 2005 08:15:02 -0700
Received: from node3.eclipse.org (localhost [127.0.0.1])by 
mail.eclipse.org

(Postfix) with ESMTP id 1DAB9E70F;Fri, 13 May 2005 11:17:14 -0400 (EDT)
Received: from mtagate4.uk.ibm.com (mtagate4.uk.ibm.com 
[195.212.29.137])by

mail.eclipse.org (Postfix) with SMTP id 6D0276ABD5for 
<aspectj-users@xxxxxxxxxxx>; Fri, 13 May 2005 11:16:05 -0400 (EDT)
Received: from 
d06nrmr1407.portsmouth.uk.ibm.com(d06nrmr1407.portsmouth.uk.ibm.com
[9.149.38.185])by mtagate4.uk.ibm.com (8.12.10/8.12.10) with ESMTP id 
j4DFEc78328870for <aspectj-users@xxxxxxxxxxx>; Fri, 13 May 2005 15:14:38 
GMT
Received: from d06av02.portsmouth.uk.ibm.com 
(d06av02.portsmouth.uk.ibm.com[9.149.37.228])by
d06nrmr1407.portsmouth.uk.ibm.com (8.12.10/NCO/VER6.6) with ESMTP 
idj4DFEbN9284252for <aspectj-users@xxxxxxxxxxx>; Fri, 13 May 2005 16:14:37
+0100
Received: from d06av02.portsmouth.uk.ibm.com (loopback [127.0.0.1])by 
d06av02.portsmouth.uk.ibm.com (8.12.11/8.13.3) with ESMTP 
idj4DFEb7M026517for <aspectj-users@xxxxxxxxxxx>; Fri, 13 May 2005 16:14:37
+0100
Received: from d06ml067.portsmouth.uk.ibm.com 
(d06ml067.portsmouth.uk.ibm.com[9.149.38.140])by
d06av02.portsmouth.uk.ibm.com (8.12.11/8.12.11) with ESMTP 
idj4DFEbFm026512for <aspectj-users@xxxxxxxxxxx>; Fri, 13 May 2005 16:14:37
+0100
X-Message-Info: GQXpnklFM/deOXuyugSvCR2mxkvbZGrT7xa62XqVDbE=
X-Original-To: aspectj-users@xxxxxxxxxxx
Delivered-To: aspectj-users@xxxxxxxxxxx
Sensitivity:
X-Mailer: Lotus Notes Release 6.5.3 September 14, 2004
X-MIMETrack: Serialize by Router on D06ML067/06/M/IBM(Release 6.53HF247
|January 6, 2005) at 13/05/2005 16:14:37
X-BeenThere: aspectj-users@xxxxxxxxxxx
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: aspectj-users.eclipse.org
List-Unsubscribe: <https://dev.eclipse.org/mailman/listinfo/aspectj-users
>,<
mailto:aspectj-users-request@xxxxxxxxxxx?subject=unsubscribe>
List-Archive: <http://eclipse.org/pipermail/aspectj-users>
List-Post: <mailto:aspectj-users@xxxxxxxxxxx>
List-Help: <mailto:aspectj-users-request@xxxxxxxxxxx?subject=help>
List-Subscribe: <https://dev.eclipse.org/mailman/listinfo/aspectj-users>,<
mailto:aspectj-users-request@xxxxxxxxxxx?subject=subscribe>
Errors-To: aspectj-users-bounces@xxxxxxxxxxx
Return-Path: aspectj-users-bounces@xxxxxxxxxxx
X-OriginalArrivalTime: 13 May 2005 15:15:03.0565 (UTC) 
FILETIME=[89BCABD0:01C557CE]





Tim,

I'm sure there was a thread on either aspectj-users or aspectj-dev but I 
can't find it. Bottom line is the existing field value is not a property 
of the join point so you must get it directly. The simple examples below 
shows you how to use reflection or direct access:

public class SomeClass {

        private int intField;

        public void setInt (int i) {
              intField = i;
        }
}

public aspect Aspect {

        pointcut fieldSet(int newValue) :
              set(* SomeClass+.*) && args(newValue)
              && withincode(* SomeClass+.set*(..))
              ;

        before (int newValue) : fieldSet (newValue) {

              Object oldValue = null;
              try {
                    Class clazz = 
thisJoinPoint.getSignature().getDeclaringType();
                    String fieldName = 
thisJoinPoint.getSignature().getName();
                    Field field = clazz.getDeclaredField(fieldName);
                    field.setAccessible(true);
                    oldValue = field.get(thisJoinPoint.getThis());
              }
              catch (Exception ex) {
                    ex.printStackTrace();
              }
              System.out.println("? beforeFieldSet() oldVaue=" + oldValue 
+ ", newValue=" + newValue);
        }
}

public privileged aspect PrivilegedAspect {

        pointcut intFieldSet(SomeClass obj, int newValue) :
              set(* intField) && target(obj) && args(newValue)
              && withincode(* SomeClass+.set*(..))
              ;

        before (SomeClass obj, int newValue) : intFieldSet (obj,newValue) 
{
              int oldValue = obj.intField;
              System.out.println("? beforeIntFieldSet() oldVaue=" + 
oldValue
+ ", newValue=" + newValue);
        }

}

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx 
http://w3.hursley.ibm.com/~websterm/

"Tim Schafer" <tschafer@xxxxxxxxxxx>@eclipse.org on 11/05/2005 21:47:44

Please respond to aspectj-users@xxxxxxxxxxx

Sent by:    aspectj-users-bounces@xxxxxxxxxxx


To:    aspectj-users@xxxxxxxxxxx
cc:
Subject:    [aspectj-users] set() capture oldvalue


I've used the following pointcut to capture all field modifications that 
occur within a setter method.

pointcut fieldSet(Object newValue) : set(* SomeClass+.*) && args(newValue) 
&& withincode(* SomeClass+.set*(..));

I can capture the new value, but I can't capture the old value without 
resorting to reflection. In theory aspectJ could provide access to the old 
value more statically. But aspectJ doesn't seem to support this. Or am I 
missing something?


Tim Schafer
tschafer@xxxxxxxxxxx


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx 
https://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx 
https://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx 
https://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx 
https://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx 
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users




Back to the top