Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] passing information to a pointcut

Thanks Matthew, I will probably stick to the separate concrete aspects.

Regards,
Simon


Matthew Webster wrote:



Simon,

Did you see my other posting? Using pertypewithin() allows you to have a
different logger for each class which is what your example shows. If you
want a different logger for an arbitrary set of join points I suggest
defining a separate concrete aspect.

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/

Simon Heinzle <simon.heinzle@xxxxxxxxxx>@eclipse.org on 13/04/2005 16:19:50

Please respond to aspectj-users@xxxxxxxxxxx

Sent by:    aspectj-users-bounces@xxxxxxxxxxx


To:    aspectj-users@xxxxxxxxxxx
cc:
Subject:    Re: [aspectj-users] passing information to a pointcut


Matthew,

Thanks for the reply but with your solution it's not possible to use 2
or more different loggers.

The idea is to have a generic abstract aspect together with a concrete
implementation. The concrete implementation should decide which logger
to use dependent on the pointcut taken.

(log4j has a complete hierarchie of loggers dependent on their name)

Anyway, I can live with the current solution for development code.

Regards,
Simon


Matthew Webster wrote:



Simon,

The this, target and args pointcuts are sufficient to expose all context
available at a joint point. The log object you are trying to obtain is

not

a property of the joint point but rather a field defined by a property of
the join point i.e. this. In a simplified version the Log object is
obtained through a template method:

public abstract aspect AbstractAspect2 {

   protected abstract Log getLog();

   protected abstract pointcut beforeTrace();

   before() : beforeTrace() {
       Log l = getLog();
       if (l.isEnabled()) l.log("Before.");
   }

}

public aspect Aspect2 extends AbstractAspect2 {
   private static Log testLog = new Log(true, "Test");

   protected Log getLog() {
           return testLog;
   }

   protected pointcut beforeTrace() : beforeTraceTest()
      || beforeTraceTest2();

     pointcut beforeTraceTest() :
      execution(* Test.doSome(..));

     pointcut beforeTraceTest2() :
       execution(* Test2.doSome(..));

}

However you have a secondary concern which is to use a different Log

object

of each class. For a solution to your problem see my posting wrt the new
pertypewithin() feature of AspectJ 5:
http://dev.eclipse.org/mhonarc/lists/aspectj-dev/msg01261.html.

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/

Simon Heinzle <simon.heinzle@xxxxxxxxxx>@eclipse.org on 13/04/2005

14:51:11

Please respond to aspectj-users@xxxxxxxxxxx

Sent by:    aspectj-users-bounces@xxxxxxxxxxx


To:    aspectj-users@xxxxxxxxxxx
cc:
Subject:    Re: [aspectj-users] passing information to a pointcut


Hi all,

I want to share the workaround i found for the my problem:
(note the abstract aspect will work as Logging - Handling Layer whereas
the concrete aspect will just contain Logger-Instances & pointcuts)

public abstract aspect AbstractAspect {
        private static Log logref;

        public static boolean setLog(Log l) {
                logref = l;
                return l.isEnabled();
        }

        abstract pointcut beforeTrace();

        before() : beforeTrace() {
                logref.log("Before.");
        }
}

public aspect Aspect extends AbstractAspect {
        private static Log testLog = new Log(true, "Test");
        private static Log test2Log = new Log(true, "Test2");

        pointcut beforeTrace() : beforeTraceTest()
                        || beforeTraceTest2();

        pointcut beforeTraceTest() :
                        execution(* Test.doSome(..))
                        && if (setLog(testLog));
        pointcut beforeTraceTest2() :
                         execution(* Test2.doSome(..))
                        && if (setLog(test2Log));

}


I'm not happy with this solution as it involves a method call & the
target application is Logging (which in case of debug disabled) is quite
time critical. However the JIT may optimize that away.

Perhaps some of you see another way to do such a thing?

Regards,
Simon


Simon Heinzle wrote:


Hi everybody,

is there a possibility to pass information other than args() and this()
and alike to a pointcut?? For example like

pointcut logPointcut(Object thiz, Object logger) :
  call (* *..Clazz.method(..) && this(thiz) && logger(myLogger);
                                                   \--------------/
(something like this) ---------------------------------------^

Didn't find any information on that...

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



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


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



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


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


--
 AdNovum Informatik AG
 Simon Heinzle
 Praktikant

 Roentgenstrasse 22, CH-8005 Zuerich
 mailto:simon.heinzle@xxxxxxxxxx
 phone: +41 44 272 6111, fax: +41 44 272 6312
 http://www.adnovum.ch

 AdNovum Offices: Bern, Budapest, San Mateo, Zuerich (HQ)


Back to the top