Re: [aspectwerkz-user] RE: Initializing references from a "before" aspect
Alexandre Vasseur <[email protected]>
| Newsgroups | gmane.comp.java.aspectwerkz.user |
|---|---|
| Message-ID | <[email protected]> |
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 On 4/19/05, Hindin, Avi <[email protected]> wrote: > > > > Hi Jonas, > > > > Firstly thank you for your quick response; I'm trying to do this example: > > > > <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(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"); > > } > > } > > > > 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 + ">"); > > } > > } > > > > At AW compile time I got this error: > > org.codehaus.aspectwerkz.exception.DefinitionException: > could not find advice method > [aroundGreeting(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?) > > > > Can you help me with this problem? > > > > Thanks, > > Avi Hindin. > > > > > -----Original Message----- > From: Jonas Bonér [mailto:[email protected]] > Sent: Sunday, April 17, 2005 7:36 PM > To: [email protected] > Cc: Hindin, Avi; Haimov, Gilad; Sivan, Aryeh > Subject: Re: Initializing references from a "before" aspect > > > > Hi there. > > > > If I understand you correctly, you want to modify the value of a > > parameter that is passed to the method you are advising. > > > > If so I would use an around advice and make use of the custom join > > point (see > http://aspectwerkz.codehaus.org/new_features_in_2_0.html#Strongly_typed_proceed > > for details) to change the parameter value and pass the modified > > parameter value on. > > > > Does this help? > > > > /Jonas > > > > On hi there4/17/05, Hindin, Avi <[email protected]> wrote: > > > Hi guys, > > > > > > > > > > > > My aim is to write a "before" aspect that initializes a reference passed > > > to > > > the original method as null. > > > > > > > > > > > > That is, what I logically want to do in the aspect is: > > > > > > myMethod(String str) > > > > > > { > > > > > > // "before" aspect should do the following: > > > > > > If(str==null) > > > > > > str = "abc"; > > > > > > > > > > > > > > > > > > // applicative logic here .... > > > > > > } > > > > > > > > > > > > All this is well, but, of course, does not work. Why? Because AspectWerkz > > > implements "before" aspects by calling > > > > > > an automatically generated method to do the work (example below) and you > > > cannot, of course, initialize a reference > > > > > > within a method. > > > > > > > > > > > > But is there a workaround? Please notice that such a workaround cannot > > > involve attaching the aspect > > > > > > to code _callng_ the method, since that code is not available to me. > > > > > > > > > > > > Your help will be highly appreciated! > > > > > > > > > > > > Avi Hindin > > > > > > BMC Software > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > /Jonas