From fa5447e1a09aca6e9a8ea8d4360683beeaeab298 Mon Sep 17 00:00:00 2001 From: edwardsmj Date: Wed, 27 May 2009 09:54:09 +0000 Subject: Added new method for testing Equality of two interfaces, as described in TUSCANY-3064 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@779075 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/interfacedef/InterfaceContractMapper.java | 17 +++++- .../impl/InterfaceContractMapperImpl.java | 70 +++++++++++++++++++++- 2 files changed, 84 insertions(+), 3 deletions(-) (limited to 'java/sca/modules') diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java b/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java index 5601b09660..ad16aa671e 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java +++ b/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java @@ -47,6 +47,12 @@ public interface InterfaceContractMapper { * *

*

+ * This relationship implies that the source contract is a subset of the target + * contract - ie all the operations of the source must be present in the target, but + * the target can in principle contain additional operations not present in the + * source + *

+ *

* Please note this test is not symmetric: the success of isCompatible(A, B) * does NOT imply isCompatible(B, A) * @@ -56,6 +62,15 @@ public interface InterfaceContractMapper { * contract */ boolean isCompatible(InterfaceContract source, InterfaceContract target); + + /** + * Check that two interface contracts are equal. The contracts are equal if the two contracts have the + * same set of operations, with each operation having the same signature. + * @param source - the source contract + * @param target - the target contract + * @return + */ + boolean isEqual(InterfaceContract source, InterfaceContract target); /** * @param source @@ -84,7 +99,7 @@ public interface InterfaceContractMapper { * @param target The target data type * @return */ - boolean isCompatible(DataType source, DataType target, boolean remotable); + boolean isCompatible(DataType source, DataType target, boolean remotable); /** * Check if source operation is compatible with the target operation diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java b/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java index 647dc2021e..524182f66c 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java +++ b/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java @@ -50,6 +50,72 @@ public class InterfaceContractMapperImpl implements InterfaceContractMapper { } } + + + /** + * Check that two interface contracts are equal. The contracts are equal if the two contracts have the + * same set of operations, with each operation having the same signature, both for forward and callback + * interfaces + * @param source + * @param target + * @return + */ + public boolean isEqual(InterfaceContract source, InterfaceContract target) { + // Are the forward interfaces equal? + if( isEqual( source.getInterface(), target.getInterface()) ) { + // Is there a Callback interface? + if( source.getCallbackInterface() == null && target.getCallbackInterface() == null ) { + return true; + } else { + if( isEqual( source.getCallbackInterface(), target.getCallbackInterface()) ) { + return true; + } // end if + } // end if + } // end if + return false; + } // end method isEqual + + /** + * Check that two interfaces are equal. The interfaces are equal if the two interfaces have the + * same set of operations, with each operation having the same signature. + * @param source + * @param target + * @return + */ + public boolean isEqual(Interface source, Interface target) { + if (source == target) { + // Shortcut for performance + return true; + } // end if + if (source == null || target == null) { + return false; + } // end if + + if (source.isDynamic() || target.isDynamic()) { + return true; + } + + if (source.isRemotable() != target.isRemotable()) { + return false; + } + if (source.isConversational() != target.isConversational()) { + return false; + } + if( source.getOperations().size() != target.getOperations().size() ) { + return false; + } + + for (Operation operation : source.getOperations()) { + Operation targetOperation = getOperation(target.getOperations(), operation.getName()); + if (targetOperation == null) { + return false; + } + if (!isCompatible(operation, targetOperation, source.isRemotable())) { + return false; + } + } + return true; + } // end method isEqual public boolean isCompatible(Operation source, Operation target, boolean remotable) { if (source == target) { @@ -76,8 +142,8 @@ public class InterfaceContractMapperImpl implements InterfaceContractMapper { // FIXME: We need to deal with wrapped<-->unwrapped conversion // Check output type - DataType sourceOutputType = source.getOutputType(); - DataType targetOutputType = target.getOutputType(); + DataType sourceOutputType = source.getOutputType(); + DataType targetOutputType = target.getOutputType(); boolean checkSourceWrapper = true; List sourceInputType = source.getInputType().getLogical(); -- cgit v1.2.3