From 23e67fbe1c61a8a8e91fc3149b127bb1b1f16e40 Mon Sep 17 00:00:00 2001 From: Rob Harrop Date: Mon, 14 Sep 2009 15:00:37 +0000 Subject: [PATCH] [SPR-6017] a few more tweaks to how getLocalName is handled git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1878 50f2f4bb-b051-0410-bef5-90022cba6387 --- .../AbstractSimpleBeanDefinitionParser.java | 29 +++++++++++++++---- .../ComponentScanBeanDefinitionParser.java | 6 ++-- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/AbstractSimpleBeanDefinitionParser.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/AbstractSimpleBeanDefinitionParser.java index abe347348d3..20c96bba686 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/AbstractSimpleBeanDefinitionParser.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/AbstractSimpleBeanDefinitionParser.java @@ -124,11 +124,11 @@ public abstract class AbstractSimpleBeanDefinitionParser extends AbstractSingleB * @see #extractPropertyName(String) */ @Override - protected final void doParse(Element element, BeanDefinitionBuilder builder) { + protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { NamedNodeMap attributes = element.getAttributes(); for (int x = 0; x < attributes.getLength(); x++) { Attr attribute = (Attr) attributes.item(x); - if (isEligibleAttribute(attribute)) { + if (isEligibleAttribute(attribute, parserContext)) { String propertyName = extractPropertyName(attribute.getLocalName()); Assert.state(StringUtils.hasText(propertyName), "Illegal property name returned from 'extractPropertyName(String)': cannot be null or empty."); @@ -144,12 +144,31 @@ public abstract class AbstractSimpleBeanDefinitionParser extends AbstractSingleB *

The default implementation considers any attribute as eligible, * except for the "id" attribute and namespace declaration attributes. * @param attribute the XML attribute to check + * @param parserContext the ParserContext * @see #isEligibleAttribute(String) */ + protected boolean isEligibleAttribute(Attr attribute, ParserContext parserContext) { + boolean eligible = isEligibleAttribute(attribute); + if(!eligible) { + String fullName = attribute.getName(); + eligible = (!fullName.equals("xmlns") && !fullName.startsWith("xmlns:") && + isEligibleAttribute(parserContext.getDelegate().getLocalName(attribute))); + } + return eligible; + } + + /** + * Determine whether the given attribute is eligible for being + * turned into a corresponding bean property value. + *

The default implementation considers any attribute as eligible, + * except for the "id" attribute and namespace declaration attributes. + * @param attribute the XML attribute to check + * @see #isEligibleAttribute(String) + * @deprecated in favour of {@link #isEligibleAttribute(org.w3c.dom.Attr, ParserContext)} + */ + @Deprecated protected boolean isEligibleAttribute(Attr attribute) { - String fullName = attribute.getName(); - return (!fullName.equals("xmlns") && !fullName.startsWith("xmlns:") && - isEligibleAttribute(attribute.getLocalName())); + return false; } /** diff --git a/org.springframework.context/src/main/java/org/springframework/context/annotation/ComponentScanBeanDefinitionParser.java b/org.springframework.context/src/main/java/org/springframework/context/annotation/ComponentScanBeanDefinitionParser.java index b550048b6ec..a6dee3590ae 100644 --- a/org.springframework.context/src/main/java/org/springframework/context/annotation/ComponentScanBeanDefinitionParser.java +++ b/org.springframework.context/src/main/java/org/springframework/context/annotation/ComponentScanBeanDefinitionParser.java @@ -119,7 +119,7 @@ public class ComponentScanBeanDefinitionParser implements BeanDefinitionParser { readerContext.error(ex.getMessage(), readerContext.extractSource(element), ex.getCause()); } - parseTypeFilters(element, scanner, readerContext); + parseTypeFilters(element, scanner, readerContext, parserContext); return scanner; } @@ -194,7 +194,7 @@ public class ComponentScanBeanDefinitionParser implements BeanDefinitionParser { } protected void parseTypeFilters( - Element element, ClassPathBeanDefinitionScanner scanner, XmlReaderContext readerContext) { + Element element, ClassPathBeanDefinitionScanner scanner, XmlReaderContext readerContext, ParserContext parserContext) { // Parse exclude and include filter elements. ClassLoader classLoader = scanner.getResourceLoader().getClassLoader(); @@ -202,7 +202,7 @@ public class ComponentScanBeanDefinitionParser implements BeanDefinitionParser { for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { - String localName = node.getLocalName(); + String localName = parserContext.getDelegate().getLocalName(node); try { if (INCLUDE_FILTER_ELEMENT.equals(localName)) { TypeFilter typeFilter = createTypeFilter((Element) node, classLoader);