Skip to content

Commit 9aac595

Browse files
committed
feat: XmlBeanDefinitionBuilder setPropertyReferenceIfAttributeDefined()
1 parent fd3f9b7 commit 9aac595

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

int-aws-support/src/main/java/org/springframework/integration/aws/config/xml/XmlBeanDefinitionBuilder.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.function.Consumer;
1111

1212
import static org.springframework.core.Conventions.attributeNameToPropertyName;
13+
import static org.springframework.integration.config.xml.IntegrationNamespaceUtils.setReferenceIfAttributeDefined;
1314
import static org.springframework.integration.config.xml.IntegrationNamespaceUtils.setValueIfAttributeDefined;
1415

1516
public class XmlBeanDefinitionBuilder {
@@ -49,23 +50,33 @@ public XmlBeanDefinitionBuilder addConstructorArgValue(String attributeName) {
4950
return this;
5051
}
5152

52-
public XmlBeanDefinitionBuilder setPropertyValue(String attributeName) {
53-
builder.addPropertyValue(attributeNameToPropertyName(attributeName), new TypedStringValue(element.getAttribute(attributeName)));
53+
public XmlBeanDefinitionBuilder setPropertyReference(String attributeName) {
54+
builder.addPropertyReference(attributeNameToPropertyName(attributeName), element.getAttribute(attributeName));
5455
return this;
5556
}
5657

57-
public XmlBeanDefinitionBuilder setPropertyValue(String propertyName, String attributeName) {
58-
builder.addPropertyValue(propertyName, new TypedStringValue(element.getAttribute(attributeName)));
58+
public XmlBeanDefinitionBuilder setPropertyReference(String propertyName, String attributeName) {
59+
builder.addPropertyReference(propertyName, element.getAttribute(attributeName));
5960
return this;
6061
}
6162

62-
public XmlBeanDefinitionBuilder setPropertyReference(String attributeName) {
63-
builder.addPropertyReference(attributeNameToPropertyName(attributeName), element.getAttribute(attributeName));
63+
public XmlBeanDefinitionBuilder setPropertyReferenceIfAttributeDefined(String attributeName) {
64+
setReferenceIfAttributeDefined(builder, element, attributeName);
6465
return this;
6566
}
6667

67-
public XmlBeanDefinitionBuilder setPropertyReference(String propertyName, String attributeName) {
68-
builder.addPropertyReference(propertyName, element.getAttribute(attributeName));
68+
public XmlBeanDefinitionBuilder setPropertyReferenceIfAttributeDefined(String propertyName, String attributeName) {
69+
setReferenceIfAttributeDefined(builder, element, attributeName, propertyName);
70+
return this;
71+
}
72+
73+
public XmlBeanDefinitionBuilder setPropertyValue(String attributeName) {
74+
builder.addPropertyValue(attributeNameToPropertyName(attributeName), new TypedStringValue(element.getAttribute(attributeName)));
75+
return this;
76+
}
77+
78+
public XmlBeanDefinitionBuilder setPropertyValue(String propertyName, String attributeName) {
79+
builder.addPropertyValue(propertyName, new TypedStringValue(element.getAttribute(attributeName)));
6980
return this;
7081
}
7182

int-aws-support/src/test/java/org/springframework/integration/aws/config/xml/XmlBeanDefinitionBuilderTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ void testProperties() {
4545
var def = builder
4646
.addConstructorArgValue("value-property")
4747
.addConstructorArgReference("ref-property")
48-
.setPropertyValue("value-property")
49-
.setPropertyValue("property", "value-property")
5048
.setPropertyReference("ref-property")
5149
.setPropertyReference("ref", "ref-property")
50+
.setPropertyReferenceIfAttributeDefined("undefinedRef")
51+
.setPropertyReferenceIfAttributeDefined("definedRef", "ref-property")
52+
.setPropertyReferenceIfAttributeDefined("undefinedRef", "undefined-ref")
53+
.setPropertyValue("value-property")
54+
.setPropertyValue("property", "value-property")
5255
.setPropertyValueIfAttributeDefined("defined-property")
5356
.setPropertyValueIfAttributeDefined("undefined-property")
5457
.setPropertyValueIfAttributeDefined("expected", "defined-property")
@@ -63,10 +66,11 @@ void testProperties() {
6366

6467
assertThat(def.getPropertyValues())
6568
.containsOnly(
66-
new PropertyValue("valueProperty", new TypedStringValue("value")),
67-
new PropertyValue("property", new TypedStringValue("value")),
6869
new PropertyValue("refProperty", new RuntimeBeanReference("bean")),
6970
new PropertyValue("ref", new RuntimeBeanReference("bean")),
71+
new PropertyValue("definedRef", new RuntimeBeanReference("bean")),
72+
new PropertyValue("valueProperty", new TypedStringValue("value")),
73+
new PropertyValue("property", new TypedStringValue("value")),
7074
new PropertyValue("definedProperty", new TypedStringValue("test")),
7175
new PropertyValue("expected", new TypedStringValue("test"))
7276
);

0 commit comments

Comments
 (0)