Created
July 10, 2015 07:22
-
-
Save Kotlin-Native/6f497bccf2ad0297a6eb 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) { | |
| if (base == null || !(property instanceof String)) { | |
| return true; | |
| } | |
| Method method = getFluentMethod(context, base, property.toString()); | |
| if (method == null) { | |
| return true; | |
| } | |
| context.setPropertyResolved(true); | |
| return false; | |
| } | |
| public void setValue(ELContext context, Object base, Object property, Object value) { | |
| if (base == null || !(property instanceof String)) { | |
| return; | |
| } | |
| Method method = getFluentMethod(context, base, property.toString()); | |
| if (method == null) { | |
| return; | |
| } | |
| try { | |
| method.invoke(base, value); | |
| } catch (IllegalAccessException e) { | |
| throw new IllegalStateException(e); | |
| } catch (InvocationTargetException e) { | |
| if (e.getTargetException() instanceof RuntimeException) { | |
| throw (RuntimeException)e.getTargetException(); | |
| } else { | |
| throw new IllegalStateException(e.getTargetException()); | |
| } | |
| } | |
| context.setPropertyResolved(true); | |
| } | |
| private Method getFluentMethod(ELContext context, Object base, String name) { | |
| ... | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment