You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2009/10/15 17:28:31 UTC

svn commit: r825517 - in /tuscany/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl: ComponentBuilderImpl.java CompositeComponentTypeBuilderImpl.java

Author: slaws
Date: Thu Oct 15 15:28:30 2009
New Revision: 825517

URL: http://svn.apache.org/viewvc?rev=825517&view=rev
Log:
Separate reference and service interface compatibility processing in order to get the promotion sub-set/super-set relationship right

Modified:
    tuscany/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java
    tuscany/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java

Modified: tuscany/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java?rev=825517&r1=825516&r2=825517&view=diff
==============================================================================
--- tuscany/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java (original)
+++ tuscany/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java Thu Oct 15 15:28:30 2009
@@ -58,6 +58,7 @@
 import org.apache.tuscany.sca.core.FactoryExtensionPoint;
 import org.apache.tuscany.sca.core.UtilityExtensionPoint;
 import org.apache.tuscany.sca.definitions.Definitions;
+import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractException;
 import org.apache.tuscany.sca.interfacedef.InterfaceContract;
 import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
 import org.apache.tuscany.sca.monitor.Monitor;
@@ -193,7 +194,7 @@
             }
 
             // interface contracts
-            calculateInterfaceContract(component, componentService, componentTypeService);
+            calculateServiceInterfaceContract(component, componentService, componentTypeService);
 
             // bindings
             calculateBindings(componentService, componentTypeService);
@@ -243,7 +244,7 @@
             reconcileReferenceMultiplicity(component, componentReference, componentTypeReference);
 
             // interface contracts
-            calculateInterfaceContract(component, componentReference, componentTypeReference);
+            calculateReferenceInterfaceContract(component, componentReference, componentTypeReference);
 
             // bindings
             calculateBindings(componentReference, componentTypeReference);
@@ -1072,18 +1073,57 @@
         }
     }
 
+
     /**
-     * The following methods implement rules that the OASIS specification defined explicitly
-     * to control how configuration from a component type is inherited by a component
+     * Interface contract from higher in the implementation hierarchy takes precedence
+     * When it comes to checking compatibility the top level service interface is a 
+     * subset of the promoted service interface so treat the top level interface as
+     * the source
+     * 
+     * @param topContract the top contract 
+     * @param bottomContract the bottom contract
      */
+    private void calculateServiceInterfaceContract(Component component, Service topContract, Service bottomContract) {
+
+        // Use the interface contract from the bottom level contract if
+        // none is specified on the top level contract
+        InterfaceContract topInterfaceContract = topContract.getInterfaceContract();
+        InterfaceContract bottomInterfaceContract = bottomContract.getInterfaceContract();
 
+        if (topInterfaceContract == null) {
+            topContract.setInterfaceContract(bottomInterfaceContract);
+        } else if (bottomInterfaceContract != null) {
+            // Check that the top and bottom interface contracts are compatible
+            boolean isCompatible = true;
+            String incompatibilityReason = "";
+            try{
+                isCompatible = interfaceContractMapper.checkCompatibility(topInterfaceContract, bottomInterfaceContract, false, false);
+            } catch (IncompatibleInterfaceContractException ex){
+                isCompatible = false;
+                incompatibilityReason = ex.getMessage();
+            }            
+            if (!isCompatible) {
+                Monitor.error(monitor,
+                              this,
+                              Messages.ASSEMBLY_VALIDATION,
+                              "ServiceIncompatibleComponentInterface",
+                              component.getName(),
+                              topContract.getName(),
+                              incompatibilityReason);
+            }
+        }
+    }
+    
     /**
-     * OASIS RULE: Interface contract from higher in the implementation hierarchy takes precedence
+     * Interface contract from higher in the implementation hierarchy takes precedence
+     * When it comes to checking compatibility the top level reference interface is a 
+     * superset of the promoted reference interface so treat the treat the promoted
+     * (bottom) interface as the source    
      * 
      * @param topContract the top contract 
      * @param bottomContract the bottom contract
      */
-    private void calculateInterfaceContract(Component component, Contract topContract, Contract bottomContract) {
+    private void calculateReferenceInterfaceContract(Component component, Reference topContract, Reference bottomContract) {
 
         // Use the interface contract from the bottom level contract if
         // none is specified on the top level contract
@@ -1094,29 +1134,28 @@
             topContract.setInterfaceContract(bottomInterfaceContract);
         } else if (bottomInterfaceContract != null) {
             // Check that the top and bottom interface contracts are compatible
-            boolean isCompatible = interfaceContractMapper.isCompatible(bottomInterfaceContract, topInterfaceContract);
+            boolean isCompatible = true;
+            String incompatibilityReason = "";
+            try{
+                isCompatible = interfaceContractMapper.checkCompatibility(bottomInterfaceContract, topInterfaceContract, false, false);
+            } catch (IncompatibleInterfaceContractException ex){
+                isCompatible = false;
+                incompatibilityReason = ex.getMessage();
+            }            
             if (!isCompatible) {
-                if (topContract instanceof Reference) {
-                    Monitor.error(monitor,
-                                  this,
-                                  Messages.ASSEMBLY_VALIDATION,
-                                  "ReferenceIncompatibleComponentInterface",
-                                  component.getName(),
-                                  topContract.getName());
-                } else {
-                    Monitor.error(monitor,
-                                  this,
-                                  Messages.ASSEMBLY_VALIDATION,
-                                  "ServiceIncompatibleComponentInterface",
-                                  component.getName(),
-                                  topContract.getName());
-                }
+                Monitor.error(monitor,
+                              this,
+                              Messages.ASSEMBLY_VALIDATION,
+                              "ReferenceIncompatibleComponentInterface",
+                              component.getName(),
+                              topContract.getName(),
+                              incompatibilityReason);
             }
         }
-    }
+    }    
 
     /**
-     * OASIS RULE: Bindings from higher in the hierarchy take precedence
+     * Bindings from higher in the hierarchy take precedence
      * 
      * @param componentService the top service 
      * @param componentTypeService the bottom service
@@ -1145,7 +1184,7 @@
     }
     
     /**
-     * OASIS RULE: Bindings from higher in the hierarchy take precedence
+     * Bindings from higher in the hierarchy take precedence
      * 
      * @param componentReference the top service 
      * @param componentTypeReference the bottom service

Modified: tuscany/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java?rev=825517&r1=825516&r2=825517&view=diff
==============================================================================
--- tuscany/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java (original)
+++ tuscany/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java Thu Oct 15 15:28:30 2009
@@ -45,6 +45,7 @@
 import org.apache.tuscany.sca.core.FactoryExtensionPoint;
 import org.apache.tuscany.sca.core.UtilityExtensionPoint;
 import org.apache.tuscany.sca.definitions.Definitions;
+import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractException;
 import org.apache.tuscany.sca.interfacedef.InterfaceContract;
 import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
 import org.apache.tuscany.sca.monitor.Monitor;
@@ -228,7 +229,7 @@
             ComponentService promotedComponentService = compositeService.getPromotedService();
 
             // promote interface contracts
-            calculatePromotedInterfaceContract(compositeService, promotedComponentService);
+            calculatePromotedServiceInterfaceContract(compositeService, promotedComponentService);
 
             // promote bindings
             calculatePromotedBindings(compositeService, promotedComponentService);
@@ -265,7 +266,7 @@
             for (ComponentReference promotedComponentReference : promotedReferences) {
 
                 // promote interface contracts
-                calculatePromotedInterfaceContract(compositeReference, promotedComponentReference);
+                calculatePromotedReferenceInterfaceContract(compositeReference, promotedComponentReference);
 
                 // promote bindings
                 // Don't need to promote reference bindings as any lower level binding will
@@ -408,12 +409,15 @@
      */
 
     /**
-     * OASIS RULE: Interface contract from higher in the implementation hierarchy takes precedence
+     * Interface contract from higher in the implementation hierarchy takes precedence. 
+     * When it comes to checking compatibility the top level service interface is a 
+     * subset of the promoted service interface so treat the top level interface as
+     * the source
      * 
      * @param topContract the top contract 
      * @param bottomContract the bottom contract
      */
-    private void calculatePromotedInterfaceContract(Contract topContract, Contract bottomContract) {
+    private void calculatePromotedServiceInterfaceContract(Service topContract, Service bottomContract) {
         // Use the interface contract from the bottom level contract if
         // none is specified on the top level contract
         InterfaceContract topInterfaceContract = topContract.getInterfaceContract();
@@ -423,27 +427,65 @@
             topContract.setInterfaceContract(bottomInterfaceContract);
         } else if (bottomInterfaceContract != null) {
             // Check that the top and bottom interface contracts are compatible
-            boolean isCompatible = interfaceContractMapper.isCompatible(topInterfaceContract, bottomInterfaceContract);
+            boolean isCompatible = true;
+            String incompatibilityReason = "";
+            try{
+                isCompatible = interfaceContractMapper.checkCompatibility(topInterfaceContract, bottomInterfaceContract, false, false);
+            } catch (IncompatibleInterfaceContractException ex){
+                isCompatible = false;
+                incompatibilityReason = ex.getMessage();
+            }
             if (!isCompatible) {
-                if (topContract instanceof Reference) {
-                    Monitor.error(monitor,
-                                  this,
-                                  Messages.ASSEMBLY_VALIDATION,
-                                  "ReferenceInterfaceNotSubSet",
-                                  topContract.getName());
-                } else {
-                    Monitor.error(monitor,
-                                  this,
-                                  Messages.ASSEMBLY_VALIDATION,
-                                  "ServiceInterfaceNotSubSet",
-                                  topContract.getName());
-                }
+                Monitor.error(monitor,
+                              this,
+                              Messages.ASSEMBLY_VALIDATION,
+                              "ServiceInterfaceNotSubSet",
+                              topContract.getName(),
+                              incompatibilityReason);
             }
         }
     }
+    
+    /**
+     * Interface contract from higher in the implementation hierarchy takes precedence. 
+     * When it comes to checking compatibility the top level reference interface is a 
+     * superset of the promoted reference interface so treat the treat the promoted
+     * (bottom) interface as the source
+     * 
+     * @param topContract the top contract 
+     * @param bottomContract the bottom contract
+     */    
+    private void calculatePromotedReferenceInterfaceContract(Reference topContract, Reference bottomContract) {
+        // Use the interface contract from the bottom level contract if
+        // none is specified on the top level contract
+        InterfaceContract topInterfaceContract = topContract.getInterfaceContract();
+        InterfaceContract bottomInterfaceContract = bottomContract.getInterfaceContract();
+
+        if (topInterfaceContract == null) {
+            topContract.setInterfaceContract(bottomInterfaceContract);
+        } else if (bottomInterfaceContract != null) {
+            // Check that the top and bottom interface contracts are compatible
+            boolean isCompatible = true;
+            String incompatibilityReason = "";
+            try{
+                isCompatible = interfaceContractMapper.checkCompatibility(bottomInterfaceContract, topInterfaceContract, false, false);
+            } catch (IncompatibleInterfaceContractException ex){
+                isCompatible = false;
+                incompatibilityReason = ex.getMessage();
+            }
+            if (!isCompatible) {
+                Monitor.error(monitor,
+                              this,
+                              Messages.ASSEMBLY_VALIDATION,
+                              "ReferenceInterfaceNotSubSet",
+                              topContract.getName(),
+                              incompatibilityReason);
+            }
+        }
+    }    
 
     /**
-     * OASIS RULE: Bindings from higher in the implementation hierarchy take precedence
+     * Bindings from higher in the implementation hierarchy take precedence
      * 
      * @param compositeService
      * @param promotedComponentService