diff options
author | bdaniel <bdaniel@13f79535-47bb-0310-9956-ffa450edef68> | 2010-11-14 22:32:24 +0000 |
---|---|---|
committer | bdaniel <bdaniel@13f79535-47bb-0310-9956-ffa450edef68> | 2010-11-14 22:32:24 +0000 |
commit | ebc9f8e8938b56b0564ca447fef38ba42db689dd (patch) | |
tree | 91f7ad5ea13a1a5e1b4776e31d1f9c845addbab0 /sca-java-2.x/trunk/modules | |
parent | 5670f96c39fb938bfc6951dcb87d623a2d03bf8d (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')
7 files changed, 140 insertions, 55 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java b/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java index a072b31322..dc1b7e024b 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java +++ b/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java @@ -240,7 +240,7 @@ public class Interface2WSDLGenerator { if (useOutputWrapper) { addDataType(dataTypes, dt2, helpers); } else { - dt2 = op.getOutputType(); + dt2 = op.getOutputType().getLogical().get(0); addDataType(dataTypes, dt2, helpers); } @@ -645,8 +645,9 @@ public class Interface2WSDLGenerator { if (op.getWrapper() != null) { outputMsg.addPart(generateWrapperPart(definition, op, helpers, wrappers, false)); } else { - DataType outputType = op.getOutputType(); - if (outputType != null) { + + if ((op.getOutputType() != null) && ( op.getOutputType().getLogical().get(0) != null)) { + DataType outputType = op.getOutputType().getLogical().get(0); outputMsg.addPart(generatePart(definition, outputType, "return")); elements = new ArrayList<ElementInfo>(); ElementInfo element = getElementInfo(outputType.getPhysical(), outputType, null, helpers); @@ -754,7 +755,7 @@ public class Interface2WSDLGenerator { } else { Class<?> returnType = method.getReturnType(); if (returnType != Void.TYPE) { - DataType dataType = operation.getOutputType(); + DataType dataType = operation.getOutputType().getLogical().get(0); elements.set(0, getElementInfo(returnType, dataType, elements.get(0).getQName(), helpers)); } } 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 ) { diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java index 03853a2883..afdad37e2d 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java @@ -123,12 +123,15 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { holderPattern = true; // Pop results and place in holder (demote). Holder holder = (Holder) args[ i ]; - Object[] resultArray = (Object[])result; - holder.value = resultArray[++resultIdx]; + + Object[] results = (Object[])result; + if ( result != null ) { + holder.value = results[++resultIdx]; + } } } } - if ( holderPattern ) + if ( holderPattern && result != null) return ((Object[])result)[0]; else return result; 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<String, Object> metadata) { - // Create a data type to represent the ouput produced by the target operation - DataType<DataType> targetType = - new DataTypeImpl<DataType>(IDL_OUTPUT, Object.class, targetOperation.getOutputType()); - - // Create a data type to represent the ouput expected by the source operation - DataType<DataType> sourceType = - new DataTypeImpl<DataType>(IDL_OUTPUT, Object.class, sourceOperation.getOutputType()); - + + DataType sourceType = new DataTypeImpl<DataType>(IDL_OUTPUT, Object.class, sourceOperation.getOutputType()); + DataType targetType = new DataTypeImpl<DataType>(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<DataType> outputTypes = sourceOperation.getOutputType().getLogical(); + List<DataType> outputTypesTarget = targetOperation == null ? null : targetOperation.getOutputType().getLogical(); + Object[] copy = new Object[output.length]; + Map<Object, Object> map = new IdentityHashMap<Object, Object>(); + 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) { |