ActionProxy的构建过程

阅读更多
ActionProxy的构建过程:

ActionProxy proxy = config.getContainer().getInstance(ActionProxyFactory.class).createActionProxy(
                    namespace, name, method, extraContext, true, false);
首先生成DefaultActionInvocation,
然后到了这个工厂类:通过该工厂类生成proxy。同时prepare也初始化了DefaultActionInvocation。
public class StrutsActionProxyFactory extends DefaultActionProxyFactory {

    @Override
    public ActionProxy createActionProxy(ActionInvocation inv, String namespace, String actionName, String methodName, boolean executeResult, boolean cleanupContext) {
        
        StrutsActionProxy proxy = new StrutsActionProxy(inv, namespace, actionName, methodName, executeResult, cleanupContext);
        container.inject(proxy);
	//这个方法做了一些初始化工作,其中同时初始化了method.
	/**
	 初始化method的代码 
	 private void resolveMethod() {
        // if the method is set to null, use the one from the configuration
        // if the one from the configuration is also null, use "execute"
        if (StringUtils.isEmpty(this.method)) {
            this.method = config.getMethodName();
            if (StringUtils.isEmpty(this.method)) {
                this.method = ActionConfig.DEFAULT_METHOD;
            }
            methodSpecified = false;
        }
    }
      这段代码说明了如果没有在xml中配置method,那么会默认调用execute方法。
	*/ 
	proxy.prepare();
        return proxy;
    }
}
		  



ActionConfig其中封装了xml中的一条配置信息:
public class ActionConfig extends Located implements Serializable {

    public static final String DEFAULT_METHOD = "execute";
    public static final String WILDCARD = "*";

    protected List interceptors; // a list of interceptorMapping Objects eg. List
    protected Map params;
    protected Map results;
    protected List exceptionMappings;
    protected String className;
    protected String methodName;
    protected String packageName;
    protected String name;
    protected Set allowedMethods;


你可能感兴趣的:(java)