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

📄 managedbeandefinitiondocumentreader.java

📁 Please read your package and describe it at least 40 bytes in English. System will automatically de
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * Copyright 2002-2004 the original author or authors. *  * Licensed 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 de.mindmatters.faces.spring.factory.xml;import java.util.List;import java.util.Locale;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.springframework.beans.MutablePropertyValues;import org.springframework.beans.PropertyValue;import org.springframework.beans.factory.config.BeanDefinition;import org.springframework.beans.factory.config.BeanDefinitionHolder;import org.springframework.beans.factory.config.ConfigurableBeanFactory;import org.springframework.beans.factory.config.ConstructorArgumentValues;import org.springframework.beans.factory.config.TypedStringValue;import org.springframework.beans.factory.parsing.BeanComponentDefinition;import org.springframework.beans.factory.parsing.BeanEntry;import org.springframework.beans.factory.parsing.ParseState;import org.springframework.beans.factory.support.BeanDefinitionBuilder;import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;import org.springframework.beans.factory.support.ManagedList;import org.springframework.beans.factory.support.ManagedMap;import org.springframework.beans.factory.support.RootBeanDefinition;import org.springframework.beans.factory.xml.BeanDefinitionDocumentReader;import org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader;import org.springframework.beans.factory.xml.XmlReaderContext;import org.springframework.beans.propertyeditors.LocaleEditor;import org.springframework.context.HierarchicalMessageSource;import org.springframework.context.MessageSource;import org.springframework.context.MessageSourceResolvable;import org.springframework.context.support.AbstractApplicationContext;import org.springframework.context.support.ResourceBundleMessageSource;import org.springframework.util.ClassUtils;import org.springframework.util.StringUtils;import org.springframework.util.xml.DomUtils;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import de.mindmatters.faces.spring.context.FacesWebApplicationContext;import de.mindmatters.faces.spring.factory.ManagedBeanFactory;/** * Faces implementation of the {@link BeanDefinitionDocumentReader} interface. * Parses bean definitions according to the "faces-config" DTD. *  * <p> * Tries to build and register bean definitions of type * {@link de.mindmatters.faces.spring.factory.ManagedBeanDefinition} parsed from * the "managed-bean"-elements. Futhermode this parser is able to parse * definitions according to the spring beans DTD. * </p> *  * <dl> * <dt><strong>Note:</strong></dt> * <dd> * <ul> * <li>the ResourceBundle defined in the faces configuration file in the * "message-resource" tag is used as * {@link org.springframework.context.MessageSource}</li> * <li>only a bean with <code>application</code> scope defined in the faces * configuration file in the "managed-bean-scope" tag is interpreted as * singleton</li> * </ul> * </dd> * </dl> *  * @author Andreas Kuhrwahl *  * @see de.mindmatters.faces.spring.factory.ManagedBeanDefinition */public class ManagedBeanDefinitionDocumentReader implements        BeanDefinitionDocumentReader {    /**     * JSF implementation of a     * {@link org.springframework.context.HierarchicalMessageSource}. Checks if     * the given <code>Locale</code> is supported. See "locale-config" tag in     * the "faces-config" DTD.     *      * @author Andreas Kuhrwahl     * @author Thomas Jachmann     *      * @see org.springframework.context.support.ResourceBundleMessageSource     */    public static final class FacesHierarchicalMessageSource implements            HierarchicalMessageSource {        /** The supported locales. */        private List supportedLocales;        /** The default locale. */        private Locale defaultLocale;        /** The internal MessageSource this class delegates to. */        private final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();        /**         * Creates a faces message source.         */        protected FacesHierarchicalMessageSource() {            super();        }        /**         * Creates a faces MessageSource with the given base-names, default         * locale and supported locales.         *          * @param baseNames         *            names of the base message resource         * @param defaultLocale         *            name of the default locale         * @param supportedLocales         *            locales which are supported by this implementation         */        public FacesHierarchicalMessageSource(final List baseNames,                final String defaultLocale, final List supportedLocales) {            this();            this.messageSource.setBasenames((String[]) baseNames                    .toArray(new String[baseNames.size()]));            try {                LocaleEditor editor = new LocaleEditor();                editor.setAsText(defaultLocale);                this.defaultLocale = (Locale) editor.getValue();            } catch (Exception ex) {                this.defaultLocale = Locale.getDefault();            }            this.supportedLocales = supportedLocales;            this.supportedLocales.add(defaultLocale);        }        /**         * {@inheritDoc}         */        public void setParentMessageSource(final MessageSource parent) {            this.messageSource.setParentMessageSource(parent);        }        /**         * {@inheritDoc}         */        public MessageSource getParentMessageSource() {            return this.messageSource.getParentMessageSource();        }        /**         * {@inheritDoc}         */        public String getMessage(final String code, final Object[] args,                final String defaultMessage, final Locale locale) {            Locale supportedLocale = locale;            if (!this.supportedLocales.contains(supportedLocale.toString())) {                supportedLocale = this.defaultLocale;            }            return this.messageSource.getMessage(code, args, defaultMessage,                    supportedLocale);        }        /**         * {@inheritDoc}         */        public String getMessage(final String code, final Object[] args,                final Locale locale) {            Locale supportedLocale = locale;            if (!this.supportedLocales.contains(supportedLocale.toString())) {                supportedLocale = this.defaultLocale;            }            return this.messageSource.getMessage(code, args, supportedLocale);        }        /**         * {@inheritDoc}         */        public String getMessage(final MessageSourceResolvable resolvable,                final Locale locale) {            Locale supportedLocale = locale;            if (!this.supportedLocales.contains(supportedLocale.toString())) {                supportedLocale = this.defaultLocale;            }            return this.messageSource.getMessage(resolvable, supportedLocale);        }    }    /** &lt;faces-config&gt;&lt;/faces-config&gt; element. */    public static final String ROOT_ELEMENT = "faces-config";    /** &lt;message-bundle&gt;&lt;/message-bundle&gt; element. */    public static final String MESSAGE_BUNDLE_ELEMENT = "message-bundle";    /** &lt;locale-config&gt;&lt;/locale-config&gt; element. */    public static final String LOCALE_CONFIG_ELEMENT = "locale-config";    /** &lt;default-locale&gt;&lt;/default-locale&gt; element. */    public static final String DEFAULT_LOCALE_ELEMENT = "default-locale";    /** &lt;supported-locale&gt;&lt;/supported-locale&gt; element. */    public static final String SUPPORTED_LOCALE_ELEMENT = "supported-locale";    /** &lt;managed-bean&gt;&lt;/managed-bean&gt; element. */    public static final String BEAN_ELEMENT = "managed-bean";    /**     * id attribute of the &lt;managed-bean&gt;&lt;/managed-bean&gt; element.     */    public static final String ID_ATTRIBUTE = "id";    /** &lt;managed-bean-name&gt;&lt;/managed-bean-name&gt; element. */    public static final String NAME_ELEMENT = "managed-bean-name";    /** &lt;managed-bean-class&gt;&lt;/managed-bean-class&gt; element. */    public static final String CLASS_ELEMENT = "managed-bean-class";    /** &lt;managed-bean-scope&gt;&lt;/managed-bean-scope&gt; element. */    public static final String SCOPE_ELEMENT = "managed-bean-scope";    /** &lt;managed-property&gt;&lt;/managed-property&gt; element. */    public static final String PROPERTY_ELEMENT = "managed-property";    /** &lt;property-name&gt;&lt;/property-name&gt; element. */    public static final String PROPERTY_NAME_ELEMENT = "property-name";    /** &lt;property-class&gt;&lt;/property-class&gt; element. */    public static final String PROPERTY_CLASS_ELEMENT = "property-class";    /** &lt;value&gt;&lt;/value&gt; element. */    public static final String VALUE_ELEMENT = "value";    /** &lt;value-class&gt;&lt;/value-class&gt; element. */    public static final String VALUE_CLASS_ELEMENT = "value-class";    /** &lt;null-value&gt;&lt;/null-value&gt; element. */    public static final String NULL_VALUE_ELEMENT = "null-value";    /** &lt;map-entries&gt;&lt;/map-entries&gt; element. */    public static final String MAP_ENTRIES_ELEMENT = "map-entries";    /** &lt;map-entry&gt;&lt;/map-entry&gt; element. */    public static final String MAP_ENTRY_ELEMENT = "map-entry";    /** &lt;key&gt;&lt;/key&gt; element. */    public static final String KEY_ELEMENT = "key";    /** &lt;key-class&gt;&lt;/key-class&gt; element. */    public static final String KEY_CLASS_ELEMENT = "key-class";    /** &lt;list-entries&gt;&lt;/list-entries&gt; element. */    public static final String LIST_ENTRIES_ELEMENT = "list-entries";    /** The prototype scope. */    private static final String SCOPE_PROTOTYPE = ConfigurableBeanFactory.SCOPE_PROTOTYPE;    /** The singleton scope. */    private static final String SCOPE_SINGLETON = ConfigurableBeanFactory.SCOPE_SINGLETON;    /** For logging. */    protected final Log logger = LogFactory.getLog(getClass());    /**     * The {@link XmlReaderContext} used within this     * {@link BeanDefinitionDocumentReader}.     */

⌨️ 快捷键说明

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