| 82 | |
| 83 | |
| 84 | @Override |
| 85 | public Object invoke(ELContext context, Object base, Object method, Class<?>[] paramTypes, Object[] params) { |
| 86 | Objects.requireNonNull(context); |
| 87 | |
| 88 | if (base instanceof ELClass && method instanceof String methodName) { |
| 89 | context.setPropertyResolved(base, method); |
| 90 | |
| 91 | Class<?> clazz = ((ELClass) base).getKlass(); |
| 92 | |
| 93 | if ("<init>".equals(methodName)) { |
| 94 | Constructor<?> match = Util.findConstructor(context, clazz, paramTypes, params); |
| 95 | |
| 96 | Object[] parameters = |
| 97 | Util.buildParameters(context, match.getParameterTypes(), match.isVarArgs(), params); |
| 98 | |
| 99 | Object result; |
| 100 | try { |
| 101 | result = match.newInstance(parameters); |
| 102 | } catch (InvocationTargetException e) { |
| 103 | Throwable cause = e.getCause(); |
| 104 | Util.handleThrowable(cause); |
| 105 | throw new ELException(cause); |
| 106 | } catch (ReflectiveOperationException e) { |
| 107 | throw new ELException(e); |
| 108 | } |
| 109 | return result; |
| 110 | |
| 111 | } else { |
| 112 | // Static method so base should be null |
| 113 | Method match = Util.findMethod(context, clazz, null, methodName, paramTypes, params); |
| 114 | |
| 115 | if (match == null) { |
| 116 | throw new MethodNotFoundException( |
| 117 | Util.message(context, "staticFieldELResolver.methodNotFound", methodName, clazz.getName())); |
| 118 | } |
| 119 | |
| 120 | Object[] parameters = |
| 121 | Util.buildParameters(context, match.getParameterTypes(), match.isVarArgs(), params); |
| 122 | |
| 123 | Object result; |
| 124 | try { |
| 125 | result = match.invoke(null, parameters); |
| 126 | } catch (IllegalArgumentException | IllegalAccessException e) { |
| 127 | throw new ELException(e); |
| 128 | } catch (InvocationTargetException e) { |
| 129 | Throwable cause = e.getCause(); |
| 130 | Util.handleThrowable(cause); |
| 131 | throw new ELException(cause); |
| 132 | } |
| 133 | return result; |
| 134 | } |
| 135 | } |
| 136 | return null; |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public Class<?> getType(ELContext context, Object base, Object property) { |