ognl_ognl用于什么_java(8)

电脑杂谈  发布时间:2017-02-16 12:32:16  来源:网络整理
 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

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 滕明耀
      滕明耀

      因为她

      • 萧绎
        萧绎

        中国军队尤其海军必须始终头顶国耻心记仇恨

    • 吴融
      吴融

      想在南海找回

    • 杨熙
      杨熙

      居然在非正规渠道买产品

    热点图片
    拼命载入中...