From 699653d2ae2df1cec6af2915c90a6a7137a1c077 Mon Sep 17 00:00:00 2001 From: slaws Date: Tue, 13 Dec 2011 14:12:38 +0000 Subject: TUSCANY-3890 - separate the request wrapper model from the response wrapper model as per the change in 1.x under TUSCANY-2931. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1213702 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tuscany/sca/interfacedef/Operation.java | 28 ++- .../impl/InterfaceContractMapperImpl.java | 38 ++-- .../sca/interfacedef/impl/InterfaceImpl.java | 58 +++--- .../sca/interfacedef/impl/OperationImpl.java | 73 +++++-- .../tuscany/sca/interfacedef/util/WrapperInfo.java | 218 +++++++++------------ 5 files changed, 223 insertions(+), 192 deletions(-) (limited to 'sca-java-2.x/trunk/modules/assembly/src/main/java') diff --git a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/Operation.java b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/Operation.java index 59a79c72d6..100387ce30 100644 --- a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/Operation.java +++ b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/Operation.java @@ -130,23 +130,43 @@ public interface Operation extends Cloneable, PolicySubject { /** * @return the wrapperInfo */ - WrapperInfo getWrapper(); + WrapperInfo getInputWrapper(); /** * @param wrapperInfo the wrapperInfo to set */ - void setWrapper(WrapperInfo wrapperInfo); + void setInputWrapper(WrapperInfo wrapperInfo); + + /** + * @return the wrapperInfo + */ + WrapperInfo getOutputWrapper(); + + /** + * @param wrapperInfo the wrapperInfo to set + */ + void setOutputWrapper(WrapperInfo wrapperInfo); /** * @return the wrapperStyle */ - boolean isWrapperStyle(); + boolean isInputWrapperStyle(); /** * @param wrapperStyle the wrapperStyle to set */ - void setWrapperStyle(boolean wrapperStyle); + void setInputWrapperStyle(boolean wrapperStyle); + /** + * @return the wrapperStyle + */ + boolean isOutputWrapperStyle(); + + /** + * @param wrapperStyle the wrapperStyle to set + */ + void setOutputWrapperStyle(boolean wrapperStyle); + /** * @deprecated This should be the WrapperInfo.getDataBinding() * Get the databinding for the operation diff --git a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java index 7e51e38aaf..d04c8b4d97 100644 --- a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java +++ b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java @@ -245,36 +245,29 @@ public class InterfaceContractMapperImpl implements InterfaceContractMapper { boolean passByValue = (source.getInterface().isRemotable()) && byValue; - // if (source.getInterface().isRemotable()) { - // return true; - // } - // FIXME: We need to deal with wrapped<-->unwrapped conversion - // Check output type List sourceOutputType = source.getOutputType().getLogical(); List targetOutputType = target.getOutputType().getLogical(); - boolean checkSourceWrapper = true; List sourceInputType = source.getInputType().getLogical(); - if (source.isWrapperStyle() && source.getWrapper() != null) { - sourceInputType = source.getWrapper().getUnwrappedInputType().getLogical(); - sourceOutputType = source.getWrapper().getUnwrappedOutputType().getLogical(); - checkSourceWrapper = false; - } - boolean checkTargetWrapper = true; List targetInputType = target.getInputType().getLogical(); - if (target.isWrapperStyle() && target.getWrapper() != null) { - targetInputType = target.getWrapper().getUnwrappedInputType().getLogical(); - targetOutputType = target.getWrapper().getUnwrappedOutputType().getLogical(); - checkTargetWrapper = false; + + if (source.isInputWrapperStyle() && source.getInputWrapper() != null) { + sourceInputType = source.getInputWrapper().getUnwrappedType().getLogical(); + } + + if (source.isOutputWrapperStyle() && source.getOutputWrapper() != null) { + sourceOutputType = source.getOutputWrapper().getUnwrappedType().getLogical(); } - /* TODO - Why are we assuming compatibility if one side is wrapped and the other is not? - if (checkSourceWrapper != checkTargetWrapper) { - return true; + if (target.isInputWrapperStyle() && target.getInputWrapper() != null) { + targetInputType = target.getInputWrapper().getUnwrappedType().getLogical(); + } + + if (target.isOutputWrapperStyle() && target.getOutputWrapper() != null) { + targetOutputType = target.getOutputWrapper().getUnwrappedType().getLogical(); } - */ if ( sourceOutputType.size() != targetOutputType.size()) { if (audit != null){ @@ -294,7 +287,6 @@ public class InterfaceContractMapperImpl implements InterfaceContractMapper { } } - if (sourceInputType.size() != targetInputType.size()) { if (audit != null){ audit.append("different number of input types"); @@ -348,7 +340,9 @@ public class InterfaceContractMapperImpl implements InterfaceContractMapper { @Override public boolean isCompatibleWithoutUnwrapByValue(Operation source, Operation target, Compatibility compatibilityType) { - if (!source.isWrapperStyle() == target.isWrapperStyle()) { + if (!source.isInputWrapperStyle() == target.isInputWrapperStyle()) { + return false; + } else if (!source.isOutputWrapperStyle() == target.isOutputWrapperStyle()) { return false; } else { return isCompatible(source, target, compatibilityType, true); diff --git a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java index 1daa6baf9c..ec7c784547 100644 --- a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java +++ b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java @@ -161,10 +161,10 @@ public class InterfaceImpl implements Interface { } } - if (op.isWrapperStyle()) { - WrapperInfo wrapper = op.getWrapper(); + if (op.isInputWrapperStyle()) { + WrapperInfo wrapper = op.getInputWrapper(); if (wrapper != null) { - DataType> unwrappedInputType = wrapper.getUnwrappedInputType(); + DataType> unwrappedInputType = wrapper.getUnwrappedType(); if (unwrappedInputType != null) { for (DataType d : unwrappedInputType.getLogical()) { if (d.getDataBinding() == null) { @@ -172,12 +172,21 @@ public class InterfaceImpl implements Interface { } } } - DataType unwrappedOutputType = wrapper.getUnwrappedOutputType(); - if (unwrappedOutputType != null && unwrappedOutputType.getDataBinding() == null) { - unwrappedOutputType.setDataBinding(dataBinding); - } } } + if (op.isOutputWrapperStyle()) { + WrapperInfo wrapper = op.getOutputWrapper(); + if (wrapper != null) { + DataType> unwrappedOutputType = wrapper.getUnwrappedType(); + if (unwrappedOutputType != null){ + for (DataType d : unwrappedOutputType.getLogical()) { + if (d.getDataBinding() == null) { + d.setDataBinding(dataBinding); + } + } + } + } + } } } } @@ -188,7 +197,7 @@ public class InterfaceImpl implements Interface { } else { dataType.setDataBinding(dataBinding); } - } + } public void resetDataBinding(String dataBinding) { for (Operation op : getOperations()) { @@ -213,29 +222,34 @@ public class InterfaceImpl implements Interface { setDataBinding((DataType) d.getLogical(), dataBinding); } } - if (op.isWrapperStyle()) { - WrapperInfo wrapper = op.getWrapper(); - if (wrapper != null) { - DataType> unwrappedInputType = wrapper.getUnwrappedInputType(); + if (op.isInputWrapperStyle()) { + WrapperInfo inputWrapper = op.getInputWrapper(); + if (inputWrapper != null) { + DataType> unwrappedInputType = inputWrapper.getUnwrappedType(); if (unwrappedInputType != null) { for (DataType d : unwrappedInputType.getLogical()) { setDataBinding(d, dataBinding); } } - DataType> unwrappedOutputType = wrapper.getUnwrappedOutputType(); + } + } + if (op.isOutputWrapperStyle()) { + WrapperInfo outputWrapper = op.getOutputWrapper(); + if (outputWrapper != null) { + DataType> unwrappedOutputType = outputWrapper.getUnwrappedType(); if (unwrappedOutputType != null) { for (DataType d : unwrappedOutputType.getLogical()) { setDataBinding(d, dataBinding); } } } - } + } } } public void resetInterfaceInputTypes(Interface newInterface){ for (int i = 0; i < getOperations().size(); i++) { - // only remote interfaces only have a data type model defined + // only remote interfaces have a data type model defined // and in this case operations cannot be overloaded so match // operations by name Operation oldOperation = getOperations().get(i); @@ -255,16 +269,16 @@ public class InterfaceImpl implements Interface { oldOperation.setInputType(newOperation.getInputType()); // set wrapper - if (newOperation.isWrapperStyle()) { - oldOperation.setWrapperStyle(true); - oldOperation.setWrapper(newOperation.getWrapper()); + if (newOperation.isInputWrapperStyle()) { + oldOperation.setInputWrapperStyle(true); + oldOperation.setInputWrapper(newOperation.getInputWrapper()); } } } public void resetInterfaceOutputTypes(Interface newInterface){ for (int i = 0; i < getOperations().size(); i++) { - // only remote interfaces only have a data type model defined + // only remote interfaces have a data type model defined // and in this case operations cannot be overloaded so match // operations by name Operation oldOperation = getOperations().get(i); @@ -287,9 +301,9 @@ public class InterfaceImpl implements Interface { oldOperation.setFaultTypes(newOperation.getFaultTypes()); // set wrapper - if (newOperation.isWrapperStyle()) { - oldOperation.setWrapperStyle(true); - oldOperation.setWrapper(newOperation.getWrapper()); + if (newOperation.isOutputWrapperStyle()) { + oldOperation.setOutputWrapperStyle(true); + oldOperation.setOutputWrapper(newOperation.getOutputWrapper()); } } } diff --git a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/OperationImpl.java b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/OperationImpl.java index b820f95fcf..8d6cbc6d86 100644 --- a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/OperationImpl.java +++ b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/OperationImpl.java @@ -51,8 +51,10 @@ public class OperationImpl implements Operation { private Interface interfaze; private List parameterModes = new ArrayList(); private boolean nonBlocking; - private boolean wrapperStyle; - private WrapperInfo wrapper; + private boolean inputWrapperStyle; + private boolean outputWrapperStyle; + private WrapperInfo inputWrapper; + private WrapperInfo outputWrapper; private boolean dynamic; private boolean notSubjectToWrapping; @@ -167,38 +169,75 @@ public class OperationImpl implements Operation { /** * @return the wrapperInfo */ - public WrapperInfo getWrapper() { - return wrapper; + public WrapperInfo getInputWrapper() { + return inputWrapper; } /** * @param wrapperInfo the wrapperInfo to set */ - public void setWrapper(WrapperInfo wrapperInfo) { - this.wrapper = wrapperInfo; + public void setInputWrapper(WrapperInfo wrapperInfo) { + this.inputWrapper = wrapperInfo; } + + /** + * @return the wrapperInfo + */ + public WrapperInfo getOutputWrapper() { + return outputWrapper; + } + + /** + * @param wrapperInfo the wrapperInfo to set + */ + public void setOutputWrapper(WrapperInfo wrapperInfo) { + this.outputWrapper = wrapperInfo; + } /** * @return the wrapperStyle */ - public boolean isWrapperStyle() { - return wrapperStyle; + public boolean isInputWrapperStyle() { + return inputWrapperStyle; } /** * @param wrapperStyle the wrapperStyle to set */ - public void setWrapperStyle(boolean wrapperStyle) { - this.wrapperStyle = wrapperStyle; + public void setInputWrapperStyle(boolean wrapperStyle) { + this.inputWrapperStyle = wrapperStyle; + } + + /** + * @return the wrapperStyle + */ + public boolean isOutputWrapperStyle() { + return outputWrapperStyle; } + /** + * @param wrapperStyle the wrapperStyle to set + */ + public void setOutputWrapperStyle(boolean wrapperStyle) { + this.outputWrapperStyle = wrapperStyle; + } + public String getDataBinding() { - return wrapper != null ? wrapper.getDataBinding() : null; + if (inputWrapper != null){ + return inputWrapper.getDataBinding(); + } + if (outputWrapper != null){ + return outputWrapper.getDataBinding(); + } + return null; } public void setDataBinding(String dataBinding) { - if (wrapper != null) { - wrapper.setDataBinding(dataBinding); + if (inputWrapper != null) { + inputWrapper.setDataBinding(dataBinding); + } + if (outputWrapper != null) { + outputWrapper.setDataBinding(dataBinding); } } @@ -258,8 +297,12 @@ public class OperationImpl implements Operation { copy.attributes.putAll(attributes); // [rfeng] We need to clone the wrapper as it holds the databinding information - if (wrapper != null) { - copy.wrapper = (WrapperInfo)wrapper.clone(); + if (inputWrapper != null) { + copy.inputWrapper = (WrapperInfo)inputWrapper.clone(); + } + + if (outputWrapper != null) { + copy.outputWrapper = (WrapperInfo)outputWrapper.clone(); } return copy; diff --git a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/util/WrapperInfo.java b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/util/WrapperInfo.java index dfdc85d405..6873943efc 100644 --- a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/util/WrapperInfo.java +++ b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/util/WrapperInfo.java @@ -31,7 +31,7 @@ import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; * A WSDL operation qualifies for wrapper style mapping only if the following * criteria are met: *
    - *
  • (i) The operation�s input and output messages (if present) each contain + *
  • (i) The operations input and output messages (if present) each contain * only a single part *
  • (ii) The input message part refers to a global element declaration whose * localname is equal to the operation name @@ -49,83 +49,123 @@ import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; * @tuscany.spi.extension.asclient */ public class WrapperInfo implements Cloneable { - private ElementInfo inputWrapperElement; - - private ElementInfo outputWrapperElement; - - private List inputChildElements; - - private List outputChildElements; - - // The data type of the unwrapped input child elements - private DataType> unwrappedInputType; - - // The data type of the unwrapped output child elements - private DataType> unwrappedOutputType; - - // The data for the input/output wrappers + + // The databinding for the wrapper private String dataBinding; - - // The data type for the input (request) wrapper bean - private DataType inputWrapperType; - // The data type for the output (response) wrapper bean - private DataType outputWrapperType; + + // The XML element representation of the wrapper + private ElementInfo wrapperElement; + + // The XML child elements of the wrapper + private List childElements; + + // The data type for the wrapper bean + private DataType wrapperType; + + // The data types of the unwrapped child elements + private DataType> unwrappedType; public WrapperInfo(String dataBinding, - ElementInfo inputWrapperElement, - ElementInfo outputWrapperElement, - List inputElements, - List outputElements) { + ElementInfo wrapperElement, + List childElements) { super(); this.dataBinding = dataBinding; - this.inputWrapperElement = inputWrapperElement; - this.outputWrapperElement = outputWrapperElement; - this.inputChildElements = inputElements; - this.outputChildElements = outputElements; + this.wrapperElement = wrapperElement; + this.childElements = childElements; } /** - * @return the inputElements + * Get the list of XML child elements that this + * wrapper wraps + * + * @return the childElements */ - public List getInputChildElements() { - return inputChildElements; + public List getChildElements() { + return childElements; } /** - * @return the inputWrapperElement + * Get the XML element that represents this wrapper + * + * @return the wrapperElement */ - public ElementInfo getInputWrapperElement() { - return inputWrapperElement; + public ElementInfo getWrapperElement() { + return wrapperElement; } - + /** - * @return the outputElements + * Get the databinding that this wrapper will + * be subject to + * + * @return dataBinding */ - public List getOutputChildElements() { - return outputChildElements; + public String getDataBinding() { + return dataBinding; } /** - * @return the outputWrapperElement + * Set the databinding that this wrapper will + * be subject to + * + * @param dataBinding + */ + public void setDataBinding(String dataBinding) { + this.dataBinding = dataBinding; + } + + /** + * Get the Tuscany data type for the wrapper + * + * @return Tuscany data type for the wrapper */ - public ElementInfo getOutputWrapperElement() { - return outputWrapperElement; + public DataType getWrapperType() { + return wrapperType; } /** - * @return the unwrappedInputType + * Set the Tuscany data type for the wrapper + * + * @param wrapperType Tuscany data type for the wrapper + */ + public void setWrapperType(DataType wrapperType) { + this.wrapperType = wrapperType; + } + + /** + * Return the Java class for the wrapper + * + * @return Java class for the wrapper + */ + public Class getWrapperClass() { + return wrapperType == null ? null : wrapperType.getPhysical(); + } + + @Override + public Object clone() throws CloneNotSupportedException { + WrapperInfo copy = (WrapperInfo) super.clone(); + if (wrapperType != null) { + copy.wrapperType = (DataType)wrapperType.clone(); + } + return copy; + + } + + /** + * Creates and caches the data types for the child elements + * + * @return The list of child element data types */ - public DataType> getUnwrappedInputType() { - if (unwrappedInputType == null) { + public DataType> getUnwrappedType() { + if (unwrappedType == null) { List childTypes = new ArrayList(); - for (ElementInfo element : getInputChildElements()) { + for (ElementInfo element : getChildElements()) { DataType type = getDataType(element); childTypes.add(type); } - unwrappedInputType = new DataTypeImpl>("idl:unwrapped.input", Object[].class, childTypes); + unwrappedType = new DataTypeImpl>("idl:unwrapped", Object[].class, childTypes); } - return unwrappedInputType; - } + return unwrappedType; + } private DataType getDataType(ElementInfo element) { DataType type = null; @@ -138,84 +178,4 @@ public class WrapperInfo implements Cloneable { return type; } - /** - * @return the unwrappedOutputType - */ - public DataType> getUnwrappedOutputType() { - if (unwrappedOutputType == null) { - List childTypes = new ArrayList(); - for (ElementInfo element : getOutputChildElements()) { - DataType type = getDataType(element); - childTypes.add(type); - } - unwrappedOutputType = new DataTypeImpl>("idl:unwrapped.input", Object[].class, childTypes); - } - return unwrappedOutputType; } - - public Class getInputWrapperClass() { - return inputWrapperType == null ? null : inputWrapperType.getPhysical(); - } - - public Class getOutputWrapperClass() { - return outputWrapperType == null ? null : outputWrapperType.getPhysical(); - } - - public String getDataBinding() { - return dataBinding; - } - - public void setDataBinding(String dataBinding) { - this.dataBinding = dataBinding; - } - - public DataType getInputWrapperType() { - return inputWrapperType; - } - - public void setInputWrapperType(DataType inputWrapperType) { - this.inputWrapperType = inputWrapperType; - } - - public DataType getOutputWrapperType() { - return outputWrapperType; - } - - public void setOutputWrapperType(DataType outputWrapperType) { - this.outputWrapperType = outputWrapperType; - } - - @Override - public Object clone() throws CloneNotSupportedException { - WrapperInfo copy = (WrapperInfo) super.clone(); - if (inputWrapperType != null) { - copy.inputWrapperType = (DataType)inputWrapperType.clone(); - } - if (outputWrapperType != null) { - copy.outputWrapperType = (DataType)outputWrapperType.clone(); - } - if (unwrappedInputType != null) { - List clonedLogicalTypes = new ArrayList(); - for (DataType t : unwrappedInputType.getLogical()) { - DataType type = (DataType) t.clone(); - clonedLogicalTypes.add(type); - } - DataType> clonedUnwrappedInputType = - new DataTypeImpl>(unwrappedInputType.getPhysical(), clonedLogicalTypes); - clonedUnwrappedInputType.setDataBinding(unwrappedInputType.getDataBinding()); - copy.unwrappedInputType = clonedUnwrappedInputType; - } - if (unwrappedOutputType != null) { - List clonedLogicalTypes = new ArrayList(); - for (DataType t : unwrappedOutputType.getLogical()) { - DataType type = (DataType) t.clone(); - clonedLogicalTypes.add(type); - } - DataType> clonedUnwrappedOutputType = - new DataTypeImpl>(unwrappedOutputType.getPhysical(), clonedLogicalTypes); - clonedUnwrappedOutputType.setDataBinding(unwrappedOutputType.getDataBinding()); - copy.unwrappedOutputType = clonedUnwrappedOutputType; - } - return copy; - - } } -- cgit v1.2.3