diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-10-15 15:28:30 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-10-15 15:28:30 +0000 |
commit | 9e94f4ab4e030cbb6aa0def120a22c61a2fa1152 (patch) | |
tree | d9fc518e0fe476ef5154a4e7c83369d661edffa0 /java/sca | |
parent | d82c798041573a200128f5970df894db21e6af0a (diff) |
Separate reference and service interface compatibility processing in order to get the promotion sub-set/super-set relationship right
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@825517 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca')
2 files changed, 125 insertions, 44 deletions
diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java index 27d13442cd..9c4a1c9282 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java @@ -58,6 +58,7 @@ import org.apache.tuscany.sca.core.ExtensionPointRegistry; 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 @@ public class ComponentBuilderImpl { } // interface contracts - calculateInterfaceContract(component, componentService, componentTypeService); + calculateServiceInterfaceContract(component, componentService, componentTypeService); // bindings calculateBindings(componentService, componentTypeService); @@ -243,7 +244,7 @@ public class ComponentBuilderImpl { reconcileReferenceMultiplicity(component, componentReference, componentTypeReference); // interface contracts - calculateInterfaceContract(component, componentReference, componentTypeReference); + calculateReferenceInterfaceContract(component, componentReference, componentTypeReference); // bindings calculateBindings(componentReference, componentTypeReference); @@ -1072,18 +1073,57 @@ public class ComponentBuilderImpl { } } + /** - * 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 @@ public class ComponentBuilderImpl { 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 @@ public class ComponentBuilderImpl { } /** - * 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 diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java index d0bc098fbe..381eb87857 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java @@ -45,6 +45,7 @@ import org.apache.tuscany.sca.core.ExtensionPointRegistry; 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 @@ public class CompositeComponentTypeBuilderImpl { ComponentService promotedComponentService = compositeService.getPromotedService(); // promote interface contracts - calculatePromotedInterfaceContract(compositeService, promotedComponentService); + calculatePromotedServiceInterfaceContract(compositeService, promotedComponentService); // promote bindings calculatePromotedBindings(compositeService, promotedComponentService); @@ -265,7 +266,7 @@ public class CompositeComponentTypeBuilderImpl { 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 @@ public class CompositeComponentTypeBuilderImpl { */ /** - * 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 @@ public class CompositeComponentTypeBuilderImpl { 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 |