Skip to content

Instantly share code, notes, and snippets.

@Kotlin-Native
Created July 10, 2015 07:22
Show Gist options
  • Select an option

  • Save Kotlin-Native/6f497bccf2ad0297a6eb to your computer and use it in GitHub Desktop.

Select an option

Save Kotlin-Native/6f497bccf2ad0297a6eb to your computer and use it in GitHub Desktop.
FluentELResolver
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