On 9 Jan 2013, at 09:20, Michael wrote:

> Hi All,
> 
> I created an annotation named "Validate"
> 
> @Retention(RetentionPolicy.RUNTIME)
> @Target(ElementType.METHOD)
> public @interface Validate {
>     Class<? extends MethodInterceptor>[] value();
> }
> 
> And defined it before a method
> @Validate({OneInterceptor.class, TwoInterceptor.class})
>     public void doPost(HttpServletRequest req, HttpServletResponse resp) {
>         //do something
>     }
> 
> OneInterceptor implements MethodInterceptor {.....}  TwoInterceptor 
> implements MethodInterceptor{....}
> 
> So I want to know is there a possible to bind interceptors within a Module 
> like this ?  Many thanks!

One option would be to have a ValidateMethodInterceptor implementation bound in 
your module that gets the Validate annotation from the reflected method, ie. 
methodInvocation.getMethod().getAnnotation(Validate.class) - and then delegates 
to the listed method interceptors. If you want the delegated method 
interceptors injected (as opposed to clazz.newInstance) then you'll need to add 
a @Inject'd field/setter to ValidateMethodInterceptor for the injector and 
arrange for the ValidateMethodInterceptor instance to be injected with 
binder.requestInjection(...)  - then you can call injector.getInstance(clazz) 
for each interceptor at delegation time.

--
Cheers, Stuart

-- 
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