[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
|
- From: Andrew Eisenberg <andrew@xxxxxxxxxxxx>
- Date: Tue, 13 Oct 2009 09:14:41 -0700
- Delivered-to: aspectj-users@eclipse.org
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:reply-to:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:content-type:content-transfer-encoding; bh=vePNQ60lHHxlDnErobDi6qXf6MpVi6DklxJgkQaCRHI=; b=apM8QtFHlRaC50Kj4FaXJ5LioupEpCNW80rGAvRVi+6BwjTwDeushFUZ1sKwhc9rof CCl6yhHZ4RGiavNq/lHuR1kvUTrztrYyA+v5mveICUYkKlYEiuhGpj8c94zhaL2tIUBe 3Yyq0VaNQaYaviGd5xZtdIOpui1xOCDLkKEKE=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:reply-to:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; b=DaywYBkGqaeFPqWLAT1v1XVlOdYbiDMfSu+ZYqdwdCy16mPFybp2KxWfabWAeSl+Us xSt2H9ERO4XBzLf2+k8KgTOehKEoBKqG4IUPQE84VkaBbigOCuQfoFaFkVfPdGRpEOYN /bnOGfXeZbGHvHP5KRJtbdJVckCrCrIFkNTmU=
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
>
>