Created
July 10, 2015 07:21
-
-
Save Kotlin-Native/171344495cc36fee6775 to your computer and use it in GitHub Desktop.
FluentELResolver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class FluentELResolver extends BeanELResolver { | |
| public boolean isReadOnly(ELContext context, Object base, Object property) { | |
| return getFluentMethod(context, base, property.toString()) != null; | |
| } | |
| public void setValue(ELContext context, Object base, Object property, Object value) { | |
| invoke(getFluentMethod(context, base, property.toString), base, value); | |
| } | |
| private Method getFluentMethod(ELContext context, Object base, String name) { | |
| name = Character.toUpperCase(name.charAt(0)) + name.substring(1); | |
| for (Method method : base.getClass().getMethods()) { | |
| if (isFluentWriteMethod(method, context, base, name)) { | |
| return method; | |
| } | |
| } | |
| return null; | |
| } | |
| private boolean isFluentWriteMethod(Method method, ELContext context, Object base, String property) { | |
| return method.getName().endsWith(property) && method.getParameterTypes().length == 1 && | |
| method.getParameterTypes()[0] == getType(context, base, property); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment