How is a $Proxy$_$$_Weld$EnterpriseProxy$ proxy subclass implemented?

空扰寡人 提交于 2020-01-23 09:28:09

问题


In a Java EE 7 application, let's say I have a session bean class "@Stateless public class MyEJB". When debugging under Glassfish 4, I can see that a proxy subclass named MyEJB$Proxy$_$$_Weld$EnterpriseProxy$ was created (in order to provide Java EE container services to the EJB).

I am trying to figure out how these proxy subclasses are implemented. Is there a standard Java EE SPI which the proxy implementation calls, for example, to demarcate a transaction? Or is this done through container-specific internal APIs only?

(My motivation for this question is so that I could implement a portable CDI extension to enable true POJOs and OO programming in a Java EE context.)


回答1:


Proxy implementations are created by the ProxyFactory class. You can have a look at the source in the Weld Github repo.

Basically proxy classes look like this:

public class Test_$$Proxy extends Test
{  
  public void doSomething(int someValue)  
  {  
    Testinstance = lookupBean();  
    instance.doSomething(someValue);  
  }  

  private Test lookupBean()  
  {  
    //get the correct instance from the BeanManager and return it  
  }  
}  

Plus a lot of extra magic. Maybe you can get some details from the CDI spec and from this article.



来源:https://stackoverflow.com/questions/22465410/how-is-a-proxy-weldenterpriseproxy-proxy-subclass-implemented

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!