From: <mcu...@us...> - 2007-08-20 22:32:46
|
Revision: 1096 http://orm.svn.sourceforge.net/orm/?rev=1096&view=rev Author: mcurland Date: 2007-08-20 15:32:49 -0700 (Mon, 20 Aug 2007) Log Message: ----------- Covered additional ORMElementGateway case, extension of work done for [1087] refs #327 Fixed issue adding implied mandatory constraints to non-mandatory preferred identifier roles. refs #330 Modified Paths: -------------- trunk/ORMModel/ObjectModel/ObjectType.cs trunk/Oial/ORMOialBridge/ORMElementGateway.cs Modified: trunk/ORMModel/ObjectModel/ObjectType.cs =================================================================== --- trunk/ORMModel/ObjectModel/ObjectType.cs 2007-08-20 22:30:52 UTC (rev 1095) +++ trunk/ORMModel/ObjectModel/ObjectType.cs 2007-08-20 22:32:49 UTC (rev 1096) @@ -1363,6 +1363,7 @@ { bool canBeIndependent = true; LinkedElementCollection<Role> preferredIdentifierRoles = null; + bool checkedPreferredRoles = false; LinkedElementCollection<Role> playedRoles = PlayedRoleCollection; int playedRoleCount = playedRoles.Count; MandatoryConstraint impliedMandatory = ImpliedMandatoryConstraint; @@ -1404,19 +1405,20 @@ currentRoleIsMandatory = true; bool turnedOffCanBeIndependent = false; // The role must be part of a fact type that has a role in the preferred identifier. - if (preferredIdentifierRoles == null) + if (!checkedPreferredRoles) { + checkedPreferredRoles = true; UniquenessConstraint preferredIdentifier = PreferredIdentifier; - if (preferredIdentifier == null) + if (preferredIdentifier != null) { - canBeIndependent = false; - turnedOffCanBeIndependent = true; - } - else - { preferredIdentifierRoles = preferredIdentifier.RoleCollection; } } + if (preferredIdentifierRoles == null) + { + canBeIndependent = false; + turnedOffCanBeIndependent = true; + } if (canBeIndependent) { RoleBase oppositeRole = playedRole.OppositeRole; @@ -1445,9 +1447,29 @@ } } } - if (!currentRoleIsMandatory) + if (!currentRoleIsMandatory && canBeIndependent) { - seenNonMandatoryRole = true; + bool nonMandatoryRoleInPreferredIdentifier = false; + if (!checkedPreferredRoles) + { + checkedPreferredRoles = true; + UniquenessConstraint preferredIdentifier = PreferredIdentifier; + if (preferredIdentifier != null) + { + preferredIdentifierRoles = preferredIdentifier.RoleCollection; + } + } + if (preferredIdentifierRoles != null) + { + RoleBase oppositeRole = playedRole.OppositeRole; + nonMandatoryRoleInPreferredIdentifier = + null != oppositeRole && + preferredIdentifierRoles.Contains(oppositeRole.Role); + } + if (!nonMandatoryRoleInPreferredIdentifier) + { + seenNonMandatoryRole = true; + } } if (impliedMandatory != null && canBeIndependent) { @@ -1565,7 +1587,7 @@ { if (mandatoryConstraint.IsImplied) { - // The pattern has already been validated. Anything object + // The pattern has already been validated. Any object with // an implied mandatory constraint can be independent. return true; } Modified: trunk/Oial/ORMOialBridge/ORMElementGateway.cs =================================================================== --- trunk/Oial/ORMOialBridge/ORMElementGateway.cs 2007-08-20 22:30:52 UTC (rev 1095) +++ trunk/Oial/ORMOialBridge/ORMElementGateway.cs 2007-08-20 22:32:49 UTC (rev 1096) @@ -70,7 +70,7 @@ foreach (ObjectType objectType in model.ObjectTypeCollection) { if (!IsElementExcluded(objectType) && - !ShouldConsiderObjectType(objectType, null)) + !ShouldConsiderObjectType(objectType, null, false)) { ExcludeObjectType(objectType, abstractionModel, true, notifyExcluded); } @@ -92,9 +92,10 @@ /// markings on its preferred identifier. /// </summary> /// <param name="objectType">The <see cref="ObjectType"/> to test</param> + /// <param name="ignoreFactTypesFilteredForThisObjectType">Don't block consideration of this <paramref name="objectType"/> if a <see cref="FactType"/> is excluded because this <see cref="ObjectType"/> is currently excluded.</param> /// <param name="ignoreFactType">Succeed even if this <see cref="FactType"/> is excluded. Can be <see langword="null"/>.</param> /// <returns><see langword="true"/> if the <paramref name="objectType"/> passes all necessary conditions for consideration.</returns> - private static bool ShouldConsiderObjectType(ObjectType objectType, FactType ignoreFactType) + private static bool ShouldConsiderObjectType(ObjectType objectType, FactType ignoreFactType, bool ignoreFactTypesFilteredForThisObjectType) { // Look at the error states we care about. If any of these error // states are present then we do not consider. @@ -118,10 +119,10 @@ if (factType != ignoreFactType && IsElementExcluded(factType)) { - if (ignoreFactType != null && ShouldConsiderFactType(factType, objectType, true)) + if (ignoreFactTypesFilteredForThisObjectType && ShouldConsiderFactType(factType, objectType, true)) { // This pattern is used only during delay validation. A cleaner model would - // be a delagate callback, but it isn't worth the additional overhead given + // be a delegate callback, but it isn't worth the additional overhead given // that this would be the only code that would ever run there. FilterModifiedFactType(factType, true); } @@ -158,7 +159,7 @@ if (rolePlayer == null || (ignoreRolePlayer != rolePlayer && IsElementExcluded(rolePlayer) && - !(!ignoreRolePlayersFilteredForThisFactType || ShouldConsiderObjectType(rolePlayer, factType)))) + !(!ignoreRolePlayersFilteredForThisFactType || ShouldConsiderObjectType(rolePlayer, factType, true)))) { return false; } @@ -188,7 +189,7 @@ { ModelHasObjectType link = element as ModelHasObjectType; ObjectType objectType = link.ObjectType; - if (ShouldConsiderObjectType(objectType, null)) + if (ShouldConsiderObjectType(objectType, null, false)) { AddObjectType(objectType); } @@ -268,7 +269,7 @@ { ObjectType objectType = (ObjectType)element; ExcludedORMModelElement exclusionLink = ExcludedORMModelElement.GetLinkToAbstractionModel(objectType); - if (ShouldConsiderObjectType(objectType, null)) + if (ShouldConsiderObjectType(objectType, null, true)) { if (exclusionLink != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |