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
- CGLIB代理CGLib
- Leetcode Implement strStr()LeetCode
- CGLib淺析CGLib
- CGLib 簡析CGLib
- 代理模式CGLIB模式CGLib
- Leetcode 28 Implement strStr()LeetCode
- Implement Leader Election Algorithm With GoGo
- Leetcode-Implement strStr()LeetCode
- Implement strStr() leetcode javaLeetCodeJava
- CGLib 動態代理CGLib
- Cglib proxy探祕CGLib
- cglib代理的使用CGLib
- Cglib及其基本使用CGLib
- cglib FastClass機制CGLibAST
- leetcode28_Implement strStr()LeetCode
- LintCode-Implement Queue by Stacks
- LeetCode-Implement strStr()-KMPLeetCodeKMP
- WPF C# implement scaletransform and translatetransfrom programmaticallyC#ORM
- 動態代理-cglib分析CGLib
- LeetCode- Implement Trie (Prefix Tree)LeetCode
- Leetcode Implement Queue using StacksLeetCode
- how to implement speech recognition in J2EE
- java中Cglib代理的使用JavaCGLib
- AOP底層原理之CGlibCGLib
- CGlib動態代理複習CGLib
- LeetCode-Implement Stack Using QueuesLeetCode
- LeetCode-Implement Queue using StacksLeetCode
- 【LeetCode 28_字串_匹配】Implement strStr()LeetCode字串
- LintCode-Implement Iterator of Binary Search Tree
- [LeetCode] Implement strStr() 實現strStr()函式LeetCode函式
- Tasks of a Database Administrator : Implement the Database Design (13)Database
- LeetCode | 232 Implement Queue Using StacksLeetCode
- JDK動態代理和 CGLIB 代理JDKCGLib
- Java動態代理(JDK和cglib)JavaJDKCGLib
- JDK動態代理和CGLib代理JDKCGLib
- 使用cglib動態建立java類CGLibJava
- 求解spring aop cglib問題SpringCGLib