Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] How to use "call pointcut", when using reflection

On Thu, 28 Aug 2003 08:45:50 -0700, "Jim Hugunin" <lists@xxxxxxxxxxx>
said:
> Tarun Sharma wrote:
> > The problem : If I have to use "call pointcut" as in
> > call(ConstructorPattern) and if there the constructor is invoked via
> > reflection then it doesn't seem to execute the advice. I believe the
> > reason is at the compile time weaving the "ajc compiler" does not weave
> > for clients executing via reflection.
> 
> The only way I believe you can do this in AspectJ-1.1 is to put your 
> advice on the reflective call itself and then do a dynamic test, i.e.
> 
> after() returning(Object newObject):
>      call(Object java.lang.reflect.Constructor.newInstance(*))
> {
>      if (newObject instanceof MyClass) {
>          <do something here with newObject>
>      }
> }

Hi Jim, Thanks a lot for your reply

I really appreciate and understand that this might be one way to atleast
try, but I believe you would agree that this might not be practical due
to following limitations I see.

1. To have "call construct", I understand that the caller must be
included in the weaving (at compile time)and this case it would be core
class of jdk i.e. "Constructor", I am not sure if the classloader would
allow this. Can we do weaving at class loading time.? Even in that case,
I guess the classloader issue might need to be seen.It would be good to
know if you have tried something like this. 

2. Even if it is somehow possible to do the above point (1), I would need
to check the various object_types, as you mentioned already (instanceof)
in the code snippet and then do certain things. If we do some generic
operations via reflection on the newly created object, then its not too
bad.But for specific object manuplation, every_possible_object_type check
would not be helpful or advisible.

3. The same needs to be done for Method.invoke(), as they would also be
left (if called via reflection).

> 
> > The issue is I CANNOT use "execution pointcut" as I have to get return
> > type from the "call(ConstructorPattern)"
> 
> Hmm, are you sure you need this?  Are you using around advice to change 
> the return value, or do you just need to access it?  You can use the 
> this pcd to bind the value of the new Object, like this:
> 
> after(Object newObject) returning:
>      execution(MyClass.new(..)) && this(newObject)
> {
>      <do something here with newObject>
> }

Yes, I am almost sure that with the present knowledge I need this and you
got it completely right. I am trying to use around advice on a
constructor call to change the return value, Thats the goal I want to
achieve. The problem is that I do not see that you can do this with any
other joinpoints available in aspectJ.

The code you mentioned would be helpful incase I wanted to do some
post_initialization operation on the object, but unfortunately that will
not solve my problem.

Does anyone have an idea about, at what other times weaving is possible
and or available.? and might solve this issue.?

I am begining to wonder now, is there ANY_USAGE_OF_CALL_POINTCUT in
practice, if it can be fooled due to reflective calls and the limitation
of access to client code for weaving.

Lastly, any further suggestion would be very helpful.

Thanks
Tarun

> 
> I hope this helps - Jim
> 
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
-- 
  Tarun Sharma
  t_sharma@xxxxxxxxxxxx

-- 
http://www.fastmail.fm - One of many happy users:
  http://www.fastmail.fm/docs/quotes.html


Back to the top