use of javax.el.MethodNotFoundException in project tomcat70 by apache.
the class AstIdentifier method getMethodExpression.
private final MethodExpression getMethodExpression(EvaluationContext ctx) throws ELException {
Object obj = null;
// case A: ValueExpression exists, getValue which must
// be a MethodExpression
VariableMapper varMapper = ctx.getVariableMapper();
ValueExpression ve = null;
if (varMapper != null) {
ve = varMapper.resolveVariable(this.image);
if (ve != null) {
obj = ve.getValue(ctx);
}
}
// a MethodExpression to be able to invoke
if (ve == null) {
ctx.setPropertyResolved(false);
obj = ctx.getELResolver().getValue(ctx, null, this.image);
}
// finally provide helpful hints
if (obj instanceof MethodExpression) {
return (MethodExpression) obj;
} else if (obj == null) {
throw new MethodNotFoundException("Identity '" + this.image + "' was null and was unable to invoke");
} else {
throw new ELException("Identity '" + this.image + "' does not reference a MethodExpression instance, returned type: " + obj.getClass().getName());
}
}
use of javax.el.MethodNotFoundException in project tomcat70 by apache.
the class ReflectionUtil method getMethod.
/**
* Returns a method based on the criteria.
* @param base the object that owns the method
* @param property the name of the method
* @param paramTypes the parameter types to use
* @param paramValues the parameter values
* @return the method specified
* @throws MethodNotFoundException
*/
/*
* This class duplicates code in javax.el.Util. When making changes keep
* the code in sync.
*/
@SuppressWarnings("null")
public static Method getMethod(Object base, Object property, Class<?>[] paramTypes, Object[] paramValues) throws MethodNotFoundException {
if (base == null || property == null) {
throw new MethodNotFoundException(MessageFactory.get("error.method.notfound", base, property, paramString(paramTypes)));
}
String methodName = (property instanceof String) ? (String) property : property.toString();
int paramCount;
if (paramTypes == null) {
paramCount = 0;
} else {
paramCount = paramTypes.length;
}
Method[] methods = base.getClass().getMethods();
Map<Method, MatchResult> candidates = new HashMap<Method, MatchResult>();
for (Method m : methods) {
if (!m.getName().equals(methodName)) {
// Method name doesn't match
continue;
}
Class<?>[] mParamTypes = m.getParameterTypes();
int mParamCount;
if (mParamTypes == null) {
mParamCount = 0;
} else {
mParamCount = mParamTypes.length;
}
// Check the number of parameters
if (!(paramCount == mParamCount || (m.isVarArgs() && paramCount >= mParamCount))) {
// Method has wrong number of parameters
continue;
}
// Check the parameters match
int exactMatch = 0;
int assignableMatch = 0;
int coercibleMatch = 0;
boolean noMatch = false;
for (int i = 0; i < mParamCount; i++) {
// Can't be null
if (mParamTypes[i].equals(paramTypes[i])) {
exactMatch++;
} else if (i == (mParamCount - 1) && m.isVarArgs()) {
Class<?> varType = mParamTypes[i].getComponentType();
for (int j = i; j < paramCount; j++) {
if (isAssignableFrom(paramTypes[j], varType)) {
assignableMatch++;
} else {
if (paramValues == null || j >= paramValues.length) {
noMatch = true;
break;
} else {
if (isCoercibleFrom(paramValues[j], varType)) {
coercibleMatch++;
} else {
noMatch = true;
break;
}
}
}
// Don't treat a varArgs match as an exact match, it can
// lead to a varArgs method matching when the result
// should be ambiguous
}
} else if (isAssignableFrom(paramTypes[i], mParamTypes[i])) {
assignableMatch++;
} else {
if (paramValues == null || i >= paramValues.length) {
noMatch = true;
break;
} else {
if (isCoercibleFrom(paramValues[i], mParamTypes[i])) {
coercibleMatch++;
} else {
noMatch = true;
break;
}
}
}
}
if (noMatch) {
continue;
}
// return it
if (exactMatch == paramCount) {
return getMethod(base.getClass(), m);
}
candidates.put(m, new MatchResult(exactMatch, assignableMatch, coercibleMatch, m.isBridge()));
}
// Look for the method that has the highest number of parameters where
// the type matches exactly
MatchResult bestMatch = new MatchResult(0, 0, 0, false);
Method match = null;
boolean multiple = false;
for (Map.Entry<Method, MatchResult> entry : candidates.entrySet()) {
int cmp = entry.getValue().compareTo(bestMatch);
if (cmp > 0 || match == null) {
bestMatch = entry.getValue();
match = entry.getKey();
multiple = false;
} else if (cmp == 0) {
multiple = true;
}
}
if (multiple) {
if (bestMatch.getExact() == paramCount - 1) {
// Only one parameter is not an exact match - try using the
// super class
match = resolveAmbiguousMethod(candidates.keySet(), paramTypes);
} else {
match = null;
}
if (match == null) {
// the match is ambiguous so throw an exception
throw new MethodNotFoundException(MessageFactory.get("error.method.ambiguous", base, property, paramString(paramTypes)));
}
}
// Handle case where no match at all was found
if (match == null) {
throw new MethodNotFoundException(MessageFactory.get("error.method.notfound", base, property, paramString(paramTypes)));
}
return getMethod(base.getClass(), match);
}
use of javax.el.MethodNotFoundException in project Activiti by Activiti.
the class JuelExpression method getValueFromContext.
private Object getValueFromContext(ELContext elContext, DelegateInterceptor delegateInterceptor) {
try {
ExpressionGetInvocation invocation = new ExpressionGetInvocation(valueExpression, elContext);
delegateInterceptor.handleInvocation(invocation);
return invocation.getInvocationResult();
} catch (PropertyNotFoundException pnfe) {
throw new ActivitiException("Unknown property used in expression: " + expressionText, pnfe);
} catch (MethodNotFoundException mnfe) {
throw new ActivitiException("Unknown method used in expression: " + expressionText, mnfe);
} catch (Exception ele) {
throw new ActivitiException("Error while evaluating expression: " + expressionText, ele);
}
}
Aggregations