[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] How to use a constructor pointcut in a pertarget aspect
|
Hi Christoph,
Your problem here is that for call() pointcuts, there is no target
object (ie- it is always null). The best way I can think of
implementing your strategy is by using an internal map to keep track
of boundTo objects.
Can anyone think of a better solution?
On Tue, Oct 13, 2009 at 6:55 AM, Christoph Kurrat
<c.kurrat@xxxxxxxxxxxxxx> wrote:
> Hi,
>
> I'm trying to log read and write accesses with aspectJ.
> To do this, I want to capture the constructor calls, read and write calls
> and close calls of, for example, RandomAccessFile objects.
> The logged data shall be saved inside the aspect. For this reason, I want to
> use pertarget to capture constructor invocations. The problem is, that the
> used pointcut doesn't seem to work; neither an aspect instance is created,
> nor the advice for the constructor is used; i get a "advice has not been
> applied" message.
>
> These are the pointcuts used to capture the constructor calls.
>
> public pointcut randomAccessFileCreation() : call(RandomAccessFile.new(..));
> public pointcut writerCreation() : (call(FileWriter.new(..)) ||
> call(PrintWriter.new(File,..)) || call(PrintWriter.new(String,..)));
>
> These pointcuts (and more, for example readerCreation() following the same
> principle) are joined with the newAspect() pointcut:
>
> public pointcut newAspect() : writerCreation() ||
> randomAccessFileCreation();
>
>
> The aspect is defined like this:
> public privileged aspect loggingAspect pertarget(newAspect()){
>
>
> The advice belonging to the newAspect() pointcut:
> after() returning(Object obj) : newAspect(){
> boundTo = obj;
> System.err.println("new Object " + boundTo);
> log.setTimeOpen(Calendar.getInstance().getTime());
> }
> }
>
> In the constructor of the aspect, i print a log message, too.
>
> None of the log messages is printed during the execution of the program.
>
> What am i doing wrong here?
>
> Thanks
>
> Christoph
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>