开发者

Generating java proxy class in Eclipse

Is there a way in Eclipse to generate a proxy class (as in proxy pattern, not a remote call)? Something along the lines of this

public class FooBar{
    public int getBiz(){
        return 1234;
    } 
}

generates

public class FooBarProxy{
    protected FooBar foobar;
    public FooBarProxy(FooBar f) {...}
    public int getBiz(){
      开发者_Python百科  return foobar.getBiz()
    } 
}


Create the proxy class yourself, and add the FooBar instance variable. Select the variable, right click-->source-->generate delegate methods


Why not use java's built in dynamic proxy. It generates a proxy at runtime:

  1. implement your proxy logic by implementing java.lang.reflect.InvocationHandler
  2. create a dynamic proxy; see http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Proxy.html (example included)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜