Re: [aspectwerkz-user] 'after returning' syntax

Alexandre Vasseur <[email protected]> Tue, 19 Jul 2005 18:25:38 +0200
Newsgroups gmane.comp.java.aspectwerkz.user
Message-ID <[email protected]>
Hi

Using annotations:

    /**
     * @AfterReturning(type="i", pointcut="execution(*
test.afterxxx.TestBinding.returnInt(..))")
     */
    public void logAfterBinding(int i) {
        TestBinding.log("afterReturningInt " + i);
    }

or (no binding)

   /**
     * @AfterReturning(type="java.lang.String",
pointcut="aroundFinallyReturning || aroundFinallyReturningThrowing ||
     * aroundReturningThrowing || finallyReturning ||
finallyReturningThrowing ||
     * returningThrowing || aroundReturning || returning")
     */
    public void logAfterReturningString(final StaticJoinPoint
joinPoint) throws Throwable {
        Test.log("logAfterReturningString ");
    }


and using XML:
(adapt for after returning but you get the idea: use the advice method
signature as the error message says)

            <advice name="afterGreeting(JoinPoint jp,
java.lang.Exception ex)" type="after throwing(ex)"
bind-to="greetMethod"/>

    public void afterGreeting(JoinPoint joinPoint, java.lang.Exception ex) {
            log("afterGreetingException");
        }

note that JoinPoint is not fully qualified in the XML because it is a
known type, as all java.lang.* and java.util.* types. If ever you use
some other type, use fully qualified name (just as showned here with
java.lang.Exception).
That 's a drawback of the XML style.

Alex


On 7/19/05, Marc Candle <[email protected]> wrote:
> 
> Hi,
> 
> I'm using AspectWerkz 2.0 under Tomcat 5.5.9 but it's unclear to me how to
> use the "after returning" directive. Basically, I cannot find examples of
> how to access the returning variable from the aspect. Are there any
> available examples online?
> 
> Here is my example:
> 
> I declare a simple Class:
> 
>         package test;
> 
>         public class MyClass {
> 
>         MyClass() {};
> 
>         public String returnSomething(String tp)
>            return tp+" hello";
> 
>         }
> 
> Then in AOP.XML I add :
> 
>         <pointcut name="returntest" expression="call(* test.MyClass.
> returnSomething(..))"/>
> 
>         <advice name="returnAspect " type="after
> returning(java.lang.String)" bind-to="returntest"/>
> 
> Finally in my Aspect class, I have:
> 
>         public void returnAspect (JoinPoint joinPoint, Object returnValue)
>                  throws Throwable {
>                 //do something with returnValue
>         }
> 
> Which generates the following error:
> 
>         org.codehaus.aspectwerkz.exception.DefinitionException: could not
> find    advice method [returnAspect] in [MyAspect] (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?)
> 
> The following version works, but then I can't access the returned value.
> 
>         public void returnAspect (JoinPoint joinPoint)
>                  throws Throwable {
>                 //no access to returnValue
>         }
> 
> Any help would be appreciated,
> 
> Regards
> 
> Mark
> 
> 
> 
> 
>