SWF-444 - Allow a an expected type to be supplied on the <method-result> tag and type conversion applied if necessary
This commit is contained in:
@@ -147,6 +147,8 @@ public class XmlFlowBuilder extends AbstractFlowBuilder implements ResourceHolde
|
||||
|
||||
private static final String METHOD_RESULT_ELEMENT = "method-result";
|
||||
|
||||
private static final String RESULT_TYPE_ATTRIBUTE = "result-type";
|
||||
|
||||
private static final String EVALUATE_ACTION_ELEMENT = "evaluate-action";
|
||||
|
||||
private static final String SET_ELEMENT = "set";
|
||||
@@ -754,7 +756,8 @@ public class XmlFlowBuilder extends AbstractFlowBuilder implements ResourceHolde
|
||||
String beanId = element.getAttribute(BEAN_ATTRIBUTE);
|
||||
String methodName = element.getAttribute(METHOD_ATTRIBUTE);
|
||||
Parameters parameters = parseMethodParameters(element);
|
||||
MethodSignature methodSignature = new MethodSignature(methodName, parameters);
|
||||
Class desiredResultType = parseMethodResultType(element);
|
||||
MethodSignature methodSignature = new MethodSignature(methodName, parameters, desiredResultType);
|
||||
ActionResultExposer resultExposer = parseMethodResultExposer(element);
|
||||
return getLocalContext().getBeanInvokingActionFactory().createBeanInvokingAction(beanId,
|
||||
getLocalContext().getBeanFactory(), methodSignature, resultExposer,
|
||||
@@ -783,6 +786,17 @@ public class XmlFlowBuilder extends AbstractFlowBuilder implements ResourceHolde
|
||||
return parameters;
|
||||
}
|
||||
|
||||
private Class parseMethodResultType(Element element) {
|
||||
Element resultElement = DomUtils.getChildElementByTagName(element, METHOD_RESULT_ELEMENT);
|
||||
Class type = null;
|
||||
if (resultElement != null) {
|
||||
if (resultElement.hasAttribute(RESULT_TYPE_ATTRIBUTE)) {
|
||||
type = (Class) fromStringTo(Class.class).execute(resultElement.getAttribute(RESULT_TYPE_ATTRIBUTE));
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
private ActionResultExposer parseMethodResultExposer(Element element) {
|
||||
Element resultElement = DomUtils.getChildElementByTagName(element, METHOD_RESULT_ELEMENT);
|
||||
if (resultElement != null) {
|
||||
|
||||
@@ -1012,8 +1012,8 @@ parameter type, a type conversion will be attempted.
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
<![CDATA[
|
||||
The name of the attribute that will expose the return value of the target bean-action method.
|
||||
Used in conjunction with the 'scope' attribute.
|
||||
An expression used to expose the return value of the target bean-action method, such as "#{flowScope.myResult}".
|
||||
Can be a simple literal when used in conjunction with the 'scope' attribute.
|
||||
]]>
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
@@ -1035,6 +1035,16 @@ If not specified the default scope type is used ('request' by default).
|
||||
]]>
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="result-type" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
<![CDATA[
|
||||
The desired method result type. Optional. If specified and the method return value is not of the
|
||||
desired result type, a type conversion will be attempted.
|
||||
]]>
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
Reference in New Issue
Block a user