Merge pull request #153 from gid79/SPR-9812
* SPR-9812: Allow 'arg-type' matches against element body Polish whitespace
This commit is contained in:
commit
e4158f91a4
|
@ -827,7 +827,11 @@ public class BeanDefinitionParserDelegate {
|
||||||
// Look for arg-type match elements.
|
// Look for arg-type match elements.
|
||||||
List<Element> argTypeEles = DomUtils.getChildElementsByTagName(replacedMethodEle, ARG_TYPE_ELEMENT);
|
List<Element> argTypeEles = DomUtils.getChildElementsByTagName(replacedMethodEle, ARG_TYPE_ELEMENT);
|
||||||
for (Element argTypeEle : argTypeEles) {
|
for (Element argTypeEle : argTypeEles) {
|
||||||
replaceOverride.addTypeIdentifier(argTypeEle.getAttribute(ARG_TYPE_MATCH_ATTRIBUTE));
|
String match = argTypeEle.getAttribute(ARG_TYPE_MATCH_ATTRIBUTE);
|
||||||
|
match = (StringUtils.hasText(match) ? match : DomUtils.getTextValue(argTypeEle));
|
||||||
|
if (StringUtils.hasText(match)) {
|
||||||
|
replaceOverride.addTypeIdentifier(match);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
replaceOverride.setSource(extractSource(replacedMethodEle));
|
replaceOverride.setSource(extractSource(replacedMethodEle));
|
||||||
overrides.addOverride(replaceOverride);
|
overrides.addOverride(replaceOverride);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2012 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.
|
||||||
|
@ -540,6 +540,9 @@ abstract class OverrideOneMethod extends MethodReplaceCandidate implements Overr
|
||||||
return "replaceMe:" + someParam;
|
return "replaceMe:" + someParam;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String replaceMe(String someParam) {
|
||||||
|
return "replaceMe:" + someParam;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
<beans>
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Not yet in use: illustration of possible approach
|
Not yet in use: illustration of possible approach
|
||||||
|
@ -80,4 +80,16 @@
|
||||||
<property name="age"><value>27</value></property>
|
<property name="age"><value>27</value></property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean id="overrideOneMethodByAttribute" class="org.springframework.beans.factory.xml.OverrideOneMethod">
|
||||||
|
<replaced-method name="replaceMe" replacer="reverseReplacer">
|
||||||
|
<arg-type match="String"/>
|
||||||
|
</replaced-method>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="overrideOneMethodByElement" class="org.springframework.beans.factory.xml.OverrideOneMethod">
|
||||||
|
<replaced-method name="replaceMe" replacer="reverseReplacer">
|
||||||
|
<arg-type>String</arg-type>
|
||||||
|
</replaced-method>
|
||||||
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2012 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.
|
||||||
|
@ -1489,6 +1489,24 @@ public final class XmlBeanFactoryTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Test void testOverrideMethodByArgTypeAttribute() {
|
||||||
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
reader.loadBeanDefinitions(DELEGATION_OVERRIDES_CONTEXT);
|
||||||
|
OverrideOneMethod oom = (OverrideOneMethod) xbf.getBean("overrideOneMethodByAttribute");
|
||||||
|
assertEquals("should not replace", "replaceMe:1", oom.replaceMe(1));
|
||||||
|
assertEquals("should replace", "cba", oom.replaceMe("abc"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Test void testOverrideMethodByArgTypeElement() {
|
||||||
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
reader.loadBeanDefinitions(DELEGATION_OVERRIDES_CONTEXT);
|
||||||
|
OverrideOneMethod oom = (OverrideOneMethod) xbf.getBean("overrideOneMethodByElement");
|
||||||
|
assertEquals("should not replace", "replaceMe:1", oom.replaceMe(1));
|
||||||
|
assertEquals("should replace", "cba", oom.replaceMe("abc"));
|
||||||
|
}
|
||||||
|
|
||||||
public static class DoSomethingReplacer implements MethodReplacer {
|
public static class DoSomethingReplacer implements MethodReplacer {
|
||||||
|
|
||||||
public Object lastArg;
|
public Object lastArg;
|
||||||
|
|
Loading…
Reference in New Issue