Skip to content

Commit 7835e66

Browse files
author
Rob Harrop
committed
[SPR-6017] a few more tweaks to how getLocalName is handled
1 parent ee0a59d commit 7835e66

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

org.springframework.aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
106106
for (int i = 0; i < childNodes.getLength(); i++) {
107107
Node node = childNodes.item(i);
108108
if (node.getNodeType() == Node.ELEMENT_NODE) {
109-
String localName = node.getLocalName();
109+
String localName = parserContext.getDelegate().getLocalName(node);
110110
if (POINTCUT.equals(localName)) {
111111
parsePointcut((Element) node, parserContext);
112112
}
@@ -216,7 +216,7 @@ private void parseAspect(Element aspectElement, ParserContext parserContext) {
216216
boolean adviceFoundAlready = false;
217217
for (int i = 0; i < nodeList.getLength(); i++) {
218218
Node node = nodeList.item(i);
219-
if (isAdviceNode(node)) {
219+
if (isAdviceNode(node, parserContext)) {
220220
if (!adviceFoundAlready) {
221221
adviceFoundAlready = true;
222222
if (!StringUtils.hasText(aspectName)) {
@@ -264,12 +264,12 @@ private AspectComponentDefinition createAspectComponentDefinition(
264264
* '<code>before</code>', '<code>after</code>', '<code>after-returning</code>',
265265
* '<code>after-throwing</code>' or '<code>around</code>'.
266266
*/
267-
private boolean isAdviceNode(Node aNode) {
267+
private boolean isAdviceNode(Node aNode, ParserContext parserContext) {
268268
if (!(aNode instanceof Element)) {
269269
return false;
270270
}
271271
else {
272-
String name = aNode.getLocalName();
272+
String name = parserContext.getDelegate().getLocalName(aNode);
273273
return (BEFORE.equals(name) || AFTER.equals(name) || AFTER_RETURNING_ELEMENT.equals(name) ||
274274
AFTER_THROWING_ELEMENT.equals(name) || AROUND.equals(name));
275275
}
@@ -317,7 +317,7 @@ private AbstractBeanDefinition parseAdvice(
317317
List<BeanDefinition> beanDefinitions, List<BeanReference> beanReferences) {
318318

319319
try {
320-
this.parseState.push(new AdviceEntry(adviceElement.getLocalName()));
320+
this.parseState.push(new AdviceEntry(parserContext.getDelegate().getLocalName(adviceElement)));
321321

322322
// create the method factory bean
323323
RootBeanDefinition methodDefinition = new RootBeanDefinition(MethodLocatingFactoryBean.class);
@@ -366,7 +366,7 @@ private AbstractBeanDefinition createAdviceDefinition(
366366
RootBeanDefinition methodDef, RootBeanDefinition aspectFactoryDef,
367367
List<BeanDefinition> beanDefinitions, List<BeanReference> beanReferences) {
368368

369-
RootBeanDefinition adviceDefinition = new RootBeanDefinition(getAdviceClass(adviceElement));
369+
RootBeanDefinition adviceDefinition = new RootBeanDefinition(getAdviceClass(adviceElement, parserContext));
370370
adviceDefinition.setSource(parserContext.extractSource(adviceElement));
371371

372372
adviceDefinition.getPropertyValues().addPropertyValue(ASPECT_NAME_PROPERTY, aspectName);
@@ -407,8 +407,8 @@ else if (pointcut instanceof String) {
407407
/**
408408
* Gets the advice implementation class corresponding to the supplied {@link Element}.
409409
*/
410-
private Class getAdviceClass(Element adviceElement) {
411-
String elementName = adviceElement.getLocalName();
410+
private Class getAdviceClass(Element adviceElement, ParserContext parserContext) {
411+
String elementName = parserContext.getDelegate().getLocalName(adviceElement);
412412
if (BEFORE.equals(elementName)) {
413413
return AspectJMethodBeforeAdvice.class;
414414
}

org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/AbstractBeanDefinitionParser.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public final BeanDefinition parse(Element element, ParserContext parserContext)
5959
String id = resolveId(element, definition, parserContext);
6060
if (!StringUtils.hasText(id)) {
6161
parserContext.getReaderContext().error(
62-
"Id is required for element '" + element.getLocalName() + "' when used as a top-level tag", element);
62+
"Id is required for element '" + parserContext.getDelegate().getLocalName(element)
63+
+ "' when used as a top-level tag", element);
6364
}
6465
BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id);
6566
registerBeanDefinition(holder, parserContext.getRegistry());

org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/SimplePropertyNamespaceHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
6363
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
6464
if (node instanceof Attr) {
6565
Attr attr = (Attr) node;
66-
String propertyName = attr.getLocalName();
66+
String propertyName = parserContext.getDelegate().getLocalName(attr);
6767
String propertyValue = attr.getValue();
6868
MutablePropertyValues pvs = definition.getBeanDefinition().getPropertyValues();
6969
if (pvs.contains(propertyName)) {

org.springframework.context/src/main/java/org/springframework/scheduling/config/ScheduledTasksBeanDefinitionParser.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
*/
3636
public class ScheduledTasksBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
3737

38+
private static final String ELEMENT_SCHEDULED = "scheduled";
39+
3840
@Override
3941
protected boolean shouldGenerateId() {
4042
return true;
@@ -53,7 +55,7 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
5355
NodeList childNodes = element.getChildNodes();
5456
for (int i = 0; i < childNodes.getLength(); i++) {
5557
Node child = childNodes.item(i);
56-
if (!(child instanceof Element) || !child.getLocalName().equals("scheduled")) {
58+
if (!isScheduledElement(child, parserContext)) {
5759
continue;
5860
}
5961
Element taskElement = (Element) child;
@@ -99,6 +101,11 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
99101
builder.addPropertyValue("fixedRateTasks", fixedRateTaskMap);
100102
}
101103

104+
private boolean isScheduledElement(Node node, ParserContext parserContext) {
105+
return node.getNodeType() == Node.ELEMENT_NODE &&
106+
ELEMENT_SCHEDULED.equals(parserContext.getDelegate().getLocalName(node));
107+
}
108+
102109
private String createRunnableBean(String ref, String method, Element taskElement, ParserContext parserContext) {
103110
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
104111
"org.springframework.scheduling.support.MethodInvokingRunnable");

org.springframework.jms/src/main/java/org/springframework/jms/config/AbstractListenerContainerParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
9595
for (int i = 0; i < childNodes.getLength(); i++) {
9696
Node child = childNodes.item(i);
9797
if (child.getNodeType() == Node.ELEMENT_NODE) {
98-
String localName = child.getLocalName();
98+
String localName = parserContext.getDelegate().getLocalName(child);
9999
if (LISTENER_ELEMENT.equals(localName)) {
100100
parseListener((Element) child, element, parserContext);
101101
}

0 commit comments

Comments
 (0)