Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] how to capture a newly initialized object in a call pointcut?


Henry,

Try

    after (OntoModelChangeEventSource listener) returning(OntoModelChangeEventSource source) :
       
newEventSource(listener)
   {
       source.
addModelChangeListener(new ChangeListener (listener));
   }


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/



"Henry Canterburry" <canterburry@xxxxxxxxx>
Sent by: aspectj-users-bounces@xxxxxxxxxxx

20/09/2006 14:37

Please respond to
aspectj-users@xxxxxxxxxxx

To
aspectj-users@xxxxxxxxxxx
cc
Subject
[aspectj-users] how to capture a newly initialized object in a call        pointcut?





I am pretty new at this aspect stuff and have been reading one of the Eclipse AspectJ Books. One of the passages concerning initializer pointcuts states:

"When the method signature of a
call _expression_ specifies a constructor, this will provide the instance (if the call is being made from a nonstatic context) of the object making the constructor call. target is always unbound—this means attempts to use it to match on a type or expose the target of the call will leave you with a pointcut that does not match the constructor call."

So, is it then at all possible to write a pointcut that both captures the instance of the calling object and the instance of the object just created?

i.e

What I really want to write is this:

   
pointcut newEventSource(ModelChangeEventSource source, ModelChangeEventSource listener) :
       call(
ModelChangeEventSource+.new(..)) &&
       this(listener+) &&
       target(source+) &&
       within(*.core.model.*);
       
   after (
OntoModelChangeEventSource source, OntoModelChangeEventSource listener) returning :
       
newEventSource(source, listener)
   {
       source.
addModelChangeListener(new ChangeListener (listener));
   }


This basically says (or at least should say) if any event source instantiates any new event source, then add the first source as a listener to the newly created source.

This is for purposes of event propagation between event sources inside a domain model.

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


Back to the top