⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultactioninvocation.java

📁 在Struts2中的jar包xwork的源代码.版本为2.0.7
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2002-2006 by OpenSymphony * All rights reserved. */package com.opensymphony.xwork2;import com.opensymphony.xwork2.config.ConfigurationException;import com.opensymphony.xwork2.config.entities.ActionConfig;import com.opensymphony.xwork2.config.entities.InterceptorMapping;import com.opensymphony.xwork2.config.entities.ResultConfig;import com.opensymphony.xwork2.interceptor.PreResultListener;import com.opensymphony.xwork2.util.ValueStack;import com.opensymphony.xwork2.util.ValueStackFactory;import com.opensymphony.xwork2.util.profiling.UtilTimerStack;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.lang.reflect.Proxy;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.Map;/** * The Default ActionInvocation implementation * * @author Rainer Hermanns * @author tmjee *  * @version $Date: 2007-03-31 18:32:47 +0200 (Sa, 31 Mrz 2007) $ $Id: DefaultActionInvocation.java 1414 2007-03-31 16:32:47Z rainerh $ *  * @see com.opensymphony.xwork2.DefaultActionProxy */public class DefaultActionInvocation implements ActionInvocation {    	private static final long serialVersionUID = -585293628862447329L;    //static {    //    if (ObjectFactory.getContinuationPackage() != null) {    //        continuationHandler = new ContinuationHandler();    //    }    //}    private static final Log LOG = LogFactory.getLog(DefaultActionInvocation.class);    protected Object action;    protected ActionProxy proxy;    protected List preResultListeners;    protected Map extraContext;    protected ActionContext invocationContext;    protected Iterator interceptors;    protected ValueStack stack;    protected Result result;    protected String resultCode;    protected boolean executed = false;    protected boolean pushAction = true;    protected ObjectFactory objectFactory;    protected ActionEventListener actionEventListener;    protected UnknownHandler unknownHandler;    protected DefaultActionInvocation(ObjectFactory objectFactory, UnknownHandler handler, ActionProxy proxy, Map extraContext) throws Exception {        this(objectFactory, handler, proxy, extraContext, true, null);    }    protected DefaultActionInvocation(final ObjectFactory objectFactory, final UnknownHandler handler, final ActionProxy proxy, final Map extraContext, final boolean pushAction) throws Exception {        this(objectFactory, handler, proxy, extraContext, pushAction, null);    }    protected DefaultActionInvocation(final ObjectFactory objectFactory, final UnknownHandler handler, final ActionProxy proxy, final Map extraContext, final boolean pushAction, final ActionEventListener actionEventListener) throws Exception {    	UtilTimerStack.profile("create DefaultActionInvocation: ",     			new UtilTimerStack.ProfilingBlock<Object>() {					public Object doProfiling() throws Exception {						DefaultActionInvocation.this.proxy = proxy;                        DefaultActionInvocation.this.objectFactory = objectFactory;				        DefaultActionInvocation.this.extraContext = extraContext;				        DefaultActionInvocation.this.pushAction = pushAction;                        DefaultActionInvocation.this.unknownHandler = handler;                        DefaultActionInvocation.this.actionEventListener = actionEventListener;                        init();						return null;					}    			});    }        public void setActionEventListener(ActionEventListener listener) {        this.actionEventListener = listener;    }    public Object getAction() {        return action;    }    public boolean isExecuted() {        return executed;    }    public ActionContext getInvocationContext() {        return invocationContext;    }    public ActionProxy getProxy() {        return proxy;    }    /**     * If the DefaultActionInvocation has been executed before and the Result is an instance of ActionChainResult, this method     * will walk down the chain of ActionChainResults until it finds a non-chain result, which will be returned. If the     * DefaultActionInvocation's result has not been executed before, the Result instance will be created and populated with     * the result params.     *     * @return a Result instance     * @throws Exception     */    public Result getResult() throws Exception {        Result returnResult = result;        // If we've chained to other Actions, we need to find the last result        while (returnResult instanceof ActionChainResult) {            ActionProxy aProxy = ((ActionChainResult) returnResult).getProxy();            if (aProxy != null) {                Result proxyResult = aProxy.getInvocation().getResult();                if ((proxyResult != null) && (aProxy.getExecuteResult())) {                    returnResult = proxyResult;                } else {                    break;                }            } else {                break;            }        }        return returnResult;    }    public String getResultCode() {        return resultCode;    }    public void setResultCode(String resultCode) {        if (isExecuted())            throw new IllegalStateException("Result has already been executed.");        this.resultCode = resultCode;    }    public ValueStack getStack() {        return stack;    }    /**     * Register a com.opensymphony.xwork2.interceptor.PreResultListener to be notified after the Action is executed and before the     * Result is executed. The ActionInvocation implementation must guarantee that listeners will be called in the order     * in which they are registered. Listener registration and execution does not need to be thread-safe.     *     * @param listener     */    public void addPreResultListener(PreResultListener listener) {        if (preResultListeners == null) {            preResultListeners = new ArrayList(1);        }        preResultListeners.add(listener);    }    public Result createResult() throws Exception {    	if (result != null) {    		return result;    	}        ActionConfig config = proxy.getConfig();        Map results = config.getResults();        ResultConfig resultConfig = null;        synchronized (config) {            try {                resultConfig = (ResultConfig) results.get(resultCode);            } catch (NullPointerException e) {            }            if (resultConfig == null) {                // If no result is found for the given resultCode, try to get a wildcard '*' match.                resultConfig = (ResultConfig) results.get("*");            }        }        if (resultConfig != null) {            try {                Result result = objectFactory.buildResult(resultConfig, invocationContext.getContextMap());                return result;            } catch (Exception e) {                LOG.error("There was an exception while instantiating the result of type " + resultConfig.getClassName(), e);                throw new XWorkException(e, resultConfig);            }        } else if (resultCode != null && !Action.NONE.equals(resultCode) && unknownHandler != null) {            return unknownHandler.handleUnknownResult(invocationContext, proxy.getActionName(), proxy.getConfig(), resultCode);        }        return null;    }    /**     * @throws ConfigurationException If no result can be found with the returned code     */    public String invoke() throws Exception {    	String profileKey = "invoke: ";    	try {    		UtilTimerStack.push(profileKey);    		    		if (executed) {    			throw new IllegalStateException("Action has already executed");    		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -