You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ed...@apache.org on 2009/05/27 11:54:09 UTC

svn commit: r779075 - in /tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef: InterfaceContractMapper.java impl/InterfaceContractMapperImpl.java

Author: edwardsmj
Date: Wed May 27 09:54:09 2009
New Revision: 779075

URL: http://svn.apache.org/viewvc?rev=779075&view=rev
Log:
Added new method for testing Equality of two interfaces, as described in TUSCANY-3064

Modified:
    tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java
    tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java

Modified: tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java?rev=779075&r1=779074&r2=779075&view=diff
==============================================================================
--- tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java (original)
+++ tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java Wed May 27 09:54:09 2009
@@ -47,6 +47,12 @@
      * </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 @@
      *         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 @@
      * @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

Modified: tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java?rev=779075&r1=779074&r2=779075&view=diff
==============================================================================
--- tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java (original)
+++ tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java Wed May 27 09:54:09 2009
@@ -50,6 +50,72 @@
         }
 
     }
+    
+
+    /**
+     * 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 @@
         // 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();