struts2对Ognl的打包-MethodAccessor
struts2对Ognl的封装--MethodAccessor
Ognl 中MethodAccessor 用于调用类实例的方法或类的静态方法
Struts 加载扩展的PropertyAccessor :
Struts 中在OgnlValueStackFactory中调用OgnlRuntime.setMethodAccessor(Class class,MethodAccessor 实例)方法来加载Struts中定义的MethodAccessor。
在OgnlValueStackFactory 实例化之后,注入Containter时:
@Inject public void setContainer(Container container) throws ClassNotFoundException { //省略其它代码 names = container.getInstanceNames(MethodAccessor.class); for (String name : names) { Class cls = Class.forName(name); if (cls != null) { OgnlRuntime.setMethodAccessor(cls, container.getInstance(MethodAccessor.class, name)); } } //省略其它代码 }
那么Container中的MethodAccessor类是从哪加载进来的呢??
是由Struts-default.xml中bean定义中加载的:
<bean type="ognl.MethodAccessor" name="java.lang.Object" class="com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor" /> <bean type="ognl.MethodAccessor" name="com.opensymphony.xwork2.util.CompoundRoot" class="com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor" />
方法调用支持的表格式形式:
1 静态方法调用:@类全名@方法名(参数值1,参数值2....)
2 方法调用:对象属性名.方法名(参数值1,参数值2....)