下面列出了怎么用javax.el.MethodNotFoundException的API类实例代码及写法,或者点击链接到github查看源代码。
public Object getValue(VariableScope variableScope) {
ELContext elContext = Context.getProcessEngineConfiguration().getExpressionManager().getElContext(variableScope);
try {
ExpressionGetInvocation invocation = new ExpressionGetInvocation(valueExpression, elContext);
Context.getProcessEngineConfiguration().getDelegateInterceptor().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 (ELException ele) {
throw new ActivitiException("Error while evaluating expression: " + expressionText, ele);
} catch (Exception e) {
throw new ActivitiException("Error while evaluating expression: " + expressionText, e);
}
}
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);
}
}
// case B: evaluate the identity against the ELResolver, again, must be
// 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());
}
}
@Test(expected=MethodNotFoundException.class)
public void testBug57855e() {
MethodExpression me = factory.createMethodExpression(context,
"${beanB.echo}", null , new Class[]{String.class});
Object r = me.invoke(context, new String[] { "aaa", "bbb" });
Assert.assertEquals("aaa, bbb", r.toString());
}
public Object getValue(Map<String, Object> variables) {
ELContext elContext = expressionManager.createElContext(variables);
try {
return valueExpression.getValue(elContext);
} catch (PropertyNotFoundException pnfe) {
throw new ActivitiFormException("Unknown property used in expression: " + expressionText, pnfe);
} catch (MethodNotFoundException mnfe) {
throw new ActivitiFormException("Unknown method used in expression: " + expressionText, mnfe);
} catch (ELException ele) {
throw new ActivitiFormException("Error while evaluating expression: " + expressionText, ele);
} catch (Exception e) {
throw new ActivitiFormException("Error while evaluating expression: " + expressionText, e);
}
}
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);
}
}
// case B: evaluate the identity against the ELResolver, again, must be
// 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());
}
}
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);
}
}
// case B: evaluate the identity against the ELResolver, again, must be
// 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());
}
}
@Override
public Object invoke(
ELContext context,
Object base,
Object method,
Class<?>[] paramTypes,
Object[] params
) {
if (method == null || RESTRICTED_METHODS.contains(method.toString())) {
throw new MethodNotFoundException(
"Cannot find method '" + method + "' in " + base.getClass()
);
}
if (isRestrictedClass(base)) {
throw new MethodNotFoundException(
"Cannot find method '" + method + "' in " + base.getClass()
);
}
Object result = super.invoke(context, base, method, paramTypes, params);
if (isRestrictedClass(result)) {
throw new MethodNotFoundException(
"Cannot find method '" + method + "' in " + base.getClass()
);
}
return result;
}
public JspMethodNotFoundException(String mark, MethodNotFoundException e) {
super(mark + " " + e.getMessage(), e.getCause());
}
@Test(expected=MethodNotFoundException.class)
public void testBug57855a() {
MethodExpression me = factory.createMethodExpression(context,
"${beanAA.echo2}", null , new Class[]{String.class});
me.invoke(context, new Object[0]);
}
@Test(expected=MethodNotFoundException.class)
public void testBug54370a() {
ReflectionUtil.getMethod(null, BASE, "testA",
new Class[] {null, String.class},
new Object[] {null, ""});
}
@Test(expected=MethodNotFoundException.class)
public void testBug54370b() {
ReflectionUtil.getMethod(null, BASE, "testB",
new Class[] {null, String.class},
new Object[] {null, ""});
}
public JspMethodNotFoundException(String mark, MethodNotFoundException e) {
super(mark + " " + e.getMessage(), e.getCause());
}
@Test(expected=MethodNotFoundException.class)
public void testBug54370a() {
ReflectionUtil.getMethod(BASE, "testA",
new Class[] {null, String.class},
new Object[] {null, ""});
}
@Test(expected=MethodNotFoundException.class)
public void testBug54370b() {
ReflectionUtil.getMethod(BASE, "testB",
new Class[] {null, String.class},
new Object[] {null, ""});
}
public JspMethodNotFoundException(String mark, MethodNotFoundException e) {
super(mark + " " + e.getMessage(), e.getCause());
}
@Test(expected=MethodNotFoundException.class)
public void testBug54370a() {
ReflectionUtil.getMethod(BASE, "testA",
new Class[] {null, String.class},
new Object[] {null, ""});
}
@Test(expected=MethodNotFoundException.class)
public void testBug54370b() {
ReflectionUtil.getMethod(BASE, "testB",
new Class[] {null, String.class},
new Object[] {null, ""});
}
/**
* Evaluates the expression relative to the provided context, and returns
* information about the actual referenced method.
*
* @param context
* The context of this evaluation
* @return an instance of <code>MethodInfo</code> containing information
* about the method the expression evaluated to.
* @throws NullPointerException
* if context is <code>null</code> or the base object is
* <code>null</code> on the last resolution.
* @throws PropertyNotFoundException
* if one of the property resolutions failed because a specified
* variable or property does not exist or is not readable.
* @throws MethodNotFoundException
* if no suitable method can be found.
* @throws ELException
* if an exception was thrown while performing property or
* variable resolution. The thrown exception must be included as
* the cause property of this exception, if available.
* @see javax.el.MethodExpression#getMethodInfo(javax.el.ELContext)
*/
@Override
public MethodInfo getMethodInfo(ELContext context)
throws PropertyNotFoundException, MethodNotFoundException,
ELException {
Node n = this.getNode();
EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
this.varMapper);
ctx.notifyBeforeEvaluation(getExpressionString());
MethodInfo result = n.getMethodInfo(ctx, this.paramTypes);
ctx.notifyAfterEvaluation(getExpressionString());
return result;
}
/**
* Evaluates the expression relative to the provided context, invokes the
* method that was found using the supplied parameters, and returns the
* result of the method invocation.
*
* @param context
* The context of this evaluation.
* @param params
* The parameters to pass to the method, or <code>null</code>
* if no parameters.
* @return the result of the method invocation (<code>null</code> if the
* method has a <code>void</code> return type).
* @throws NullPointerException
* if context is <code>null</code> or the base object is
* <code>null</code> on the last resolution.
* @throws PropertyNotFoundException
* if one of the property resolutions failed because a specified
* variable or property does not exist or is not readable.
* @throws MethodNotFoundException
* if no suitable method can be found.
* @throws ELException
* if an exception was thrown while performing property or
* variable resolution. The thrown exception must be included as
* the cause property of this exception, if available. If the
* exception thrown is an <code>InvocationTargetException</code>,
* extract its <code>cause</code> and pass it to the
* <code>ELException</code> constructor.
* @see javax.el.MethodExpression#invoke(javax.el.ELContext,
* java.lang.Object[])
*/
@Override
public Object invoke(ELContext context, Object[] params)
throws PropertyNotFoundException, MethodNotFoundException,
ELException {
EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
this.varMapper);
ctx.notifyBeforeEvaluation(getExpressionString());
Object result = this.getNode().invoke(ctx, this.paramTypes, params);
ctx.notifyAfterEvaluation(getExpressionString());
return result;
}
/**
* Evaluates the expression relative to the provided context, and returns
* information about the actual referenced method.
*
* @param context
* The context of this evaluation
* @return an instance of <code>MethodInfo</code> containing information
* about the method the expression evaluated to.
* @throws NullPointerException
* if context is <code>null</code> or the base object is
* <code>null</code> on the last resolution.
* @throws PropertyNotFoundException
* if one of the property resolutions failed because a specified
* variable or property does not exist or is not readable.
* @throws MethodNotFoundException
* if no suitable method can be found.
* @throws ELException
* if an exception was thrown while performing property or
* variable resolution. The thrown exception must be included as
* the cause property of this exception, if available.
* @see javax.el.MethodExpression#getMethodInfo(javax.el.ELContext)
*/
@Override
public MethodInfo getMethodInfo(ELContext context)
throws PropertyNotFoundException, MethodNotFoundException,
ELException {
Node n = this.getNode();
EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
this.varMapper);
return n.getMethodInfo(ctx, this.paramTypes);
}
/**
* Evaluates the expression relative to the provided context, invokes the
* method that was found using the supplied parameters, and returns the
* result of the method invocation.
*
* @param context
* The context of this evaluation.
* @param params
* The parameters to pass to the method, or <code>null</code>
* if no parameters.
* @return the result of the method invocation (<code>null</code> if the
* method has a <code>void</code> return type).
* @throws NullPointerException
* if context is <code>null</code> or the base object is
* <code>null</code> on the last resolution.
* @throws PropertyNotFoundException
* if one of the property resolutions failed because a specified
* variable or property does not exist or is not readable.
* @throws MethodNotFoundException
* if no suitable method can be found.
* @throws ELException
* if an exception was thrown while performing property or
* variable resolution. The thrown exception must be included as
* the cause property of this exception, if available. If the
* exception thrown is an <code>InvocationTargetException</code>,
* extract its <code>cause</code> and pass it to the
* <code>ELException</code> constructor.
* @see javax.el.MethodExpression#invoke(javax.el.ELContext,
* java.lang.Object[])
*/
@Override
public Object invoke(ELContext context, Object[] params)
throws PropertyNotFoundException, MethodNotFoundException,
ELException {
EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
this.varMapper);
return this.getNode().invoke(ctx, this.paramTypes, params);
}
/**
* Evaluates the expression relative to the provided context, and returns
* information about the actual referenced method.
*
* @param context
* The context of this evaluation
* @return an instance of <code>MethodInfo</code> containing information
* about the method the expression evaluated to.
* @throws NullPointerException
* if context is <code>null</code> or the base object is
* <code>null</code> on the last resolution.
* @throws PropertyNotFoundException
* if one of the property resolutions failed because a specified
* variable or property does not exist or is not readable.
* @throws MethodNotFoundException
* if no suitable method can be found.
* @throws ELException
* if an exception was thrown while performing property or
* variable resolution. The thrown exception must be included as
* the cause property of this exception, if available.
* @see javax.el.MethodExpression#getMethodInfo(javax.el.ELContext)
*/
@Override
public MethodInfo getMethodInfo(ELContext context)
throws PropertyNotFoundException, MethodNotFoundException,
ELException {
Node n = this.getNode();
EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
this.varMapper);
return n.getMethodInfo(ctx, this.paramTypes);
}
/**
* Evaluates the expression relative to the provided context, invokes the
* method that was found using the supplied parameters, and returns the
* result of the method invocation.
*
* @param context
* The context of this evaluation.
* @param params
* The parameters to pass to the method, or <code>null</code>
* if no parameters.
* @return the result of the method invocation (<code>null</code> if the
* method has a <code>void</code> return type).
* @throws NullPointerException
* if context is <code>null</code> or the base object is
* <code>null</code> on the last resolution.
* @throws PropertyNotFoundException
* if one of the property resolutions failed because a specified
* variable or property does not exist or is not readable.
* @throws MethodNotFoundException
* if no suitable method can be found.
* @throws ELException
* if an exception was thrown while performing property or
* variable resolution. The thrown exception must be included as
* the cause property of this exception, if available. If the
* exception thrown is an <code>InvocationTargetException</code>,
* extract its <code>cause</code> and pass it to the
* <code>ELException</code> constructor.
* @see javax.el.MethodExpression#invoke(javax.el.ELContext,
* java.lang.Object[])
*/
@Override
public Object invoke(ELContext context, Object[] params)
throws PropertyNotFoundException, MethodNotFoundException,
ELException {
EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
this.varMapper);
return this.getNode().invoke(ctx, this.paramTypes, params);
}