summaryrefslogtreecommitdiffstats
path: root/java/sca/modules
diff options
context:
space:
mode:
authoredwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68>2009-05-27 09:54:09 +0000
committeredwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68>2009-05-27 09:54:09 +0000
commitfa5447e1a09aca6e9a8ea8d4360683beeaeab298 (patch)
treef2985565f9ed34b29ab6c9b10d2201d1f940eed6 /java/sca/modules
parentab509d2bf1a1df42f932456dfbd0458cbd7fd76c (diff)
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
Diffstat (limited to 'java/sca/modules')
-rw-r--r--java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java17
-rw-r--r--java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java70
2 files changed, 84 insertions, 3 deletions
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 {
* </ol>
* <p/>
* <p>
+ * 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
+ * </p>
+ * <p>
* 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<DataType> sourceInputType = source.getInputType().getLogical();