summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/core-databinding/src/main/java
diff options
context:
space:
mode:
authorbdaniel <bdaniel@13f79535-47bb-0310-9956-ffa450edef68>2010-11-14 22:32:24 +0000
committerbdaniel <bdaniel@13f79535-47bb-0310-9956-ffa450edef68>2010-11-14 22:32:24 +0000
commitebc9f8e8938b56b0564ca447fef38ba42db689dd (patch)
tree91f7ad5ea13a1a5e1b4776e31d1f9c845addbab0 /sca-java-2.x/trunk/modules/core-databinding/src/main/java
parent5670f96c39fb938bfc6951dcb87d623a2d03bf8d (diff)
TUSCANY-3664 Add support for multiple operation output types
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1035090 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/core-databinding/src/main/java')
-rw-r--r--sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java18
-rw-r--r--sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java67
-rw-r--r--sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java17
-rw-r--r--sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java23
4 files changed, 86 insertions, 39 deletions
diff --git a/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java b/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java
index 23f133b0a2..0ab01fbe0b 100644
--- a/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java
+++ b/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java
@@ -104,16 +104,22 @@ public class DataBindingJavaInterfaceProcessor implements JavaInterfaceVisitor {
i++;
}
if (operation.getOutputType() != null) {
- DataType<?> d = operation.getOutputType();
- if (d.getDataBinding() == null) {
- d.setDataBinding(dataBindingId);
- }
+ for ( org.apache.tuscany.sca.interfacedef.DataType<?> d : operation.getOutputType().getLogical()) {
+ if ( d != null ) {
+ // The DataType is null for void operations
+ if ( d.getDataBinding() == null ) {
+ d.setDataBinding(dataBindingId);
+ }
+ dataBindingRegistry.introspectType(d, operation);
+ }
+ }
+
org.apache.tuscany.sca.databinding.annotation.DataType dt =
method.getAnnotation(org.apache.tuscany.sca.databinding.annotation.DataType.class);
if (dt != null) {
- d.setDataBinding(dt.value());
+ operation.getOutputType().getLogical().get(0).setDataBinding(dt.value());
}
- dataBindingRegistry.introspectType(d, operation);
+
}
}
}
diff --git a/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java b/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java
index 71dcc654eb..d02a98bfbe 100644
--- a/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java
+++ b/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java
@@ -18,17 +18,18 @@
*/
package org.apache.tuscany.sca.core.databinding.transformers;
+import java.util.ArrayList;
import java.util.List;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.databinding.BaseTransformer;
import org.apache.tuscany.sca.databinding.DataBinding;
import org.apache.tuscany.sca.databinding.Mediator;
import org.apache.tuscany.sca.databinding.PullTransformer;
import org.apache.tuscany.sca.databinding.TransformationContext;
import org.apache.tuscany.sca.databinding.TransformationException;
import org.apache.tuscany.sca.databinding.WrapperHandler;
-import org.apache.tuscany.sca.databinding.BaseTransformer;
import org.apache.tuscany.sca.interfacedef.DataType;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.interfacedef.util.ElementInfo;
@@ -189,8 +190,9 @@ public class Output2OutputTransformer extends BaseTransformer<Object, Object> im
sourceOp,
false);
}
+ DataType<List<DataType>> targetLogicalType = targetType.getLogical();
Object targetWrapper =
- mediator.mediate(sourceWrapper, sourceWrapperType, targetType.getLogical(), context
+ mediator.mediate(sourceWrapper, sourceWrapperType, targetLogicalType.getLogical().get(0), context
.getMetadata());
return targetWrapper;
}
@@ -204,10 +206,25 @@ public class Output2OutputTransformer extends BaseTransformer<Object, Object> im
}
DataType<XMLType> argType = wrapper.getUnwrappedOutputType();
- Object child = response;
- child = mediator.mediate(response, sourceType.getLogical(), argType, context.getMetadata());
- targetWrapperHandler.setChildren(targetWrapper, new Object[] {child}, targetOp, false);
- return targetWrapper;
+
+ if ( !sourceOp.hasHolders() ) {
+ Object child = response;
+ DataType<List<DataType>> sourceLogicalType = sourceType.getLogical();
+ child = mediator.mediate(response, sourceLogicalType.getLogical().get(0), argType, context.getMetadata());
+ targetWrapperHandler.setChildren(targetWrapper, new Object[] {child}, targetOp, false);
+ return targetWrapper;
+ } else {
+ Object[] child = (Object[])response;
+ ArrayList<Object> children = new ArrayList<Object>();
+ for ( int i=0; i < child.length; i++) {
+ DataType<List<DataType>> sourceLogicalType = sourceType.getLogical();
+ DataType childType = sourceLogicalType.getLogical().get(i);
+ if ( childType != null )
+ children.add(mediator.mediate(child[i], childType, argType, context.getMetadata()));
+ }
+ targetWrapperHandler.setChildren(targetWrapper, children.toArray(), targetOp, false);
+ return targetWrapper;
+ }
} else if (sourceWrapped && (!targetWrapped && !targetBare)) {
// Wrapped to Unwrapped
Object sourceWrapper = response;
@@ -228,19 +245,47 @@ public class Output2OutputTransformer extends BaseTransformer<Object, Object> im
targetWrapperInfo != null ? targetWrapperInfo.getOutputWrapperType() : null;
if (targetWrapperType != null && matches(sourceOp.getWrapper(), targetOp.getWrapper())) {
+ DataType<List<DataType>> sourceLogicalType = sourceType.getLogical();
Object targetWrapper =
- mediator.mediate(sourceWrapper, sourceType.getLogical(), targetWrapperType, context
+ mediator.mediate(sourceWrapper, sourceLogicalType.getLogical().get(0), targetWrapperType, context
.getMetadata());
return targetWrapperHandler.getChildren(targetWrapper, targetOp, false).get(0);
}
}
}
- Object child = sourceWrapperHandler.getChildren(sourceWrapper, sourceOp, false).get(0);
- DataType<?> childType = sourceOp.getWrapper().getUnwrappedOutputType();
- return mediator.mediate(child, childType, targetType.getLogical(), context.getMetadata());
+ if ( !targetOp.hasHolders()) {
+ Object child = sourceWrapperHandler.getChildren(sourceWrapper, sourceOp, false).get(0);
+ DataType<?> childType = sourceOp.getWrapper().getUnwrappedOutputType();
+ DataType<List<DataType>> foo = targetType.getLogical();
+ return mediator.mediate(child, childType, foo.getLogical().get(0), context.getMetadata());
+ } else {
+ Object[] child = sourceWrapperHandler.getChildren(sourceWrapper, sourceOp, false).toArray();
+ DataType<?> childType = sourceOp.getWrapper().getUnwrappedOutputType();
+ DataType<List<DataType>> targetLogicalType = targetType.getLogical();
+
+ Object[] target = child;
+ if ( targetLogicalType.getLogical().get(0) == null ) {
+ target = new Object[child.length +1];
+ target[0] = null;
+ for ( int i=1; i <= child.length; i++ ) {
+// if ( targetLogicalType.getLogical().get(i).getDataBinding() == null )
+// targetLogicalType.getLogical().get(i).setDataBinding(targetDataBinding);
+ target[i] = mediator.mediate(child[i-1], childType, targetLogicalType.getLogical().get(i), context.getMetadata());
+ }
+ } else {
+ for ( int i=0; i < child.length; i++) {
+// if ( targetLogicalType.getLogical().get(i).getDataBinding() == null )
+// targetLogicalType.getLogical().get(i).setDataBinding(targetDataBinding);
+ target[i] = mediator.mediate(child[i], childType, targetLogicalType.getLogical().get(i) , context.getMetadata());
+ }
+ }
+ return target;
+ }
} else {
// FIXME: Do we want to handle wrapped to wrapped?
- return mediator.mediate(response, sourceType.getLogical(), targetType.getLogical(), context
+ DataType<List<DataType>> sourceLogical = sourceType.getLogical();
+ DataType<List<DataType>> targetLogical = targetType.getLogical();
+ return mediator.mediate(response, sourceLogical.getLogical().get(0), targetLogical.getLogical().get(0), context
.getMetadata());
}
} catch (Exception e) {
diff --git a/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java b/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java
index 0e615519f1..bdb4d6fa08 100644
--- a/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java
+++ b/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java
@@ -84,14 +84,19 @@ public class DataBindingRuntimeWireProcessor implements RuntimeWireProcessor {
}
// Check output type
- DataType sourceOutputType = source.getOutputType();
- DataType targetOutputType = target.getOutputType();
+ List<DataType> sourceOutputType = source.getOutputType().getLogical();
+ List<DataType> targetOutputType = target.getOutputType().getLogical();
- // Note the target output type is now the source for checking
- // compatibility
- if (isTransformationRequired(targetOutputType, sourceOutputType)) {
- return true;
+ int outputSize = sourceOutputType.size();
+ if ( outputSize != targetOutputType.size() ) {
+ return true;
}
+
+ for (int i = 0; i < outputSize; i++) {
+ if (isTransformationRequired(sourceOutputType.get(i), targetOutputType.get(i))) {
+ return true;
+ }
+ }
List<DataType> sourceInputType = source.getInputType().getLogical();
List<DataType> targetInputType = target.getInputType().getLogical();
diff --git a/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java b/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java
index 7bf9833d04..3b4891af9d 100644
--- a/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java
+++ b/sca-java-2.x/trunk/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java
@@ -21,6 +21,7 @@ package org.apache.tuscany.sca.core.databinding.wire;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -59,17 +60,7 @@ public class DataTransformationInterceptor implements Interceptor {
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.invocable = invocable;
}
@@ -121,21 +112,21 @@ public class DataTransformationInterceptor implements Interceptor {
* 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 ) {
+ protected List<DataType<DataType>> getHolderTypes( DataType<List<DataType>> inputTypes ) {
+ ArrayList<DataType<DataType>> returnTypes = new ArrayList<DataType<DataType>>();
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;
+ returnTypes.add(dataType);
}
}
}
}
- return null;
+ return returnTypes;
}
protected static boolean isHolder( Type type ) {