summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java
diff options
context:
space:
mode:
authorbeckerdo <beckerdo@13f79535-47bb-0310-9956-ffa450edef68>2009-01-11 22:14:15 +0000
committerbeckerdo <beckerdo@13f79535-47bb-0310-9956-ffa450edef68>2009-01-11 22:14:15 +0000
commit06411d4f4afcb69eafa24cadad267eb6681ddaa2 (patch)
tree11847614377caa655975d65becf85a2f79eb4fa6 /branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java
parent77e0d936ff50694b2c450ab74a4490f2462bc93f (diff)
TUSCANY-2332 Web services Holder support
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@733526 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java')
-rw-r--r--branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java52
1 files changed, 51 insertions, 1 deletions
diff --git a/branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java b/branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java
index 5814f3d215..ee26d61c42 100644
--- a/branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java
+++ b/branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java
@@ -20,7 +20,10 @@
package org.apache.tuscany.sca.core.databinding.wire;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
@@ -31,6 +34,7 @@ import org.apache.tuscany.sca.interfacedef.DataType;
import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
import org.apache.tuscany.sca.interfacedef.util.FaultException;
import org.apache.tuscany.sca.interfacedef.util.XMLType;
import org.apache.tuscany.sca.invocation.DataExchangeSemantics;
@@ -63,6 +67,21 @@ public class DataTransformationInterceptor implements Interceptor, DataExchangeS
super();
this.sourceOperation = sourceOperation;
this.targetOperation = targetOperation;
+ if ( sourceOperation instanceof JavaOperation ) {
+ JavaOperation javaOp = (JavaOperation) sourceOperation;
+ Method sourceMethod = javaOp.getJavaMethod();
+ }
+ // Holder pattern. In order to perform data mediation on Holder return types, it is
+ // necessary to set up a data transformation on the Holder<T> class T. on return.
+ DataType<DataType> returnTargetType = getFirstHolderType( sourceOperation.getInputType() );
+ if ( returnTargetType != null ) {
+ this.sourceOperation.setOutputType(returnTargetType);
+ }
+ returnTargetType = getFirstHolderType( targetOperation.getInputType() );
+ if ( returnTargetType != null ) {
+ this.targetOperation.setOutputType(returnTargetType);
+ }
+
this.mediator = mediator;
this.wire = wire;
this.faultExceptionMapper = faultExceptionMapper;
@@ -73,15 +92,17 @@ public class DataTransformationInterceptor implements Interceptor, DataExchangeS
}
public Message invoke(Message msg) {
+ // System.out.println( "DataTransformationInterceptor.invoke source input type=" + sourceOperation.getInputType() );
+ // System.out.println( "DataTransformationInterceptor.invoke target input type =" + targetOperation.getInputType() );
Object input = transform(msg.getBody(), sourceOperation.getInputType(), targetOperation.getInputType(), false);
msg.setBody(input);
Message resultMsg = next.invoke(msg);
- Object result = resultMsg.getBody();
if (sourceOperation.isNonBlocking()) {
// Not to reset the message body
return resultMsg;
}
+ Object result = resultMsg.getBody();
// FIXME: Should we fix the Operation model so that getOutputType
// returns DataType<DataType<T>>?
DataType<DataType> targetType =
@@ -164,6 +185,7 @@ public class DataTransformationInterceptor implements Interceptor, DataExchangeS
}
} else {
+ // !resultMsg.isFault()
assert !(result instanceof Throwable) : "Expected messages that are not throwable " + result;
Object newResult = transform(result, targetType, sourceType, true);
@@ -261,4 +283,32 @@ public class DataTransformationInterceptor implements Interceptor, DataExchangeS
return true;
}
+ /**
+ * Returns return type for first Holder in input list.
+ * Returns null if the inputs do not contain a Holder.
+ */
+ protected static DataType<DataType> getFirstHolderType( DataType<List<DataType>> inputTypes ) {
+ if (inputTypes != null) {
+ List<DataType> logicalType = inputTypes.getLogical();
+ if (logicalType != null) {
+ for (int i = 0; i < logicalType.size(); i++) {
+ DataType dataType = logicalType.get(i);
+ if (isHolder(dataType.getGenericType())) {
+ // Fix up output from void to returned data type.
+ // System.out.println("DataTransformationInterceptor.<> source input[" + i + "] is Holder, logicalType=" + dataType);
+ return dataType;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ protected static boolean isHolder( Type type ) {
+ String typeString = type.toString();
+ if ( typeString.startsWith( "javax.xml.ws.Holder" ) ) {
+ return true;
+ }
+ return false;
+ }
}