public Object getPossibleProperty( Map context, Object target, String name) throws OgnlException
{
Object result;
OgnlContext ognlContext = (OgnlContext)context;
try {
if ((result = OgnlRuntime.getMethodValue(ognlContext, target, name, true)) == OgnlRuntime.NotFound) {
result = OgnlRuntime.getFieldValue(ognlContext, target, name, true);
}
} catch (IntrospectionException ex) {
throw new OgnlException(name, ex);
} catch (OgnlException ex) {
throw ex;
} catch (Exception ex) {
throw new OgnlException(name, ex);
}
return result;
}
注释:上面的代码很简单首先OgnlRuntime.getMethodValue(ognlContext, target, name, true)获取值,如果没有找到,再去OgnlRuntime.getFieldValue(ognlContext, target, name, true)获取值。
10、重点分析一下OgnlRuntime.getMethodValue(ognlContext, target, name, true)
public static final Object getMethodValue(OgnlContext context, Object target, String propertyName, boolean checkAccessAndExistence) throws OgnlException, IllegalAccessException, NoSuchMethodException, IntrospectionException
{
Object result = null;
Method m = getGetMethod(context, (target == null) ? null : target.getClass(), propertyName);
if (checkAccessAndExistence) {
if ((m == null) || !context.getMemberAccess().isAccessible(context, target, m, propertyName)) {
result = NotFound;
}
}
if (result == null) {
if (m != null)
{
try
{
result = invokeMethod(target, m, NoArguments);
}
catch (InvocationTargetException ex)
{
throw new OgnlException(propertyName, ex.getTargetException());
}
} else {
throw new NoSuchMethodException(propertyName);
}
}
return result;
} 注释:(1)通过getGetMethod获取和name属性相对应的get方法。
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-32760-8.html
中国军队尤其海军必须始终头顶国耻心记仇恨
想在南海找回
居然在非正规渠道买产品
因为她