more work on enabling non-namespace extensions of xml parsing

This commit is contained in:
Rob Harrop 2009-09-11 20:00:04 +00:00
parent 1e9fc388ac
commit fe16447112
2 changed files with 17 additions and 5 deletions

View File

@ -1417,4 +1417,14 @@ public class BeanDefinitionParserDelegate {
public boolean nodeNameEquals(Node node, String desiredName) { public boolean nodeNameEquals(Node node, String desiredName) {
return DomUtils.nodeNameEquals(node, desiredName); return DomUtils.nodeNameEquals(node, desiredName);
} }
/**
* 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();
}
} }

View File

@ -77,10 +77,11 @@ public abstract class NamespaceHandlerSupport implements NamespaceHandler {
* the local name of the supplied {@link Element}. * the local name of the supplied {@link Element}.
*/ */
private BeanDefinitionParser findParserForElement(Element element, ParserContext parserContext) { private BeanDefinitionParser findParserForElement(Element element, ParserContext parserContext) {
BeanDefinitionParser parser = this.parsers.get(element.getLocalName()); String localName = parserContext.getDelegate().getLocalName(element);
BeanDefinitionParser parser = this.parsers.get(localName);
if (parser == null) { if (parser == null) {
parserContext.getReaderContext().fatal( parserContext.getReaderContext().fatal(
"Cannot locate BeanDefinitionParser for element [" + element.getLocalName() + "]", element); "Cannot locate BeanDefinitionParser for element [" + localName + "]", element);
} }
return parser; return parser;
} }
@ -102,11 +103,12 @@ public abstract class NamespaceHandlerSupport implements NamespaceHandler {
*/ */
private BeanDefinitionDecorator findDecoratorForNode(Node node, ParserContext parserContext) { private BeanDefinitionDecorator findDecoratorForNode(Node node, ParserContext parserContext) {
BeanDefinitionDecorator decorator = null; BeanDefinitionDecorator decorator = null;
String localName = parserContext.getDelegate().getLocalName(node);
if (node instanceof Element) { if (node instanceof Element) {
decorator = this.decorators.get(node.getLocalName()); decorator = this.decorators.get(localName);
} }
else if (node instanceof Attr) { else if (node instanceof Attr) {
decorator = this.attributeDecorators.get(node.getLocalName()); decorator = this.attributeDecorators.get(localName);
} }
else { else {
parserContext.getReaderContext().fatal( parserContext.getReaderContext().fatal(
@ -114,7 +116,7 @@ public abstract class NamespaceHandlerSupport implements NamespaceHandler {
} }
if (decorator == null) { if (decorator == null) {
parserContext.getReaderContext().fatal("Cannot locate BeanDefinitionDecorator for " + parserContext.getReaderContext().fatal("Cannot locate BeanDefinitionDecorator for " +
(node instanceof Element ? "element" : "attribute") + " [" + node.getLocalName() + "]", node); (node instanceof Element ? "element" : "attribute") + " [" + localName + "]", node);
} }
return decorator; return decorator;
} }