String t = expr.substring(idx + 1);
String method = t.substring(0, (t.length() - 1));
FacesContext context = FacesContext.getCurrentInstance();
ELContext elContext = context.getELContext();
MethodInfo controlInfo = expression.getMethodInfo(elContext);
// ensure the method names are the same
if (!controlInfo.getName().equals(method)) {
return false;
}
// Using the target, create an expression and evaluate
// it.
ExpressionFactory factory = context.getApplication().getExpressionFactory();
ValueExpression ve = factory.createValueExpression(elContext,
"#{" + target + '}',
Object.class);
if (ve == null) {
return false;
}
Object result = ve.getValue(elContext);
if (result == null) {
return false;
}
// Get all of the methods with the matching name and try
// to find a match based on controlInfo's return and parameter
// types
Method[] methods = result.getClass().getMethods();
for (Method meth : methods) {
if (meth.getName().equals(method)
&& meth.getReturnType().equals(controlInfo.getReturnType())
&& Arrays.equals(meth.getParameterTypes(),
controlInfo.getParamTypes())) {
return true;
}
}
}
return false;