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

📄 actionconfig.java.svn-base

📁 MVC开源框架
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
        // Inherit forward configs        ForwardConfig[] baseForwards = baseConfig.findForwardConfigs();        for (int i = 0; i < baseForwards.length; i++) {            ForwardConfig baseForward = baseForwards[i];            // Do we have this forward?            ForwardConfig copy = this.findForwardConfig(baseForward.getName());            if (copy == null) {                // We don't have this, so let's copy it                copy =                    (ForwardConfig) RequestUtils.applicationInstance(baseForward.getClass()                                                                                .getName());                BeanUtils.copyProperties(copy, baseForward);                this.addForwardConfig(copy);                copy.setProperties(baseForward.copyProperties());            } else {                // process any extension for this forward                copy.processExtends(getModuleConfig(), this);            }        }    }    // --------------------------------------------------------- Public Methods    /**     * <p> Add a new <code>ExceptionConfig</code> instance to the set     * associated with this action. </p>     *     * @param config The new configuration instance to be added     * @throws IllegalStateException if this module configuration has been     *                               frozen     */    public void addExceptionConfig(ExceptionConfig config) {        if (configured) {            throw new IllegalStateException("Configuration is frozen");        }        exceptions.put(config.getType(), config);    }    /**     * <p> Add a new <code>ForwardConfig</code> instance to the set of global     * forwards associated with this action. </p>     *     * @param config The new configuration instance to be added     * @throws IllegalStateException if this module configuration has been     *                               frozen     */    public void addForwardConfig(ForwardConfig config) {        if (configured) {            throw new IllegalStateException("Configuration is frozen");        }        forwards.put(config.getName(), config);    }    /**     * <p> Return the exception configuration for the specified type, if any;     * otherwise return <code>null</code>. </p>     *     * @param type Exception class name to find a configuration for     */    public ExceptionConfig findExceptionConfig(String type) {        return ((ExceptionConfig) exceptions.get(type));    }    /**     * <p> Return the exception configurations for this action.  If there are     * none, a zero-length array is returned. </p>     */    public ExceptionConfig[] findExceptionConfigs() {        ExceptionConfig[] results = new ExceptionConfig[exceptions.size()];        return ((ExceptionConfig[]) exceptions.values().toArray(results));    }    /**     * <p>Find and return the <code>ExceptionConfig</code> instance defining     * how <code>Exceptions</code> of the specified type should be handled.     * This is performed by checking local and then global configurations for     * the specified exception's class, and then looking up the superclass     * chain (again checking local and then global configurations). If no     * handler configuration can be found, return <code>null</code>.</p>     *     * <p>Introduced in <code>ActionMapping</code> in Struts 1.1, but pushed     * up to <code>ActionConfig</code> in Struts 1.2.0.</p>     *     * @param type Exception class for which to find a handler     * @since Struts 1.2.0     */    public ExceptionConfig findException(Class type) {        // Check through the entire superclass hierarchy as needed        ExceptionConfig config;        while (true) {            // Check for a locally defined handler            String name = type.getName();            log.debug("findException: look locally for " + name);            config = findExceptionConfig(name);            if (config != null) {                return (config);            }            // Check for a globally defined handler            log.debug("findException: look globally for " + name);            config = getModuleConfig().findExceptionConfig(name);            if (config != null) {                return (config);            }            // Loop again for our superclass (if any)            type = type.getSuperclass();            if (type == null) {                break;            }        }        return (null); // No handler has been configured    }    /**     * <p> Return the forward configuration for the specified key, if any;     * otherwise return <code>null</code>. </p>     *     * @param name Name of the forward configuration to return     */    public ForwardConfig findForwardConfig(String name) {        return ((ForwardConfig) forwards.get(name));    }    /**     * <p> Return all forward configurations for this module.  If there are     * none, a zero-length array is returned. </p>     */    public ForwardConfig[] findForwardConfigs() {        ForwardConfig[] results = new ForwardConfig[forwards.size()];        return ((ForwardConfig[]) forwards.values().toArray(results));    }    /**     * <p> Freeze the configuration of this action. </p>     */    public void freeze() {        super.freeze();        ExceptionConfig[] econfigs = findExceptionConfigs();        for (int i = 0; i < econfigs.length; i++) {            econfigs[i].freeze();        }        ForwardConfig[] fconfigs = findForwardConfigs();        for (int i = 0; i < fconfigs.length; i++) {            fconfigs[i].freeze();        }    }    /**     * <p>Inherit values that have not been overridden from the provided     * config object.  Subclasses overriding this method should verify that     * the given parameter is of a class that contains a property it is trying     * to inherit:</p>     *     * <pre>     * if (config instanceof MyCustomConfig) {     *     MyCustomConfig myConfig =     *         (MyCustomConfig) config;     *     *     if (getMyCustomProp() == null) {     *         setMyCustomProp(myConfig.getMyCustomProp());     *     }     * }     * </pre>     *     * <p>If the given <code>config</code> is extending another object, those     * extensions should be resolved before it's used as a parameter to this     * method.</p>     *     * @param config The object that this instance will be inheriting its     *               values from.     * @see #processExtends(ModuleConfig)     */    public void inheritFrom(ActionConfig config)        throws ClassNotFoundException, IllegalAccessException,            InstantiationException, InvocationTargetException {        if (configured) {            throw new IllegalStateException("Configuration is frozen");        }        // Inherit values that have not been overridden        if (getAttribute() == null) {            setAttribute(config.getAttribute());        }        if (!cancellableSet) {            setCancellable(config.getCancellable());        }        if (getCatalog() == null) {            setCatalog(config.getCatalog());        }        if (getCommand() == null) {            setCommand(config.getCommand());        }        if (getForward() == null) {            setForward(config.getForward());        }        if (getInclude() == null) {            setInclude(config.getInclude());        }        if (getInput() == null) {            setInput(config.getInput());        }        if (getMultipartClass() == null) {            setMultipartClass(config.getMultipartClass());        }        if (getName() == null) {            setName(config.getName());        }        if (getParameter() == null) {            setParameter(config.getParameter());        }        if (getPath() == null) {            setPath(config.getPath());        }        if (getPrefix() == null) {            setPrefix(config.getPrefix());        }        if (getRoles() == null) {            setRoles(config.getRoles());        }        if (getScope().equals("session")) {            setScope(config.getScope());        }        if (getSuffix() == null) {            setSuffix(config.getSuffix());        }        if (getType() == null) {            setType(config.getType());        }        if (!getUnknown()) {            setUnknown(config.getUnknown());        }        if (!validateSet) {            setValidate(config.getValidate());        }        inheritExceptionHandlers(config);        inheritForwards(config);        inheritProperties(config);    }    /**     * <p>Inherit configuration information from the ActionConfig that this     * instance is extending.  This method verifies that any action config     * object that it inherits from has also had its processExtends() method     * called.</p>     *     * @param moduleConfig The {@link ModuleConfig} that this bean is from.     * @see #inheritFrom(ActionConfig)     */    public void processExtends(ModuleConfig moduleConfig)        throws ClassNotFoundException, IllegalAccessException,            InstantiationException, InvocationTargetException {        if (configured) {            throw new IllegalStateException("Configuration is frozen");        }        String ancestorPath = getExtends();        if ((!extensionProcessed) && (ancestorPath != null)) {            ActionConfig baseConfig =                moduleConfig.findActionConfig(ancestorPath);            if (baseConfig == null) {                throw new NullPointerException("Unable to find "                    + "action for '" + ancestorPath + "' to extend.");            }            // Check against circular inheritance and make sure the base            //  config's own extends has been processed already            if (checkCircularInheritance(moduleConfig)) {                throw new IllegalArgumentException(                    "Circular inheritance detected for action " + getPath());            }            // Make sure the ancestor's own extension has been processed.            if (!baseConfig.isExtensionProcessed()) {                baseConfig.processExtends(moduleConfig);            }            // Copy values from the base config            inheritFrom(baseConfig);        }        extensionProcessed = true;    }    /**     * <p> Remove the specified exception configuration instance. </p>     *     * @param config ExceptionConfig instance to be removed     * @throws IllegalStateException if this module configuration has been     *                               frozen     */    public void removeExceptionConfig(ExceptionConfig config) {        if (configured) {            throw new IllegalStateException("Configuration is frozen");        }        exceptions.remove(config.getType());    }    /**     * <p> Remove the specified forward configuration instance. </p>     *     * @param config ForwardConfig instance to be removed     * @throws IllegalStateException if this module configuration has been     *                               frozen     */    public void removeForwardConfig(ForwardConfig config) {        if (configured) {            throw new IllegalStateException("Configuration is frozen");        }        forwards.remove(config.getName());    }    /**     * <p> Return a String representation of this object. </p>     */    public String toString() {        StringBuffer sb = new StringBuffer("ActionConfig[");        sb.append("cancellable=");        sb.append(cancellable);        sb.append(",path=");        sb.append(path);        sb.append(",validate=");        sb.append(validate);        if (actionId != null) {            sb.append(",actionId=");            sb.append(actionId);        }        if (attribute != null) {            sb.append(",attribute=");            sb.append(attribute);        }        if (catalog != null) {            sb.append(",catalog=");            sb.append(catalog);        }        if (command != null) {            sb.append(",command=");            sb.append(command);        }        if (inherit != null) {            sb.append(",extends=");            sb.append(inherit);        }        if (forward != null) {            sb.append(",forward=");            sb.append(forward);        }        if (include != null) {            sb.append(",include=");            sb.append(include);        }        if (input != null) {            sb.append(",input=");            sb.append(input);        }        if (multipartClass != null) {            sb.append(",multipartClass=");            sb.append(multipartClass);        }        if (name != null) {            sb.append(",name=");            sb.append(name);        }        if (parameter != null) {            sb.append(",parameter=");            sb.append(parameter);        }        if (prefix != null) {            sb.append(",prefix=");            sb.append(prefix);        }        if (roles != null) {            sb.append(",roles=");            sb.append(roles);        }        if (scope != null) {            sb.append(",scope=");            sb.append(scope);        }        if (reset != null) {            sb.append(",reset=");            sb.append(reset);        }        if (populate != null) {            sb.append(",populate=");            sb.append(populate);        }        if (suffix != null) {            sb.append(",suffix=");            sb.append(suffix);        }        if (type != null) {            sb.append(",type=");            sb.append(type);        }        return (sb.toString());    }}

⌨️ 快捷键说明

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