SWF-466 - Add a "type" attribute to "evaluation-result" to support type conversion of the action result.

This commit is contained in:
Jeremy Grelle
2008-02-05 17:53:30 +00:00
parent 763d5addeb
commit ab526797c9
9 changed files with 117 additions and 48 deletions

View File

@@ -91,7 +91,7 @@ public class MethodInvoker {
+ StylerUtils.style(arguments) + " on bean [" + bean + "]");
}
Object returnValue = applyTypeConversion(method.invoke(bean, arguments), signature.getDesiredResultType());
Object returnValue = method.invoke(bean, arguments);
if (logger.isDebugEnabled()) {
logger.debug("Invoked method with signature [" + key + "] returned value [" + returnValue + "]");
}

View File

@@ -38,17 +38,12 @@ public class MethodSignature {
*/
private Parameters parameters;
/**
* The desired result type of the method invocation
*/
private Class desiredResultType;
/**
* Creates a method signature with no parameters.
* @param methodName the name of the method
*/
public MethodSignature(String methodName) {
this(methodName, Parameters.NONE, null);
this(methodName, Parameters.NONE);
}
/**
@@ -57,21 +52,19 @@ public class MethodSignature {
* @param parameter the method parameter
*/
public MethodSignature(String methodName, Parameter parameter) {
this(methodName, new Parameters(parameter), null);
this(methodName, new Parameters(parameter));
}
/**
* Creates a method signature with a list of parameters.
* @param methodName the name of the method
* @param parameters the method parameters
* @param desiredResultType the desired result type of the method invocation
*/
public MethodSignature(String methodName, Parameters parameters, Class desiredResultType) {
public MethodSignature(String methodName, Parameters parameters) {
Assert.notNull(methodName, "The method name is required");
Assert.notNull(parameters, "The parameters are required");
this.methodName = methodName;
this.parameters = parameters;
this.desiredResultType = desiredResultType;
}
/**
@@ -88,14 +81,6 @@ public class MethodSignature {
return parameters;
}
/**
* Returns the desired result type of the method invocation
* @return the desired result type
*/
public Class getDesiredResultType() {
return desiredResultType;
}
public boolean equals(Object obj) {
if (!(obj instanceof MethodSignature)) {
return false;

View File

@@ -56,23 +56,17 @@ public class MethodInvokerTests extends TestCase {
Parameters parameters = new Parameters();
Bean bean = new Bean();
parameters.add(new Parameter(Bean.class, new StaticExpression(bean)));
MethodSignature method = new MethodSignature("testBeanArg", parameters, null);
MethodSignature method = new MethodSignature("testBeanArg", parameters);
assertSame(bean, methodInvoker.invoke(method, new TestObject(), null));
}
public void testPrimitiveArg() {
Parameters parameters = new Parameters();
parameters.add(new Parameter(Boolean.class, new StaticExpression(Boolean.TRUE)));
MethodSignature method = new MethodSignature("testPrimitiveArg", parameters, null);
MethodSignature method = new MethodSignature("testPrimitiveArg", parameters);
assertEquals(Boolean.TRUE, methodInvoker.invoke(method, new TestObject(), null));
}
public void testResultConversion() {
Parameters parameters = Parameters.NONE;
MethodSignature method = new MethodSignature("testConvertResult", parameters, Class.class);
assertEquals(Object.class, methodInvoker.invoke(method, new TestObject(), null));
}
private static class TestObject {
public void test() {
@@ -83,10 +77,6 @@ public class MethodInvokerTests extends TestCase {
return bean;
}
public String testConvertResult() {
return "java.lang.Object";
}
public boolean testPrimitiveArg(boolean primitive) {
return primitive;
}