Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Get field read

Hi,

i am an aspectj beginner and i have difficulties to write a pointcut and actually
i am wondering if what i try to achieve is possible with aspectj.

I would like to get every field within every one of mypackages which are marked with an annotation
at read time and if null set it a value.

Example:

package com.mycompany.beans
class MyBean  {
  @Logger mylogger;

   public void test() {
      mylogger.info("hello world");
   }

}

If mylogger is null i would like to instantiate it.

I tried with the following pointcut:

    @Before("get(KeyLogger com.mycompany.beans..*.*) && @annotation(kLogger)")
    public void setLoggerIfNull(Logger kLogger,JoinPoint thisJoinPoint) {
            ....
    }


The problem is that the joint point target's is an instance of MyBean (owner of mylogger attribute).
How could i access the field directly without knowing its name (it can be any class and i don't know
how the field will be named)?


Thanks in advance,
bengalister

Back to the top