refined BeanDefinitionParserDelegate to only parse default elements if they actually live in the default namespace (SPR-7218)
This commit is contained in:
parent
0390c2b9fe
commit
a6d9c90841
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -621,7 +621,7 @@ public class BeanDefinitionParserDelegate {
|
||||||
NodeList nl = ele.getChildNodes();
|
NodeList nl = ele.getChildNodes();
|
||||||
for (int i = 0; i < nl.getLength(); i++) {
|
for (int i = 0; i < nl.getLength(); i++) {
|
||||||
Node node = nl.item(i);
|
Node node = nl.item(i);
|
||||||
if (node instanceof Element && nodeNameEquals(node, META_ELEMENT)) {
|
if (isDefaultElement(node) && nodeNameEquals(node, META_ELEMENT)) {
|
||||||
Element metaElement = (Element) node;
|
Element metaElement = (Element) node;
|
||||||
String key = metaElement.getAttribute(KEY_ATTRIBUTE);
|
String key = metaElement.getAttribute(KEY_ATTRIBUTE);
|
||||||
String value = metaElement.getAttribute(VALUE_ATTRIBUTE);
|
String value = metaElement.getAttribute(VALUE_ATTRIBUTE);
|
||||||
|
|
@ -680,7 +680,7 @@ public class BeanDefinitionParserDelegate {
|
||||||
NodeList nl = beanEle.getChildNodes();
|
NodeList nl = beanEle.getChildNodes();
|
||||||
for (int i = 0; i < nl.getLength(); i++) {
|
for (int i = 0; i < nl.getLength(); i++) {
|
||||||
Node node = nl.item(i);
|
Node node = nl.item(i);
|
||||||
if (node instanceof Element && nodeNameEquals(node, CONSTRUCTOR_ARG_ELEMENT)) {
|
if (isDefaultElement(node) && nodeNameEquals(node, CONSTRUCTOR_ARG_ELEMENT)) {
|
||||||
parseConstructorArgElement((Element) node, bd);
|
parseConstructorArgElement((Element) node, bd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -693,7 +693,7 @@ public class BeanDefinitionParserDelegate {
|
||||||
NodeList nl = beanEle.getChildNodes();
|
NodeList nl = beanEle.getChildNodes();
|
||||||
for (int i = 0; i < nl.getLength(); i++) {
|
for (int i = 0; i < nl.getLength(); i++) {
|
||||||
Node node = nl.item(i);
|
Node node = nl.item(i);
|
||||||
if (node instanceof Element && nodeNameEquals(node, PROPERTY_ELEMENT)) {
|
if (isDefaultElement(node) && nodeNameEquals(node, PROPERTY_ELEMENT)) {
|
||||||
parsePropertyElement((Element) node, bd);
|
parsePropertyElement((Element) node, bd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -706,7 +706,7 @@ public class BeanDefinitionParserDelegate {
|
||||||
NodeList nl = beanEle.getChildNodes();
|
NodeList nl = beanEle.getChildNodes();
|
||||||
for (int i = 0; i < nl.getLength(); i++) {
|
for (int i = 0; i < nl.getLength(); i++) {
|
||||||
Node node = nl.item(i);
|
Node node = nl.item(i);
|
||||||
if (node instanceof Element && nodeNameEquals(node, QUALIFIER_ELEMENT)) {
|
if (isDefaultElement(node) && nodeNameEquals(node, QUALIFIER_ELEMENT)) {
|
||||||
parseQualifierElement((Element) node, bd);
|
parseQualifierElement((Element) node, bd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -719,7 +719,7 @@ public class BeanDefinitionParserDelegate {
|
||||||
NodeList nl = beanEle.getChildNodes();
|
NodeList nl = beanEle.getChildNodes();
|
||||||
for (int i = 0; i < nl.getLength(); i++) {
|
for (int i = 0; i < nl.getLength(); i++) {
|
||||||
Node node = nl.item(i);
|
Node node = nl.item(i);
|
||||||
if (node instanceof Element && nodeNameEquals(node, LOOKUP_METHOD_ELEMENT)) {
|
if (isDefaultElement(node) && nodeNameEquals(node, LOOKUP_METHOD_ELEMENT)) {
|
||||||
Element ele = (Element) node;
|
Element ele = (Element) node;
|
||||||
String methodName = ele.getAttribute(NAME_ATTRIBUTE);
|
String methodName = ele.getAttribute(NAME_ATTRIBUTE);
|
||||||
String beanRef = ele.getAttribute(BEAN_ELEMENT);
|
String beanRef = ele.getAttribute(BEAN_ELEMENT);
|
||||||
|
|
@ -737,7 +737,7 @@ public class BeanDefinitionParserDelegate {
|
||||||
NodeList nl = beanEle.getChildNodes();
|
NodeList nl = beanEle.getChildNodes();
|
||||||
for (int i = 0; i < nl.getLength(); i++) {
|
for (int i = 0; i < nl.getLength(); i++) {
|
||||||
Node node = nl.item(i);
|
Node node = nl.item(i);
|
||||||
if (node instanceof Element && nodeNameEquals(node, REPLACED_METHOD_ELEMENT)) {
|
if (isDefaultElement(node) && nodeNameEquals(node, REPLACED_METHOD_ELEMENT)) {
|
||||||
Element replacedMethodEle = (Element) node;
|
Element replacedMethodEle = (Element) node;
|
||||||
String name = replacedMethodEle.getAttribute(NAME_ATTRIBUTE);
|
String name = replacedMethodEle.getAttribute(NAME_ATTRIBUTE);
|
||||||
String callback = replacedMethodEle.getAttribute(REPLACER_ATTRIBUTE);
|
String callback = replacedMethodEle.getAttribute(REPLACER_ATTRIBUTE);
|
||||||
|
|
@ -860,7 +860,7 @@ public class BeanDefinitionParserDelegate {
|
||||||
NodeList nl = ele.getChildNodes();
|
NodeList nl = ele.getChildNodes();
|
||||||
for (int i = 0; i < nl.getLength(); i++) {
|
for (int i = 0; i < nl.getLength(); i++) {
|
||||||
Node node = nl.item(i);
|
Node node = nl.item(i);
|
||||||
if (node instanceof Element && nodeNameEquals(node, QUALIFIER_ATTRIBUTE_ELEMENT)) {
|
if (isDefaultElement(node) && nodeNameEquals(node, QUALIFIER_ATTRIBUTE_ELEMENT)) {
|
||||||
Element attributeEle = (Element) node;
|
Element attributeEle = (Element) node;
|
||||||
String attributeName = attributeEle.getAttribute(KEY_ATTRIBUTE);
|
String attributeName = attributeEle.getAttribute(KEY_ATTRIBUTE);
|
||||||
String attributeValue = attributeEle.getAttribute(VALUE_ATTRIBUTE);
|
String attributeValue = attributeEle.getAttribute(VALUE_ATTRIBUTE);
|
||||||
|
|
@ -952,7 +952,7 @@ public class BeanDefinitionParserDelegate {
|
||||||
* <code><value></code> tag that might be created
|
* <code><value></code> tag that might be created
|
||||||
*/
|
*/
|
||||||
public Object parsePropertySubElement(Element ele, BeanDefinition bd, String defaultValueType) {
|
public Object parsePropertySubElement(Element ele, BeanDefinition bd, String defaultValueType) {
|
||||||
if (!isDefaultNamespace(getNamespaceURI(ele))) {
|
if (!isDefaultNamespace(ele)) {
|
||||||
return parseNestedCustomElement(ele, bd);
|
return parseNestedCustomElement(ele, bd);
|
||||||
}
|
}
|
||||||
else if (nodeNameEquals(ele, BEAN_ELEMENT)) {
|
else if (nodeNameEquals(ele, BEAN_ELEMENT)) {
|
||||||
|
|
@ -1384,10 +1384,6 @@ public class BeanDefinitionParserDelegate {
|
||||||
return originalDef;
|
return originalDef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDefaultNamespace(String namespaceUri) {
|
|
||||||
return (!StringUtils.hasLength(namespaceUri) || BEANS_NAMESPACE_URI.equals(namespaceUri));
|
|
||||||
}
|
|
||||||
|
|
||||||
private BeanDefinitionHolder parseNestedCustomElement(Element ele, BeanDefinition containingBd) {
|
private BeanDefinitionHolder parseNestedCustomElement(Element ele, BeanDefinition containingBd) {
|
||||||
BeanDefinition innerDefinition = parseCustomElement(ele, containingBd);
|
BeanDefinition innerDefinition = parseCustomElement(ele, containingBd);
|
||||||
if (innerDefinition == null) {
|
if (innerDefinition == null) {
|
||||||
|
|
@ -1404,8 +1400,9 @@ public class BeanDefinitionParserDelegate {
|
||||||
return new BeanDefinitionHolder(innerDefinition, id);
|
return new BeanDefinitionHolder(innerDefinition, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the namespace URI for the supplied node. The default implementation uses {@link Node#getNamespaceURI}.
|
* Get the namespace URI for the supplied node. The default implementation uses {@link Node#getNamespaceURI}.
|
||||||
* Subclasses may override the default implementation to provide a different namespace identification mechanism.
|
* Subclasses may override the default implementation to provide a different namespace identification mechanism.
|
||||||
* @param node the node
|
* @param node the node
|
||||||
* @return the namespace URI of the the node.
|
* @return the namespace URI of the the node.
|
||||||
|
|
@ -1415,7 +1412,17 @@ public class BeanDefinitionParserDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether the name of the supplied node is equal to the supplied name.
|
* Ges the local name for the supplied {@link Node}. The default implementation calls {@link Node#getLocalName}.
|
||||||
|
* Subclasses may override the default implementation to provide a different mechanism for getting the local name.
|
||||||
|
* @param node the <code>Node</code>
|
||||||
|
* @return the local name of the supplied <code>Node</code>.
|
||||||
|
*/
|
||||||
|
public String getLocalName(Node node) {
|
||||||
|
return node.getLocalName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the name of the supplied node is equal to the supplied name.
|
||||||
* The default implementation checks the supplied desired name against both {@link Node#getNodeName)
|
* The default implementation checks the supplied desired name against both {@link Node#getNodeName)
|
||||||
* and {@link #getLoclName}.
|
* and {@link #getLoclName}.
|
||||||
* Subclasses may override the default implementation to provide a different mechanism for comparing node names.
|
* Subclasses may override the default implementation to provide a different mechanism for comparing node names.
|
||||||
|
|
@ -1427,13 +1434,16 @@ public class BeanDefinitionParserDelegate {
|
||||||
return desiredName.equals(node.getNodeName()) || desiredName.equals(getLocalName(node));
|
return desiredName.equals(node.getNodeName()) || desiredName.equals(getLocalName(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public boolean isDefaultNamespace(String namespaceUri) {
|
||||||
* Gets the local name for the supplied {@link Node}. The default implementation calls {@link Node#getLocalName}.
|
return (!StringUtils.hasLength(namespaceUri) || BEANS_NAMESPACE_URI.equals(namespaceUri));
|
||||||
* Subclasses may override the default implementation to provide a different mechanism for getting the local name.
|
|
||||||
* @param node the <code>Node</code>
|
|
||||||
* @return the local name of the supplied <code>Node</code>.
|
|
||||||
*/
|
|
||||||
public String getLocalName(Node node) {
|
|
||||||
return node.getLocalName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDefaultNamespace(Node node) {
|
||||||
|
return isDefaultNamespace(getNamespaceURI(node));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isDefaultElement(Node node) {
|
||||||
|
return (node instanceof Element && isDefaultNamespace(node));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -122,14 +122,13 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume
|
||||||
* @param root the DOM root element of the document
|
* @param root the DOM root element of the document
|
||||||
*/
|
*/
|
||||||
protected void parseBeanDefinitions(Element root, BeanDefinitionParserDelegate delegate) {
|
protected void parseBeanDefinitions(Element root, BeanDefinitionParserDelegate delegate) {
|
||||||
if (delegate.isDefaultNamespace(delegate.getNamespaceURI(root))) {
|
if (delegate.isDefaultNamespace(root)) {
|
||||||
NodeList nl = root.getChildNodes();
|
NodeList nl = root.getChildNodes();
|
||||||
for (int i = 0; i < nl.getLength(); i++) {
|
for (int i = 0; i < nl.getLength(); i++) {
|
||||||
Node node = nl.item(i);
|
Node node = nl.item(i);
|
||||||
if (node instanceof Element) {
|
if (node instanceof Element) {
|
||||||
Element ele = (Element) node;
|
Element ele = (Element) node;
|
||||||
String namespaceUri = delegate.getNamespaceURI(ele);
|
if (delegate.isDefaultNamespace(ele)) {
|
||||||
if (delegate.isDefaultNamespace(namespaceUri)) {
|
|
||||||
parseDefaultElement(ele, delegate);
|
parseDefaultElement(ele, delegate);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue