|
7 | 7 | import org.springframework.util.StringUtils; |
8 | 8 | import org.w3c.dom.Element; |
9 | 9 |
|
| 10 | +import java.util.function.BiConsumer; |
10 | 11 | import java.util.function.Consumer; |
| 12 | +import java.util.function.Function; |
11 | 13 |
|
12 | 14 | import static org.springframework.core.Conventions.attributeNameToPropertyName; |
13 | 15 | import static org.springframework.integration.config.xml.IntegrationNamespaceUtils.setReferenceIfAttributeDefined; |
@@ -45,29 +47,28 @@ public XmlBeanDefinitionBuilder addConstructorArgReference(String attributeName) |
45 | 47 | return this; |
46 | 48 | } |
47 | 49 |
|
48 | | - public XmlBeanDefinitionBuilder addExclusiveConstructorArgReference(String attribute1, String attribute2) { |
49 | | - var value1 = element.getAttribute(attribute1); |
50 | | - var value2 = element.getAttribute(attribute2); |
51 | | - if (StringUtils.hasText(value1) == StringUtils.hasText(value2)) { |
52 | | - error(attribute1 + " or " + attribute2 + " required and mutually exclusive"); |
53 | | - } else { |
54 | | - builder.addConstructorArgReference(StringUtils.hasText(value1) ? value1 : value2); |
55 | | - } |
56 | | - return this; |
57 | | - } |
58 | | - |
59 | 50 | public XmlBeanDefinitionBuilder addConstructorArgValue(String attributeName) { |
60 | 51 | builder.addConstructorArgValue(new TypedStringValue(element.getAttribute(attributeName))); |
61 | 52 | return this; |
62 | 53 | } |
63 | 54 |
|
64 | | - public XmlBeanDefinitionBuilder addExclusiveConstructorArgValue(String attribute1, String attribute2, Class<?> type1, Class<?> type2) { |
| 55 | + public XmlBeanDefinitionBuilder addExclusiveConstructorArgReference(String attribute1, String attribute2) { |
| 56 | + return addExclusiveConstructorArg(attribute1, attribute2, BeanDefinitionBuilder::addConstructorArgReference, BeanDefinitionBuilder::addConstructorArgReference); |
| 57 | + } |
| 58 | + |
| 59 | + public XmlBeanDefinitionBuilder addExclusiveConstructorArgValue(String attribute1, String attribute2, Function<String, ?> arg1, Function<String, ?> arg2) { |
| 60 | + return addExclusiveConstructorArg(attribute1, attribute2, (b, v) -> b.addConstructorArgValue(arg1.apply(v)), (b, v) -> b.addConstructorArgValue(arg2.apply(v))); |
| 61 | + } |
| 62 | + |
| 63 | + public XmlBeanDefinitionBuilder addExclusiveConstructorArg(String attribute1, String attribute2, BiConsumer<BeanDefinitionBuilder, String> arg1, BiConsumer<BeanDefinitionBuilder, String> arg2) { |
65 | 64 | var value1 = element.getAttribute(attribute1); |
66 | 65 | var value2 = element.getAttribute(attribute2); |
67 | 66 | if (StringUtils.hasText(value1) == StringUtils.hasText(value2)) { |
68 | 67 | error(attribute1 + " or " + attribute2 + " required and mutually exclusive"); |
| 68 | + } else if (StringUtils.hasText(value1)) { |
| 69 | + arg1.accept(builder, value1); |
69 | 70 | } else { |
70 | | - builder.addConstructorArgValue(StringUtils.hasText(value1) ? new TypedStringValue(value1, type1) : new TypedStringValue(value2, type2)); |
| 71 | + arg2.accept(builder, value2); |
71 | 72 | } |
72 | 73 | return this; |
73 | 74 | } |
|
0 commit comments