packageconfig.java

来自「在Struts2中的jar包xwork的源代码.版本为2.0.7」· Java 代码 · 共 512 行 · 第 1/2 页

JAVA
512
字号
/* * Copyright (c) 2002-2006 by OpenSymphony * All rights reserved. */package com.opensymphony.xwork2.config.entities;import com.opensymphony.xwork2.util.TextUtils;import com.opensymphony.xwork2.util.location.Located;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import java.io.Serializable;import java.util.*;/** * Configuration for Package. * <p/> * In the xml configuration file this is defined as the <code>package</code> tag. * * @author Rainer Hermanns * @version $Revision: 1445 $ */public class PackageConfig extends Located implements Comparable, Serializable {    private static final Log LOG = LogFactory.getLog(PackageConfig.class);    private Map<String, ActionConfig> actionConfigs = new LinkedHashMap<String, ActionConfig>();    private Map<String, ResultConfig> globalResultConfigs = new LinkedHashMap<String, ResultConfig>();    private Map interceptorConfigs = new LinkedHashMap();    private Map<String, ResultTypeConfig> resultTypeConfigs = new LinkedHashMap<String, ResultTypeConfig>();    private List globalExceptionMappingConfigs = new ArrayList();    private List<PackageConfig> parents = new ArrayList<PackageConfig>();    private String defaultInterceptorRef;    private String defaultActionRef;    private String defaultResultType;    private String defaultClassRef;    private String name;    private String namespace = "";    private boolean isAbstract = false;    private boolean needsRefresh;        public PackageConfig() {    }    public PackageConfig(String name) {        this.name = name;    }    public PackageConfig(String name, String namespace, boolean isAbstract) {        this(name);        this.namespace = TextUtils.noNull(namespace);        this.isAbstract = isAbstract;    }    public PackageConfig(String name, String namespace, boolean isAbstract, List parents) {        this(name, namespace, isAbstract);        if (parents != null) {            for (Iterator iterator = parents.iterator(); iterator.hasNext();) {                PackageConfig parent = (PackageConfig) iterator.next();                addParent(parent);            }        }    }    public void setAbstract(boolean isAbstract) {        this.isAbstract = isAbstract;    }    public boolean isAbstract() {        return isAbstract;    }    public Map<String, ActionConfig> getActionConfigs() {        return actionConfigs;    }    /**     * returns the Map of all the ActionConfigs available in the current package.     * ActionConfigs defined in ancestor packages will be included in this Map.     *     * @return a Map of ActionConfig Objects with the action name as the key     * @see ActionConfig     */    public Map<String, ActionConfig> getAllActionConfigs() {        Map<String, ActionConfig> retMap = new LinkedHashMap<String, ActionConfig>();        if (!parents.isEmpty()) {            for (PackageConfig parent : parents) {                retMap.putAll(parent.getAllActionConfigs());            }        }        retMap.putAll(getActionConfigs());        return retMap;    }    /**     * returns the Map of all the global ResultConfigs available in the current package.     * Global ResultConfigs defined in ancestor packages will be included in this Map.     *     * @return a Map of Result Objects with the result name as the key     * @see ResultConfig     */    public Map<String, ResultConfig> getAllGlobalResults() {        Map<String, ResultConfig> retMap = new LinkedHashMap<String, ResultConfig>();        if (!parents.isEmpty()) {            for (PackageConfig parentConfig : parents) {                retMap.putAll(parentConfig.getAllGlobalResults());            }        }        retMap.putAll(getGlobalResultConfigs());        return retMap;    }    /**     * returns the Map of all InterceptorConfigs and InterceptorStackConfigs available in the current package.     * InterceptorConfigs defined in ancestor packages will be included in this Map.     *     * @return a Map of InterceptorConfig and InterceptorStackConfig Objects with the ref-name as the key     * @see InterceptorConfig     * @see InterceptorStackConfig     */    public Map getAllInterceptorConfigs() {        Map retMap = new LinkedHashMap();        if (!parents.isEmpty()) {            for (Iterator<PackageConfig> iterator = parents.iterator(); iterator.hasNext();) {                PackageConfig parentContext = iterator.next();                retMap.putAll(parentContext.getAllInterceptorConfigs());            }        }        retMap.putAll(getInterceptorConfigs());        return retMap;    }    /**     * returns the Map of all the ResultTypeConfigs available in the current package.     * ResultTypeConfigs defined in ancestor packages will be included in this Map.     *     * @return a Map of ResultTypeConfig Objects with the result type name as the key     * @see ResultTypeConfig     */    public Map<String, ResultTypeConfig> getAllResultTypeConfigs() {        Map<String, ResultTypeConfig> retMap = new LinkedHashMap<String, ResultTypeConfig>();        if (!parents.isEmpty()) {            for (Iterator<PackageConfig> iterator = parents.iterator(); iterator.hasNext();) {                PackageConfig parentContext = iterator.next();                retMap.putAll(parentContext.getAllResultTypeConfigs());            }        }        retMap.putAll(getResultTypeConfigs());        return retMap;    }    /**     * returns the List of all the ExceptionMappingConfigs available in the current package.     * ExceptionMappingConfigs defined in ancestor packages will be included in this list.     *     * @return a List of ExceptionMappingConfigs Objects with the result type name as the key     * @see ExceptionMappingConfig     */    public List<ExceptionMappingConfig> getAllExceptionMappingConfigs() {        List<ExceptionMappingConfig> allExceptionMappings = new ArrayList<ExceptionMappingConfig>();        if (!parents.isEmpty()) {            for (Iterator<PackageConfig> iterator = parents.iterator(); iterator.hasNext();) {                PackageConfig parentContext = iterator.next();                allExceptionMappings.addAll(parentContext.getAllExceptionMappingConfigs());            }        }        allExceptionMappings.addAll(getGlobalExceptionMappingConfigs());        return allExceptionMappings;    }    public void setDefaultInterceptorRef(String name) {        defaultInterceptorRef = name;    }    public String getDefaultInterceptorRef() {        return defaultInterceptorRef;    }    public void setDefaultActionRef(String name) {        defaultActionRef = name;    }    public String getDefaultActionRef() {        return defaultActionRef;    }    public void setDefaultClassRef( String defaultClassRef ) {       this.defaultClassRef = defaultClassRef;    }        public String getDefaultClassRef() {       return defaultClassRef;    }        /**     * sets the default Result type for this package     *     * @param defaultResultType     */    public void setDefaultResultType(String defaultResultType) {        this.defaultResultType = defaultResultType;    }    /**     * Returns the default result type for this package.     */    public String getDefaultResultType() {        return defaultResultType;    }    /**     * gets the default interceptor-ref name. If this is not set on this PackageConfig, it searches the parent     * PackageConfigs in order until it finds one.     */    public String getFullDefaultInterceptorRef() {        if ((defaultInterceptorRef == null) && !parents.isEmpty()) {            for (Iterator<PackageConfig> iterator = parents.iterator(); iterator.hasNext();) {                PackageConfig parent = iterator.next();                String parentDefault = parent.getFullDefaultInterceptorRef();                if (parentDefault != null) {                    return parentDefault;                }            }        }        return defaultInterceptorRef;    }    /**     * gets the default action-ref name. If this is not set on this PackageConfig, it searches the parent     * PackageConfigs in order until it finds one.     */

⌨️ 快捷键说明

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