📄 moduleconfigimpl.java.svn-base
字号:
/* * $Id$ * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */package org.apache.struts.config.impl;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.struts.config.ActionConfig;import org.apache.struts.config.ActionConfigMatcher;import org.apache.struts.config.BaseConfig;import org.apache.struts.config.ControllerConfig;import org.apache.struts.config.ExceptionConfig;import org.apache.struts.config.FormBeanConfig;import org.apache.struts.config.ForwardConfig;import org.apache.struts.config.MessageResourcesConfig;import org.apache.struts.config.ModuleConfig;import org.apache.struts.config.PlugInConfig;import java.io.Serializable;import java.util.ArrayList;import java.util.HashMap;import java.util.List;/** * <p>The collection of static configuration information that describes a * Struts-based module. Multiple modules are identified by a <em>prefix</em> * at the beginning of the context relative portion of the request URI. If no * module prefix can be matched, the default configuration (with a prefix * equal to a zero-length string) is selected, which is elegantly backwards * compatible with the previous Struts behavior that only supported one * module.</p> * * @version $Rev$ $Date: 2005-12-31 03:57:16 -0500 (Sat, 31 Dec 2005) * $ * @since Struts 1.1 */public class ModuleConfigImpl extends BaseConfig implements Serializable, ModuleConfig { /** * <p>Commons Logging instance. </p> */ protected static Log log = LogFactory.getLog(ModuleConfigImpl.class); // ----------------------------------------------------- Instance Variables // Instance Variables at end to make comparing Interface and implementation easier. /** * <p>The set of action configurations for this module, if any, keyed by * the <code>path</code> property.</p> */ protected HashMap actionConfigs = null; /** * <p>The set of action configuration for this module, if any, keyed by * the <code>actionId</code> property.</p> */ protected HashMap actionConfigIds = null; /** * <p>The set of action configurations for this module, if any, listed in * the order in which they are added.</p> */ protected List actionConfigList = null; /** * <p>The set of exception handling configurations for this module, if * any, keyed by the <code>type</code> property.</p> */ protected HashMap exceptions = null; /** * <p>The set of form bean configurations for this module, if any, keyed * by the <code>name</code> property.</p> */ protected HashMap formBeans = null; /** * <p>The set of global forward configurations for this module, if any, * keyed by the <code>name</code> property.</p> */ protected HashMap forwards = null; /** * <p>The set of message resources configurations for this module, if any, * keyed by the <code>key</code> property.</p> */ protected HashMap messageResources = null; /** * <p>The set of configured plug-in Actions for this module, if any, in * the order they were declared and configured.</p> */ protected ArrayList plugIns = null; /** * <p>The controller configuration object for this module.</p> */ protected ControllerConfig controllerConfig = null; /** * <p>The prefix of the context-relative portion of the request URI, used * to select this configuration versus others supported by the controller * servlet. A configuration with a prefix of a zero-length String is the * default configuration for this web module.</p> */ protected String prefix = null; /** * <p>The default class name to be used when creating action form bean * instances.</p> */ protected String actionFormBeanClass = "org.apache.struts.action.ActionFormBean"; /** * The default class name to be used when creating action mapping * instances. */ protected String actionMappingClass = "org.apache.struts.action.ActionMapping"; /** * The default class name to be used when creating action forward * instances. */ protected String actionForwardClass = "org.apache.struts.action.ActionForward"; /** * <p>Matches action config paths against compiled wildcard patterns</p> */ protected ActionConfigMatcher matcher = null; /** * <p>Constructor for ModuleConfigImpl. Assumes default * configuration.</p> * * @since Struts 1.2.8 */ public ModuleConfigImpl() { this(""); } /** * <p>Construct an ModuleConfigImpl object according to the specified * parameter values.</p> * * @param prefix Context-relative URI prefix for this module */ public ModuleConfigImpl(String prefix) { super(); this.prefix = prefix; this.actionConfigs = new HashMap(); this.actionConfigIds = new HashMap(); this.actionConfigList = new ArrayList(); this.actionFormBeanClass = "org.apache.struts.action.ActionFormBean"; this.actionMappingClass = "org.apache.struts.action.ActionMapping"; this.actionForwardClass = "org.apache.struts.action.ActionForward"; this.configured = false; this.controllerConfig = null; this.exceptions = new HashMap(); this.formBeans = new HashMap(); this.forwards = new HashMap(); this.messageResources = new HashMap(); this.plugIns = new ArrayList(); } // --------------------------------------------------------- Public Methods /** * </p> Has this module been completely configured yet. Once this flag * has been set, any attempt to modify the configuration will return an * IllegalStateException.</p> */ public boolean getConfigured() { return (this.configured); } /** * <p>The controller configuration object for this module.</p> */ public ControllerConfig getControllerConfig() { if (this.controllerConfig == null) { this.controllerConfig = new ControllerConfig(); } return (this.controllerConfig); } /** * <p>The controller configuration object for this module.</p> * * @param cc The controller configuration object for this module. */ public void setControllerConfig(ControllerConfig cc) { throwIfConfigured(); this.controllerConfig = cc; } /** * <p>The prefix of the context-relative portion of the request URI, used * to select this configuration versus others supported by the controller * servlet. A configuration with a prefix of a zero-length String is the * default configuration for this web module.</p> */ public String getPrefix() { return (this.prefix); } /** * <p>The prefix of the context-relative portion of the request URI, used * to select this configuration versus others supported by the controller * servlet. A configuration with a prefix of a zero-length String is the * default configuration for this web module.</p> */ public void setPrefix(String prefix) { throwIfConfigured(); this.prefix = prefix; } /** * <p>The default class name to be used when creating action form bean * instances.</p> */ public String getActionFormBeanClass() { return this.actionFormBeanClass; } /** * <p>The default class name to be used when creating action form bean * instances.</p> * * @param actionFormBeanClass default class name to be used when creating * action form bean instances. */ public void setActionFormBeanClass(String actionFormBeanClass) { this.actionFormBeanClass = actionFormBeanClass; } /** * <p>The default class name to be used when creating action mapping * instances.</p> */ public String getActionMappingClass() { return this.actionMappingClass; } /** * <p> The default class name to be used when creating action mapping * instances. </p> * * @param actionMappingClass default class name to be used when creating * action mapping instances. */ public void setActionMappingClass(String actionMappingClass) { this.actionMappingClass = actionMappingClass; } /** * </p> Ad d a new <code>ActionConfig</code> instance to the set * associated with this module. </p> * * @param config The new configuration instance to be added * @throws IllegalStateException if this module configuration has been * frozen */ public void addActionConfig(ActionConfig config) { throwIfConfigured(); config.setModuleConfig(this); String path = config.getPath(); if (actionConfigs.containsKey(path)) { log.warn("Overriding ActionConfig of path " + path); } String actionId = config.getActionId(); if ((actionId != null) && !actionId.equals("")) { if (actionConfigIds.containsKey(actionId)) { if (log.isWarnEnabled()) { ActionConfig otherConfig = (ActionConfig) actionConfigIds.get(actionId); StringBuffer msg = new StringBuffer("Overriding actionId["); msg.append(actionId); msg.append("] for path["); msg.append(otherConfig.getPath()); msg.append("] with path["); msg.append(path); msg.append("]"); log.warn(msg); } } actionConfigIds.put(actionId, config); } actionConfigs.put(path, config); actionConfigList.add(config); } /** * <p> Add a new <code>ExceptionConfig</code> instance to the set * associated with this module. </p> * * @param config The new configuration instance to be added * @throws IllegalStateException if this module configuration has been * frozen */ public void addExceptionConfig(ExceptionConfig config) { throwIfConfigured(); String key = config.getType(); if (exceptions.containsKey(key)) { log.warn("Overriding ExceptionConfig of type " + key); } exceptions.put(key, config); } /** * <p> Add a new <code>FormBeanConfig</code> instance to the set * associated with this module. </p> * * @param config The new configuration instance to be added * @throws IllegalStateException if this module configuration has been * frozen */ public void addFormBeanConfig(FormBeanConfig config) { throwIfConfigured(); String key = config.getName(); if (formBeans.containsKey(key)) { log.warn("Overriding ActionForm of name " + key); } formBeans.put(key, config); } /** * <p> The default class name to be used when creating action forward * instances. </p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -