The first of the two matchers you provide in the bindInterceptor() call
matches at the class level.

In the example, Matchers.any() is being used for that and
Matchers.annotatedWith(NotOnWeekends.class) is being used for method
matching. This means only annotated methods on any class are matched. To
match any method on a class annotated with @NotOnWeekends as well as any
@NotOnWeekends annotated method on any class, you'd write:

WeekendBlocker weekendBlocker = new WeekendBlocker();
bindInterceptor(Matchers.annotatedWith(NotOnWeekends.class), Matchers.any(),
weekendBlocker);
bindInterceptor(Matchers.any(), Matchers.annotatedWith(NotOnWeekends.class),
weekendBlocker);

HTH,
Colin

On Tue, Apr 6, 2010 at 4:33 PM, Kartik Kumar <[email protected]>wrote:

> Hi,
>
> I am using Guice AOP to intercept some calls using Annotations. To use
> the Guice AOP example,
>
> public class NotOnWeekendsModule extends AbstractModule {
>  protected void configure() {
>    bindInterceptor(Matchers.any(),
> Matchers.annotatedWith(NotOnWeekends.class),
>        new WeekendBlocker());
>  }
> }
>
> My class is being instantiated by the injector.
>
> If I annotate on the class type, it does not recognized, it only gets
> recognized at method level. I guess, it is because the proxy
> frameworks (cglib i suppose), don't know how to handle class level
> annotations. Is there a way I can get my interceptor to intercept
> calls if I annotate on class type? Ideally I would like to intercept
> all public/default/protected scoped methods without having to annotate
> every individual method.
>
> Thanks,
>
> Kartik
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-guice%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to