提交 a6d9c908 编写于 作者: J Juergen Hoeller

refined BeanDefinitionParserDelegate to only parse default elements if they...

refined BeanDefinitionParserDelegate to only parse default elements if they actually live in the default namespace (SPR-7218)
上级 0390c2b9
/*
* 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");
* you may not use this file except in compliance with the License.
......@@ -621,7 +621,7 @@ public class BeanDefinitionParserDelegate {
NodeList nl = ele.getChildNodes();
for (int i = 0; i < nl.getLength(); 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;
String key = metaElement.getAttribute(KEY_ATTRIBUTE);
String value = metaElement.getAttribute(VALUE_ATTRIBUTE);
......@@ -680,7 +680,7 @@ public class BeanDefinitionParserDelegate {
NodeList nl = beanEle.getChildNodes();
for (int i = 0; i < nl.getLength(); 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);
}
}
......@@ -693,7 +693,7 @@ public class BeanDefinitionParserDelegate {
NodeList nl = beanEle.getChildNodes();
for (int i = 0; i < nl.getLength(); 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);
}
}
......@@ -706,7 +706,7 @@ public class BeanDefinitionParserDelegate {
NodeList nl = beanEle.getChildNodes();
for (int i = 0; i < nl.getLength(); 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);
}
}
......@@ -719,7 +719,7 @@ public class BeanDefinitionParserDelegate {
NodeList nl = beanEle.getChildNodes();
for (int i = 0; i < nl.getLength(); 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;
String methodName = ele.getAttribute(NAME_ATTRIBUTE);
String beanRef = ele.getAttribute(BEAN_ELEMENT);
......@@ -737,7 +737,7 @@ public class BeanDefinitionParserDelegate {
NodeList nl = beanEle.getChildNodes();
for (int i = 0; i < nl.getLength(); 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;
String name = replacedMethodEle.getAttribute(NAME_ATTRIBUTE);
String callback = replacedMethodEle.getAttribute(REPLACER_ATTRIBUTE);
......@@ -860,7 +860,7 @@ public class BeanDefinitionParserDelegate {
NodeList nl = ele.getChildNodes();
for (int i = 0; i < nl.getLength(); 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;
String attributeName = attributeEle.getAttribute(KEY_ATTRIBUTE);
String attributeValue = attributeEle.getAttribute(VALUE_ATTRIBUTE);
......@@ -952,7 +952,7 @@ public class BeanDefinitionParserDelegate {
* <code>&lt;value&gt;</code> tag that might be created
*/
public Object parsePropertySubElement(Element ele, BeanDefinition bd, String defaultValueType) {
if (!isDefaultNamespace(getNamespaceURI(ele))) {
if (!isDefaultNamespace(ele)) {
return parseNestedCustomElement(ele, bd);
}
else if (nodeNameEquals(ele, BEAN_ELEMENT)) {
......@@ -1384,10 +1384,6 @@ public class BeanDefinitionParserDelegate {
return originalDef;
}
public boolean isDefaultNamespace(String namespaceUri) {
return (!StringUtils.hasLength(namespaceUri) || BEANS_NAMESPACE_URI.equals(namespaceUri));
}
private BeanDefinitionHolder parseNestedCustomElement(Element ele, BeanDefinition containingBd) {
BeanDefinition innerDefinition = parseCustomElement(ele, containingBd);
if (innerDefinition == null) {
......@@ -1404,8 +1400,9 @@ public class BeanDefinitionParserDelegate {
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.
* @param node 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)
* and {@link #getLoclName}.
* 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));
}
/**
* Gets 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();
public boolean isDefaultNamespace(String namespaceUri) {
return (!StringUtils.hasLength(namespaceUri) || BEANS_NAMESPACE_URI.equals(namespaceUri));
}
public boolean isDefaultNamespace(Node node) {
return isDefaultNamespace(getNamespaceURI(node));
}
private boolean isDefaultElement(Node node) {
return (node instanceof Element && isDefaultNamespace(node));
}
}
/*
* 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");
* 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
*/
protected void parseBeanDefinitions(Element root, BeanDefinitionParserDelegate delegate) {
if (delegate.isDefaultNamespace(delegate.getNamespaceURI(root))) {
if (delegate.isDefaultNamespace(root)) {
NodeList nl = root.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element) {
Element ele = (Element) node;
String namespaceUri = delegate.getNamespaceURI(ele);
if (delegate.isDefaultNamespace(namespaceUri)) {
if (delegate.isDefaultNamespace(ele)) {
parseDefaultElement(ele, delegate);
}
else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册