Hi Sasha,
You can access all annotations on the method and/or the defining class
using the MethodInvocation parameter of MethodInterceptor.invoke().
Something like this:
public class MyInterceptor implements MethodInterceptor {
public Object invoke(MethodInvocation methodInvocation) throws
Throwable {
Method method = methodInvocation.getMethod();
MyAnnotation annotation = method.getAnnotation(Transactional.class);
....
}
}
For a full example check out guice-persist's transactional interceptor:
https://code.google.com/p/google-guice/source/browse/extensions/persist/src/com/google/inject/persist/jpa/JpaLocalTxnInterceptor.java
Line 56 is where the annotation is extracted.
HTH
--
L
On Fri, Sep 20, 2013 at 3:06 AM, Sasha Bermeister <[email protected]>wrote:
> Hi all,
>
> I've been following the tutorial on AOP at
> https://code.google.com/p/google-guice/wiki/AOP. In the tutorial, it
> shows how to use an annotation with no arguments:
>
> public class RealBillingService implements BillingService {
>
> @NotOnWeekends
> public Receipt chargeOrder(PizzaOrder order, CreditCard creditCard) {
>
> ...
> }
> }
>
>
> For my application, I need this annotation to take arguments, e.g.:
>
> @NotOnWeekends("Foo")
>
> And these arguments need to be accessible from within
> the MethodInterceptor itself (since I need to perform something different
> based on what the arguments might be).
>
> I've looked around for guides and tutorials, but nothing seems to cover
> this particular case. Any ideas?
>
> Thanks,
>
> Sasha
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/google-guice.
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.