struts2对Ognl的打包-ClassResolver
struts2对Ognl的封装--ClassResolver
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); }