Re: [aspectwerkz-user] RE: Initializing references from a "before " aspect

Alexandre Vasseur <[email protected]>
Newsgroups gmane.comp.java.aspectwerkz.user
Message-ID <[email protected]>
I just realized:
we forgot to say that it is not possible to use a custom join point
with a before advice and in general to pass new arguments to a method
using a before advice (whatever execution / call side, same with
AspectJ).

So you have to use an around advice off course.
I have added a small sample that will help you:

http://cvs.aspectwerkz.codehaus.org/viewrep/aspectwerkz/aspectwerkz4/src/jdk15/test/test/CustomProceedChangeTargetTest.java?r=1.2
see line 92 and below

and see
http://cvs.aspectwerkz.codehaus.org/viewrep/aspectwerkz/aspectwerkz4/src/jdk15/test/aop.xml?r=1.13
line 34 and below
for the aop.xml (unless you use the Java 5 @Around annotation that I
have commented in the aspect)

Alex


On 4/20/05, Haimov, Gilad <[email protected]> wrote:
> Hi Alex,
>  Thanks for your kind assistance again.
>  As Avi had stated below, we have some problems implementing a JoinPoint
> sub-interface.
> 
>  Also - I believe the task we have set out to achieve might be a bit simpler
> that
>  such sub-interfaces might not even be needed.
> 
>  I'll explain:
> 
>  We do not want to change the signature of our methods, all we want to do
>  is to initialize its first parameter. That is, for the method:
> 
>        void doAction(A a, B b)
>        {
>           .. method body ..
>        }
> 
>  We want to inject code which does this:
> 
>        void doAction(A a, B b)
>        {
>            a = new A(); // <<  code to be injected
>           .. method body ..
>        }
> 
>  We would highly appreciate it if you could tell us the exact API that can
> obtain this target /
>  direct us to relevant sample code.
> 
>  Thanks again for your assistance and for the wonderful tool you have
> developed.
> 
> Thanks again,
> Gilad Haimov
> BMC
> 
> 
> -----Original Message-----
> From: Hindin, Avi
> Sent: Tuesday, April 19, 2005 4:39 PM
> To: Haimov, Gilad; Sivan, Aryeh; Moyal, Star
> Subject: FW: [aspectwerkz-user] RE: Initializing references from a
> "before " aspect
> 
> -----Original Message-----
> From: Alexandre Vasseur [mailto:[email protected]]
> Sent: Tuesday, April 19, 2005 4:12 PM
> To: Hindin, Avi; [email protected]
> Subject: Re: [aspectwerkz-user] RE: Initializing references from a "before "
> aspect
> 
> Hi
> 
> In the given code, the MyCustomJoinPoint is a static inner interface
> of MyAspect2  so its name is not testAOP.MyCustomJoinPoint.
> 
> It is more testAOP.MyAspect2$MyCustomJoinPoint
> as printed by a Class.forName(....).getName();
> 
> Alex
> 
> On 4/19/05, Hindin, Avi <[email protected]> wrote:
> >
> >
> >
> > Hi Alex,
> >
> >
> >
> > This is the code that I'm trying:
> >
> >
> >
> > <aspectwerkz>
> >
> >
> >
> >   <system id="AspectWerkzExample">
> >
> >
> >
> >     <package name="testAOP">
> >
> >
> >
> >        <aspect class="MyAspect2">
> >
> >
> >
> >           <!--pointcut name="greetMethodPCut" expression="execution(*
> > testAOP.HelloWorld.greet(..)) && args(arg0, arg1)"/-->
> >
> >
> >
> >           <pointcut name="greetMethodPCut" expression="execution(public *
> > testAOP.HelloWorld.greet(..))"/>
> >
> >
> >
> >              <advice name="aroundGreeting(testAOP.MyCustomJoinPoint jp)"
> > type="around" bind-to="greetMethodPCut"/>
> >
> >
> >
> >        </aspect>
> >
> >
> >
> >     </package>
> >
> >
> >
> >   </system>
> >
> >
> >
> > </aspectwerkz>
> >
> >
> >
> >
> >
> > package testAOP;
> >
> >
> >
> > import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
> >
> > import org.codehaus.aspectwerkz.joinpoint.MethodRtti;
> >
> >
> >
> > public class MyAspect2 {
> >
> >
> >
> >     // we could inherit StaticJoinPoint instead
> >
> >     public static interface MyCustomJoinPoint extends JoinPoint {
> >
> >         Object proceed(String arg0, String arg1);
> >
> >     }
> >
> >
> >
> >     public Object aroundGreeting(MyCustomJoinPoint jp)
> > throws Throwable
> >
> >     {
> >
> >        // lets change the args :
> >
> >        return jp.proceed("new arg0", "new arg1");
> >
> >     }
> >
> > }
> >
> >
> >
> > package testAOP;
> >
> >
> >
> > public class HelloWorld {
> >
> >
> >
> >     public static void main(String args[]) {
> >
> >         HelloWorld world = new HelloWorld();
> >
> >         world.greet(null, null);
> >
> >     }
> >
> >
> >
> >     public void greet(String s1,String s2)
> >
> >     {
> >
> >         System.out.println(">>>>>>>>>>> <" + s1 + ">, <"+ s2 + ">");
> >
> >     }
> >
> > }
> >
> >
> >
> > Thanks,
> >
> > Avi.
> >
> >
> >
> > -----Original Message-----
> >  From: Alexandre Vasseur [mailto:[email protected]]
> >  Sent: Tuesday, April 19, 2005 3:41 PM
> >  To: Hindin, Avi
> >  Cc: [email protected]; [email protected]
> >  Subject: Re: FW: [aspectwerkz-user] RE: Initializing references from a
> > "before " aspect
> >
> >
> >
> > can you send me the code snip (custom jp, aspect and aop.xml file)
> >
> > Send it to me directly. I ll post my feedback on the list.
> >
> >
> >
> > Thanks
> >
> > Alex
> >
> >
> >
> > On 4/19/05, Hindin, Avi <[email protected]> wrote:
> >
> > >
> >
> > >
> >
> > >
> >
> >
> > > Hi Alex,
> >
> > >
> >
> > >
> >
> > >
> >
> > > I try it and I'm getting this error:
> >
> > >
> >
> > > <advice name="aroundGreeting(testAOP.MyCustomJoinPoint jp)"
> type="around"
> >
> > > bind-to="greetMethodPCut"/>
> >
> > >
> >
> > >
> >
> > >
> >
> > > org.codehaus.aspectwerkz.exception.DefinitionException:
> >
> > > could not find advice method [aroundGreeting(testAOP.MyCustomJoinPoint
> > jp)]
> >
> > > in [testAOP.MyAspect2] (are you using a compiler extension that you have
> > not
> >
> > > registered?) (are you using XML defined advice, with StaticJoinPoint
> >
> > > bindings without specifying the fullsource like signature?)
> >
> > >
> >
> > >
> >
> > >
> >
> > > Thanks,
> >
> > >
> >
> > > Avi.
> >
> > >
> >
> > >
> >
> > >
> >
> > > -----Original Message-----
> >
> > >  From: Alexandre Vasseur [mailto:[email protected]]
> >
> > >  Sent: Tuesday, April 19, 2005 11:50 AM
> >
> > >  To: [email protected]
> >
> > >  Subject: Re: [aspectwerkz-user] RE: Initializing references from a
> > "before"
> >
> > > aspect
> >
> > >
> >
> > >
> >
> > >
> >
> > > Hi
> >
> > >
> >
> > >
> >
> > >
> >
> > > I know our doc is bad on that part.
> >
> > >
> >
> > > When the advice signature is not just "(JoinPoint anyName)" or
> >
> > >
> >
> > > "(StaticJoinPoint anyName)" you have to write it entirely in the XML
> >
> > >
> >
> > > using full qualified names.
> >
> > >
> >
> > >
> >
> > >
> >
> > > <advice name="aroundGreeting(YOUR.PACKAGE.MyCustomJoinPoint jp)"
> >
> > >
> >
> > > type="around" bind-to="greetMethodPCut"/>
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > > (doc snip - to be fixed)
> >
> > >
> >
> > > #  name - [mandatory] the name of the advice is the name of the method
> >
> > >
> >
> > > in the aspect class that implements the advice, with an optional
> >
> > >
> >
> > > method signature if pointcut with signature are used. Abbreviations
> >
> > >
> >
> > > can be used in this signature, including for the JoinPoint or
> >
> > >
> >
> > > StaticJoinPointparameter. The signature must name its parameters (as
> >
> > >
> >
> > > if it was some source code) like advice3(JoinPoint jp, int i). The
> >
> > >
> >
> > > method defined this way must exist with the same signature in the
> >
> > >
> >
> > > aspect class hierarchy.
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > > Alex
> >
> > >
> >
> > >
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.