Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

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