📄 managedbeandefinitiondocumentreader.java
字号:
/* * 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); } } /** <faces-config></faces-config> element. */ public static final String ROOT_ELEMENT = "faces-config"; /** <message-bundle></message-bundle> element. */ public static final String MESSAGE_BUNDLE_ELEMENT = "message-bundle"; /** <locale-config></locale-config> element. */ public static final String LOCALE_CONFIG_ELEMENT = "locale-config"; /** <default-locale></default-locale> element. */ public static final String DEFAULT_LOCALE_ELEMENT = "default-locale"; /** <supported-locale></supported-locale> element. */ public static final String SUPPORTED_LOCALE_ELEMENT = "supported-locale"; /** <managed-bean></managed-bean> element. */ public static final String BEAN_ELEMENT = "managed-bean"; /** * id attribute of the <managed-bean></managed-bean> element. */ public static final String ID_ATTRIBUTE = "id"; /** <managed-bean-name></managed-bean-name> element. */ public static final String NAME_ELEMENT = "managed-bean-name"; /** <managed-bean-class></managed-bean-class> element. */ public static final String CLASS_ELEMENT = "managed-bean-class"; /** <managed-bean-scope></managed-bean-scope> element. */ public static final String SCOPE_ELEMENT = "managed-bean-scope"; /** <managed-property></managed-property> element. */ public static final String PROPERTY_ELEMENT = "managed-property"; /** <property-name></property-name> element. */ public static final String PROPERTY_NAME_ELEMENT = "property-name"; /** <property-class></property-class> element. */ public static final String PROPERTY_CLASS_ELEMENT = "property-class"; /** <value></value> element. */ public static final String VALUE_ELEMENT = "value"; /** <value-class></value-class> element. */ public static final String VALUE_CLASS_ELEMENT = "value-class"; /** <null-value></null-value> element. */ public static final String NULL_VALUE_ELEMENT = "null-value"; /** <map-entries></map-entries> element. */ public static final String MAP_ENTRIES_ELEMENT = "map-entries"; /** <map-entry></map-entry> element. */ public static final String MAP_ENTRY_ELEMENT = "map-entry"; /** <key></key> element. */ public static final String KEY_ELEMENT = "key"; /** <key-class></key-class> element. */ public static final String KEY_CLASS_ELEMENT = "key-class"; /** <list-entries></list-entries> 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 + -