frjaeger220 / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Enhance intercepting of methods to allow modification of parameters before methodInvocation.proceed() will get called #451

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Current Guice 2.0 implementation is fully AOP compliant, but there is 
significant leak in AOP 
MethodInterceptor interface I guess. 

If you want to pass to super method different parameters than the ones method 
has been 
originally called with, there is no chance to do that with AOP API. 

Therefore I would suggest to add conditional interface which will essentially 
encapsulate full CGI 
Interceptor interface, if possible. Please see suggested modifications as 
attached.

Not sure if that is most optimal way to do it, but hopefully will give some 
inspiration to add this 
funtionality to framework...

Thank you

Original issue reported on code.google.com by chlupa...@gmail.com on 27 Nov 2009 at 9:22

Attachments:

GoogleCodeExporter commented 9 years ago
Guice AOP supports changing the method parameters without modification. The 
array returned by methodInvocation.getArguments() is fully mutable:

public class Scratch {
  public static void main(String[] args) throws InterruptedException, IOException {
    Injector injector = Guice.createInjector(new AbstractModule() {
      protected void configure() {
        bindInterceptor(Matchers.any(), Matchers.any(), new MethodInterceptor() {
          public Object invoke(MethodInvocation methodInvocation) throws Throwable {
            methodInvocation.getArguments()[0] = "bar";
            return methodInvocation.proceed();
          }
        });
      }
    });

    injector.getInstance(Scratch.class).print("foo");
  }

  public void print(String p) {
    System.out.println(p);
  }
}

Original comment by limpbizkit on 27 Nov 2009 at 11:46