struts2对Ognl的封装--ClassResolver

本文探讨了Ognl在Struts框架中的扩展应用,特别是针对OGNLClassResolver接口的功能介绍,该接口负责从类名查找并加载对应的Class文件,支持静态属性或方法的调用。同时深入分析了Struts对ClassResolver的具体实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Ognl的扩展点:

http://java12345678.iteye.com/blog/2031790

 

OGNL ClassResolver接口 :

    用于由类名到类路径中找到Class文件,并加载生成Class对象,以支持静态属性或方法的调用

Struts对ClassResolver 的扩展:

 



 

 Struts中ClassResolver的加载:

  OgnlValueStack类(Struts对Ognl的封装类):

 

  protected void setRoot(XWorkConverter xworkConverter, CompoundRootAccessor accessor, CompoundRoot compoundRoot,
                           boolean allowStaticMethodAccess) {
        this.context = Ognl.createDefaultContext(this.root, accessor, new OgnlTypeConverterWrapper(xworkConverter), securityMemberAccess);
    }

 CompoundRootAccessor类源码:

 public Class classForName(String className, Map context) throws ClassNotFoundException {
        Object root = Ognl.getRoot(context);

        try {
            if (root instanceof CompoundRoot) {
                if (className.startsWith("vs")) {//????没明白呢
                    CompoundRoot compoundRoot = (CompoundRoot) root;

                    if ("vs".equals(className)) {
                        return compoundRoot.peek().getClass();
                    }

                    int index = Integer.parseInt(className.substring(2));

                    return compoundRoot.get(index - 1).getClass();
                }
            }
        } catch (Exception e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Got exception when tried to get class for name [#0]", e, className);
            }
        }

        return Thread.currentThread().getContextClassLoader().loadClass(className);
    }

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值