private IList <string> CreateListOfProperlyOrderedNames(XmlElement element, IList <MessagePart> messagePartAndChoiceExtensionParts , MessageVisitor visitor) { IList <string> properlyOrderedProvidedRelationshipNames = new List <string>(); foreach (MessagePart messagePart in messagePartAndChoiceExtensionParts) { ElementBridge helper = new ElementBridge(element, messagePart, GetInteraction(element.OwnerDocument)); foreach (RelationshipBridge relationshipBridge in helper.GetRelationships()) { if (!relationshipBridge.IsStructuralAttribute()) { ICollection <string> names = relationshipBridge.GetNames(); if (!names.IsEmpty()) { IEnumerator <string> iterator = names.GetEnumerator(); if (iterator.MoveNext()) { //For .NET translation properlyOrderedProvidedRelationshipNames.Add(iterator.Current); } if (names.Count > 1) { // not expecting this to ever happen, but need to know if it does so we can adjust the code visitor.AddError("Internal error: found more than one name " + ListNames(names), element); } } } } } return(properlyOrderedProvidedRelationshipNames); }
private void ValidateElementOrder(IList <MessagePart> messagePartAndChoiceExtensionParts, XmlElement element, MessageVisitor visitor) { // create list of properly ordered names (skipping those not provided, and skipping those without a relationship match) IList <string> properlyOrderedProvidedRelationshipNames = CreateListOfProperlyOrderedNames(element, messagePartAndChoiceExtensionParts , visitor); // create list of xml names in the order provided (collapsing duplicates) // remove/ignore any not in properly ordered names IList <string> xmlElementNamesInOrderProvided = CreateListOfXmlNamesInOrderProvided(element, properlyOrderedProvidedRelationshipNames ); // iterate proper list, look for exact match int expectedSize = properlyOrderedProvidedRelationshipNames.Count; int actualSize = xmlElementNamesInOrderProvided.Count; bool errorDetected = false; for (int i = 0; i < expectedSize; i++) { string expectedName = properlyOrderedProvidedRelationshipNames[i]; string actualName = actualSize > i ? xmlElementNamesInOrderProvided[i] : null; if (!StringUtils.Equals(expectedName, actualName)) { // if not found, break out and log error "beginning with...", then show expected element order errorDetected = true; string errorMessage = CreateElementOutOfOrderErrorMessage(properlyOrderedProvidedRelationshipNames, actualName); visitor.AddError(errorMessage, element); break; } } // the two sets of names should be the same length, but just in case... if (!errorDetected && actualSize > expectedSize) { string errorMessage = CreateElementOutOfOrderErrorMessage(properlyOrderedProvidedRelationshipNames, xmlElementNamesInOrderProvided [expectedSize]); visitor.AddError(errorMessage, element); } }