RE: [aspectwerkz-user] Is there a way to get a pointcut name from within an around advic e?
"Krasheninnikov, Konstantin " <[email protected]>
| Newsgroups | gmane.comp.java.aspectwerkz.user |
|---|---|
| Message-ID | <B649D06566185B459613184B8B87794D0EC56A23@gsnmp17es.firmwide.corp.gs.com> |
Alex,
Thank you for the reply.
I could not find how to get to the pointcut name but I can specify it as
parameter to an advice, e.g.
<aspect name="1" class="HelloWorldHijacker">
<param name="pointcutName" value="greetMethod"/>
<pointcut name="greetMethod" expression="execution(*
testAOP.HelloWorld2.greet(..))"/>
<advice name="yellifyier" type="around"
bind-to="greetMethod"/>
</aspect>
<aspect name="2" class="HelloWorldHijacker">
<param name="pointcutName" value="fooMethod"/>
<pointcut name="fooMethod" expression="execution(*
testAOP.HelloWorld2.foo(..))"/>
<advice name="yellifyier" type="around" bind-to="fooMethod"/>
</aspect>
Btw, just wanted to let you know that the following does not work for
"fooMethod" (no match)
<aspect class="HelloWorldHijacker">
<pointcut name="greetMethod" expression="execution(*
testAOP.HelloWorld2.greet(..))"/>
<advice name="yellifyier" type="around" bind-to="greetMethod"/>
<pointcut name="fooMethod" expression="execution(*
testAOP.HelloWorld2.foo(..))"/>
<advice name="yellifyier" type="around" bind-to="fooMethod"/>
</aspect>
(See the program output below) Is it a bug or a feature?
-krosh-
----------------------
AspectWerkz - INFO - Pre-processor
org.codehaus.aspectwerkz.transform.AspectWerkzPreProcessor loaded and
initialized
sun.misc.Launcher$AppClassLoader@67ac19@6794265:testAOP.HelloWorld2[main]
******************************************************************
* ClassLoader = sun.misc.Launcher$ExtClassLoader@53ba3d@5487165
* SystemID = virtual_5487165, 1 aspects.
******************************************************************
******************************************************************
* ClassLoader = sun.misc.Launcher$AppClassLoader@67ac19@6794265
* SystemID = AspectWerkzExample, 2 aspects.
* SystemID = virtual_6794265, 1 aspects.
* file:/home/krashk/aspectwerkz/projects/test01/aop.xml
******************************************************************
[TRACE - earlymatch: greetMethod @
AspectWerkzExample/testAOP.HelloWorldHijacker/yellifyier
[ for testAOP.HelloWorld2
[ within testAOP.HelloWorld2
[ type execution
[TRACE - earlymatch: greetMethod @
AspectWerkzExample/testAOP.HelloWorldHijacker/yellifyier
[ for testAOP.HelloWorld2
[ within testAOP.HelloWorld2
[ type within
[TRACE - earlymatch: greetMethod @
AspectWerkzExample/testAOP.HelloWorldHijacker/yellifyier
[ for testAOP.HelloWorld2
[ within testAOP.HelloWorld2
[ type within
[TRACE - earlymatch: greetMethod @
AspectWerkzExample/testAOP.HelloWorldHijacker/yellifyier
[ for testAOP.HelloWorld2
[ within testAOP.HelloWorld2
[ type within
[TRACE - match: greetMethod @
AspectWerkzExample/testAOP.HelloWorldHijacker/yellifyier
[ for testAOP.HelloWorld2.greet()Ljava/lang/String;
[ within testAOP.HelloWorld2.greet()Ljava/lang/String;
[ type execution
sun.misc.Launcher$AppClassLoader@67ac19@6794265:testAOP.HelloWorldHijacker[m
ain]
HelloWorldHijacker is constructed!
RTTI name: greet Signature: greet
Method name: greet
Return type: java.lang.String
--> testAOP.HelloWorld2::greet
<-- testAOP.HelloWorld2::greet
<yell>Hello World!</yell>
Foo
-----Original Message-----
From: Alexandre Vasseur [mailto:[email protected]]
Sent: Friday, April 08, 2005 9:41 AM
To: [email protected]
Subject: Re: [aspectwerkz-user] Is there a way to get a pointcut name from
within an around advic e?
Hi
You may have an aspect constructor that accepts
org.codehaus.aspectwerkz.AspectContext as single parameter.
From that instance you can access the AspectDefinition that should contain
what you need.
Another option would be to use Annotation defined aspect and access the
annotation using the AspectWerkz Annotations.* API (works on Java
1.4 as well).
Last, another option would be to use
SystemDefinitionContainer.getDefinition(uuid, ClassLoader) that should
contain the AspectDefinitions of the deployed aspects.
Alex
On Apr 8, 2005 3:31 PM, Krasheninnikov, Konstantin
<[email protected]> wrote:
>
>
> Hello,
>
> Given
>
> ...
> <aspect class="HelloWorldHijacker">
> <pointcut name="greetMethod" expression="execution(*
> testAOP.HelloWorld2.greet(..))"/>
> <advice name="yellifyier" type="around"
bind-to="greetMethod"/>
> </aspect>
>
> ...and
>
> public class HelloWorldHijacker {
> public Object yellifyier( JoinPoint joinPoint ) {
> String ret = null;
> try {
>
> // How to get to the pointcut name (which is
> "greetMethod") here ??
>
> Object greeting = joinPoint.proceed();
> ret = "<yell>" + greeting + "</yell>";
> }
> catch( Throwable e ) {
> e.printStackTrace();
> }
> return ret;
> }
> }
>
> Q: Is there a way to get the pointcut name from within the around advice?
>
> Thanks in advance,
>
> -krosh-
>