Implement CGLIB in ABAP
What is cglib?A Byte Code Generation Library which is high level API to generate and transform Java byte code. It is used in various scenarios such as AOP, testing, data access frameworks to generate dynamic proxy objects and intercept field access.
See one example in unit test.
In line 17, a new dynamic proxy class is generated as mock.
In line 19, we tell the proxy, "if get(0) is called on this mock class, then return mocked data "hello, world".
As a result, in line 23 "result: hello, world" will be printed out.
In debugger you can find that the variable in line 17 is mocked by CGLIB:
Its byte code is generated dynamically and stored in variable byte[] b in line 217.
Let's see another example of injecting pre-exit and post-exit ( which ABAPers are very familiar with ) into a given method via dynamic proxy generated by CGLIB:
I have a class MyMEthodExitDemo which has a normal method myFun.
A new dynamic proxy class is generated in method createProxy which has a method with equal name as original class plus custom enhancement covered by class JerryEnhancement.
The pre-exit and post-exit are defined in class JerryEnhancement which implements interface MethodInterceptor defined in CGLIB library. The original method is generated in line 14, with pre-exit before it ( line 13 ) and post-exit after it ( line 15 ).
Execute result:
How can CGLIB be implemented in ABAP?
See my implementation here
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2668579/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SAP ABAP CGLIB(Code Generation Library)的模擬實現CGLib
- Implement strStr()
- Leetcode 28 Implement strStr()LeetCode
- Implement Leader Election Algorithm With GoGo
- CGLIB代理CGLib
- LeetCode | 232 Implement Queue Using StacksLeetCode
- WPF C# implement scaletransform and translatetransfrom programmaticallyC#ORM
- CGLib淺析CGLib
- CGLib 簡析CGLib
- WPF ListBox implement autoscroll via behavior extension and SelectedItem
- Cglib proxy探祕CGLib
- cglib FastClass機制CGLibAST
- CGLib 動態代理CGLib
- cglib代理的使用CGLib
- 【leetcode】28. Implement strStr() 字串匹配KMP BMLeetCode字串匹配KMP
- 動態代理-cglib分析CGLib
- [LeetCode] 232. 225 Implement Queue/Stack using Stacks/QueuesLeetCode
- WPF datagrid implement multi select via behavior selectionchanged event in MVVMMVVM
- Cglib中LoadingCache原始碼分析CGLibGC原始碼
- AOP底層原理之CGlibCGLib
- java中Cglib代理的使用JavaCGLib
- Java動態代理(JDK和cglib)JavaJDKCGLib
- JDK動態代理和CGLib代理JDKCGLib
- JDK動態代理和 CGLIB 代理JDKCGLib
- Leetcode 225. Implement Stack using Queues 用佇列實現棧LeetCode佇列
- CGLib動態代理原理及實現CGLib
- JDK proxy 和cglib 原始碼解讀JDKCGLib原始碼
- 【深度思考】聊聊CGLIB動態代理原理CGLib
- 設計模式之cglib動態代理設計模式CGLib
- Jdk代理和CGLIB代理的區別JDKCGLib
- SAP ABAP Netweaver 裡的 ABAP 會話概念會話
- 3.靜態代理&動態代理&CGlibCGLib
- 動態代理jdk和cglib的區別JDKCGLib
- escape in ABAP and JavaScriptJavaScript
- JavaScript and Ruby in ABAPJavaScript
- SAP ABAP RFC介面通用日誌工具:abap fm logger
- SAP ABAP Gateway Client 的 ABAP 實現,重用 HTTP ConnectionGatewayclientHTTP
- 如何使用 ABAP 程式消費 SAP ABAP OData 服務