(Object proxy, Method method, Object[] args)
| 650 | final boolean isMap = (object instanceof Map); |
| 651 | final InvocationHandler handler = new InvocationHandler() { |
| 652 | @Override |
| 653 | @SuppressWarnings("null") |
| 654 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { |
| 655 | String name = method.getName(); |
| 656 | |
| 657 | // Actual method name matches always come first |
| 658 | try { |
| 659 | return on(type, object).call(name, args).get(); |
| 660 | } |
| 661 | |
| 662 | // [#14] Emulate POJO behaviour on wrapped map objects |
| 663 | catch (ReflectException e) { |
| 664 | if (isMap) { |
| 665 | Map<String, Object> map = (Map<String, Object>) object; |
| 666 | int length = (args == null ? 0 : args.length); |
| 667 | |
| 668 | if (length == 0 && name.startsWith("get")) { |
| 669 | return map.get(property(name.substring(3))); |
| 670 | } else if (length == 0 && name.startsWith("is")) { |
| 671 | return map.get(property(name.substring(2))); |
| 672 | } else if (length == 1 && name.startsWith("set")) { |
| 673 | map.put(property(name.substring(3)), args[0]); |
| 674 | return null; |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | |
| 679 | throw e; |
| 680 | } |
| 681 | } |
| 682 | }; |
| 683 | |
| 684 | return (P) Proxy.newProxyInstance(proxyType.getClassLoader(), new Class[]{proxyType}, handler); |
no test coverage detected