From ebc9f8e8938b56b0564ca447fef38ba42db689dd Mon Sep 17 00:00:00 2001 From: bdaniel Date: Sun, 14 Nov 2010 22:32:24 +0000 Subject: 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 --- .../tuscany/sca/databinding/impl/MediatorImpl.java | 52 ++++++++++++++++++---- 1 file changed, 43 insertions(+), 9 deletions(-) (limited to 'sca-java-2.x/trunk/modules/databinding/src') diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java index 5227b95432..5137338f4d 100644 --- a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java +++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java @@ -386,14 +386,10 @@ public class MediatorImpl implements Mediator { Operation sourceOperation, Operation targetOperation, Map metadata) { - // Create a data type to represent the ouput produced by the target operation - DataType targetType = - new DataTypeImpl(IDL_OUTPUT, Object.class, targetOperation.getOutputType()); - - // Create a data type to represent the ouput expected by the source operation - DataType sourceType = - new DataTypeImpl(IDL_OUTPUT, Object.class, sourceOperation.getOutputType()); - + + DataType sourceType = new DataTypeImpl(IDL_OUTPUT, Object.class, sourceOperation.getOutputType()); + DataType targetType = new DataTypeImpl(IDL_OUTPUT, Object.class, targetOperation.getOutputType()); + if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) { return output; } @@ -579,7 +575,45 @@ public class MediatorImpl implements Mediator { } public Object copyOutput(Object data, Operation sourceOperation, Operation targetOperation) { - return copy(data, targetOperation.getOutputType(), sourceOperation.getOutputType(), targetOperation, sourceOperation); + if ( data == null ) + return null; + Object[] output = null; + + if ( !sourceOperation.hasHolders() ) { + output = new Object[] {data}; + } else { + output = (Object[])data; + } + + List outputTypes = sourceOperation.getOutputType().getLogical(); + List outputTypesTarget = targetOperation == null ? null : targetOperation.getOutputType().getLogical(); + Object[] copy = new Object[output.length]; + Map map = new IdentityHashMap(); + for (int i = 0, size = output.length; i < size; i++) { + Object arg = output[i]; + if (arg == null) { + copy[i] = null; + } else { + Object copiedArg = map.get(arg); + if (copiedArg != null) { + copy[i] = copiedArg; + } else { + copiedArg = + copy(arg, + outputTypes.get(i), + outputTypesTarget == null ? null : outputTypesTarget.get(i), + sourceOperation, + targetOperation); + map.put(arg, copiedArg); + copy[i] = copiedArg; + } + } + } + if ( !targetOperation.hasHolders()) { + return copy[0]; + } else { + return copy; + } } public Object copyFault(Object fault, Operation operation) { -- cgit v1.2.3