@@ -53,24 +53,11 @@ public XmlBeanDefinitionBuilder addConstructorArgValue(String attributeName) {
5353 }
5454
5555 public XmlBeanDefinitionBuilder addExclusiveConstructorArgReference (String attribute1 , String attribute2 ) {
56- return addExclusiveConstructorArg (attribute1 , attribute2 , BeanDefinitionBuilder ::addConstructorArgReference , BeanDefinitionBuilder ::addConstructorArgReference );
56+ return setExclusiveAttribute (attribute1 , attribute2 , BeanDefinitionBuilder ::addConstructorArgReference , BeanDefinitionBuilder ::addConstructorArgReference );
5757 }
5858
5959 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 ) {
64- var value1 = element .getAttribute (attribute1 );
65- var value2 = element .getAttribute (attribute2 );
66- if (StringUtils .hasText (value1 ) == StringUtils .hasText (value2 )) {
67- error (attribute1 + " or " + attribute2 + " required and mutually exclusive" );
68- } else if (StringUtils .hasText (value1 )) {
69- arg1 .accept (builder , value1 );
70- } else {
71- arg2 .accept (builder , value2 );
72- }
73- return this ;
60+ return setExclusiveAttribute (attribute1 , attribute2 , (b , v ) -> b .addConstructorArgValue (arg1 .apply (v )), (b , v ) -> b .addConstructorArgValue (arg2 .apply (v )));
7461 }
7562
7663 public XmlBeanDefinitionBuilder setPropertyReference (String attributeName ) {
@@ -121,6 +108,18 @@ public XmlBeanDefinitionBuilder setPropertyValueIfAttributeDefined(String proper
121108 return this ;
122109 }
123110
111+ public XmlBeanDefinitionBuilder setExpressionPropertyIfAttributeDefined (String attribute ) {
112+ return setExpressionPropertyIfAttributeDefined (attribute , attribute + "-expression" );
113+ }
114+
115+ public XmlBeanDefinitionBuilder setExpressionPropertyIfAttributeDefined (String attribute , String expressionAttribute ) {
116+ return setExpressionPropertyIfAttributeDefined (attribute , expressionAttribute , attributeNameToPropertyName (attribute ), attributeNameToPropertyName (expressionAttribute ));
117+ }
118+
119+ public XmlBeanDefinitionBuilder setExpressionPropertyIfAttributeDefined (String attribute , String expressionAttribute , String property , String expressionProperty ) {
120+ return setIfExclusiveAttributeDefined (attribute , expressionAttribute , (b , v ) -> b .addPropertyValue (property , v ), (b , v ) -> b .addPropertyValue (expressionProperty , new ExpressionBeanDefinitionFactory ().createBeanDefinition (v )));
121+ }
122+
124123 public XmlBeanDefinitionBuilder setExpressionValueIfAttributeDefined (String attribute ) {
125124 return setPropertyValueIfExclusiveAttributeDefined (attribute , attribute + "-expression" , attributeNameToPropertyName (attribute ), attributeNameToPropertyName (attribute + "-expression-string" ));
126125 }
@@ -130,11 +129,31 @@ public XmlBeanDefinitionBuilder setPropertyValueIfExclusiveAttributeDefined(Stri
130129 }
131130
132131 public XmlBeanDefinitionBuilder setPropertyValueIfExclusiveAttributeDefined (String attribute1 , String attribute2 , String property1 , String property2 ) {
133- if (StringUtils .hasText (element .getAttribute (attribute1 )) && StringUtils .hasText (element .getAttribute (attribute2 ))) {
132+ return setIfExclusiveAttributeDefined (attribute1 , attribute2 , (b , v ) -> b .addPropertyValue (property1 , v ), (b , v ) -> b .addPropertyValue (property2 , v ));
133+ }
134+
135+ public XmlBeanDefinitionBuilder setExclusiveAttribute (String attribute1 , String attribute2 , BiConsumer <BeanDefinitionBuilder , String > arg1 , BiConsumer <BeanDefinitionBuilder , String > arg2 ) {
136+ var value1 = element .getAttribute (attribute1 );
137+ var value2 = element .getAttribute (attribute2 );
138+ if (StringUtils .hasText (value1 ) == StringUtils .hasText (value2 )) {
139+ error (attribute1 + " or " + attribute2 + " required and mutually exclusive" );
140+ } else if (StringUtils .hasText (value1 )) {
141+ arg1 .accept (builder , value1 );
142+ } else {
143+ arg2 .accept (builder , value2 );
144+ }
145+ return this ;
146+ }
147+
148+ public XmlBeanDefinitionBuilder setIfExclusiveAttributeDefined (String attribute1 , String attribute2 , BiConsumer <BeanDefinitionBuilder , String > arg1 , BiConsumer <BeanDefinitionBuilder , String > arg2 ) {
149+ var value1 = element .getAttribute (attribute1 );
150+ var value2 = element .getAttribute (attribute2 );
151+ if (StringUtils .hasText (value1 ) && StringUtils .hasText (value2 )) {
134152 error (attribute1 + " and " + attribute2 + " attributes are mutually exclusive" );
153+ } if (StringUtils .hasText (value1 )) {
154+ arg1 .accept (builder , value1 );
135155 } else {
136- setValueIfAttributeDefined (builder , element , attribute1 , property1 );
137- setValueIfAttributeDefined (builder , element , attribute2 , property2 );
156+ arg2 .accept (builder , value2 );
138157 }
139158 return this ;
140159 }
0 commit comments