private void MapComplexType(SourceItem sourceElement, string path, Stack <XmlQualifiedName> parentComplexTypeNames) { XmlQualifiedName qualifiedComplexTypeName = sourceElement.XsdType.QualifiedName; if (parentComplexTypeNames.Contains(qualifiedComplexTypeName)) { return; } string complexTypeName = sourceElement.XsdTypeName; if ((IsMappedToBcc(sourceElement))) { MapComplexTypeToCdt(sourceElement, parentComplexTypeNames, qualifiedComplexTypeName, complexTypeName, path); } else { List <ElementMapping> childMappings = GetChildMappings(sourceElement, parentComplexTypeNames, qualifiedComplexTypeName, path); ComplexTypeMapping complexTypeMapping = CreateComplexTypeMappingForChildMappings(childMappings, sourceElement.XsdTypeName, sourceElement.Name); if (complexTypeMapping != null) { complexTypeMappings.GetAndCreate(complexTypeName).Add(complexTypeMapping); } } }
public AttributeOrSimpleElementOrComplexElementToBccMapping(SourceItem sourceElement, IBcc targetBcc, IMapping bccTypeMapping) : base(sourceElement) { BccTypeMapping = bccTypeMapping; Bcc = targetBcc; Acc = Bcc.Acc; ElementName = sourceElement.Name; }
public override int GetHashCode() { unchecked { return(((SourceItem != null ? SourceItem.GetHashCode() : 0) * 397) ^ (TargetBccs != null ? TargetBccs.GetHashCode() : 0)); } }
private MappingFunction GetMappingFunction(SourceItem element) { if (element.IsMapped) { return(mappingFunctionStore.GetMappingFunction(element.MappingTargetKey)); } return(null); }
private object GetTargetElement(SourceItem element) { if (element.IsMapped) { return(targetElementStore.GetTargetCc(element.MappingTargetKey)); } return(null); }
public override int GetHashCode() { unchecked { int result = (SourceItem != null ? SourceItem.GetHashCode() : 0); result = (result * 397) ^ (Ascc != null ? Ascc.GetHashCode() : 0); result = (result * 397) ^ (Acc != null ? Acc.GetHashCode() : 0); return(result); } }
/// <exception cref="MappingError">Simple typed element mapped to non-BCC CCTS element.</exception> private ElementMapping MapElement(SourceItem sourceElement, string path, Stack <XmlQualifiedName> parentComplexTypeNames) { if (sourceElement.HasSimpleType()) { if (!sourceElement.IsMapped) { // ignore element return(ElementMapping.NullElementMapping); } if (IsMappedToBcc(sourceElement)) { SimpleTypeToCdtMapping simpleTypeToCdtMapping = MapSimpleType(sourceElement); return(new AttributeOrSimpleElementOrComplexElementToBccMapping(sourceElement, (IBcc)GetTargetElement(sourceElement), simpleTypeToCdtMapping)); } if (IsMappedToSup(sourceElement)) { return(new AttributeOrSimpleElementToSupMapping(sourceElement, (ICdtSup)GetTargetElement(sourceElement))); } if (IsMappedToSplitFunction(sourceElement)) { List <SimpleTypeToCdtMapping> simpleTypeToCdtMappings = new List <SimpleTypeToCdtMapping>(); MappingFunction splitFunction = GetMappingFunction(sourceElement); foreach (IBcc targetBcc in splitFunction.TargetCcs) { simpleTypeToCdtMappings.Add(MapSimpleType(sourceElement, targetBcc)); } return(new SplitMapping(sourceElement, splitFunction.TargetCcs.Convert(cc => (IBcc)cc), simpleTypeToCdtMappings)); } throw new MappingError("Simple typed element '" + path + "' mapped to non-BCC CCTS element."); } if (sourceElement.HasComplexType()) { MapComplexType(sourceElement, path, parentComplexTypeNames); if (!sourceElement.IsMapped) { return(new AsmaMapping(sourceElement)); } if (IsMappedToAscc(sourceElement)) { IAscc targetAscc = (IAscc)GetTargetElement(sourceElement); return(new ComplexElementToAsccMapping(sourceElement, targetAscc)); } if (IsMappedToBcc(sourceElement)) { IBcc targetBcc = (IBcc)GetTargetElement(sourceElement); return(new AttributeOrSimpleElementOrComplexElementToBccMapping(sourceElement, targetBcc, null)); } throw new MappingError("Complex typed element '" + path + "' not mapped to either a BCC or an ASCC."); } throw new Exception("Source element '" + path + "' has neither simple nor complex type."); }
private IEnumerable <SourceItem> FindMappedSourceItems(SourceItem sourceItem) { if (sourceItem.MappingTargetKey != null) { yield return(sourceItem); } foreach (SourceItem child in sourceItem.Children) { foreach (SourceItem mappedChildren in FindMappedSourceItems(child)) { yield return(mappedChildren); } } }
private SimpleTypeToCdtMapping MapSimpleType(SourceItem sourceElement, IBcc targetBcc) { var simpleTypeName = sourceElement.XsdTypeName; var cdt = targetBcc.Cdt; foreach (SimpleTypeToCdtMapping simpleTypeMapping in simpleTypeMappings) { if (simpleTypeMapping.SimpleTypeName == simpleTypeName && simpleTypeMapping.TargetCDT.Id == cdt.Id) { return(simpleTypeMapping); } } SimpleTypeToCdtMapping newMapping = new SimpleTypeToCdtMapping(simpleTypeName, cdt); simpleTypeMappings.Add(newMapping); return(newMapping); }
/// <summary> /// Perform name matching between the sub-tree's root element name and element names in the sourceElementTree. /// /// When a matching element is found, attach the sub-tree root's children to the element in the source tree. /// </summary> /// <param name="subTreeRoot"></param> /// <param name="sourceElementTree"></param> private static bool AttachSubTree(SourceItem subTreeRoot, SourceItem sourceElementTree) { bool hasBeenAttached = false; // The al TODO documentation foreach (var child in sourceElementTree.Children) { hasBeenAttached = hasBeenAttached || AttachSubTree(subTreeRoot, child); } if (subTreeRoot.XsdTypeName == sourceElementTree.XsdTypeName) { sourceElementTree.MergeWith(subTreeRoot); hasBeenAttached = true; } return(hasBeenAttached); }
private List <ElementMapping> GetChildMappings(SourceItem sourceElement, Stack <XmlQualifiedName> parentComplexTypeNames, XmlQualifiedName qualifiedComplexTypeName, string path) { List <ElementMapping> childMappings = new List <ElementMapping>(); foreach (var child in sourceElement.Children) { parentComplexTypeNames.Push(qualifiedComplexTypeName); var childMapping = MapElement(child, path + "/" + child.Name, parentComplexTypeNames); parentComplexTypeNames.Pop(); if (childMapping != ElementMapping.NullElementMapping) { elementMappings.Add(childMapping); childMappings.Add(childMapping); } } return(childMappings); }
private void MapComplexTypeToCdt(SourceItem sourceElement, Stack <XmlQualifiedName> parentComplexTypeNames, XmlQualifiedName qualifiedComplexTypeName, string complexTypeName, string path) { ICdt targetCdt = null; ComplexTypeMapping complexTypeMapping; List <ElementMapping> childMappings = GetChildMappings(sourceElement, parentComplexTypeNames, qualifiedComplexTypeName, path); if (childMappings.Count() > 0) { foreach (ElementMapping child in childMappings) { if (child is AttributeOrSimpleElementToSupMapping) { if (targetCdt == null) { targetCdt = ((AttributeOrSimpleElementToSupMapping)child).Cdt; } else { if (targetCdt.Id != ((AttributeOrSimpleElementToSupMapping)child).Cdt.Id) { throw new MappingError("Complex type mapped to more than one CDTs"); } } } } complexTypeMapping = new ComplexTypeToCdtMapping(sourceElement.Name, complexTypeName, childMappings); complexTypeMappings.GetAndCreate(complexTypeName + ((IBcc)GetTargetElement(sourceElement)).Cdt.Name).Add(complexTypeMapping); return; } targetCdt = ((IBcc)GetTargetElement(sourceElement)).Cdt; complexTypeMapping = new ComplexTypeToCdtMapping(sourceElement.Name, complexTypeName, childMappings) { TargetCdt = targetCdt }; complexTypeMappings.GetAndCreate(complexTypeName + ((IBcc)GetTargetElement(sourceElement)).Cdt.Name).Add(complexTypeMapping); }
public AttributeOrSimpleElementToSupMapping(SourceItem sourceElement, ICdtSup targetSup) : base(sourceElement) { Sup = targetSup; Cdt = Sup.Cdt; }
public AsmaMapping(SourceItem sourceElement) : base(sourceElement) { }
public ComplexElementToAsccMapping(SourceItem sourceElement, IAscc targetAscc) : base(sourceElement) { Ascc = targetAscc; Acc = Ascc.AssociatingAcc; }
private SimpleTypeToCdtMapping MapSimpleType(SourceItem sourceElement) { return(MapSimpleType(sourceElement, (IBcc)GetTargetElement(sourceElement))); }
public SplitMapping(SourceItem sourceElement, IEnumerable <IBcc> targetBccs, IEnumerable <SimpleTypeToCdtMapping> cdtMappings) : base(sourceElement) { CdtMappings = new List <SimpleTypeToCdtMapping>(cdtMappings); TargetBccs = new List <IBcc>(targetBccs); }
private bool IsMappedToAscc(SourceItem element) { object targetElement = GetTargetElement(element); return(targetElement != null && targetElement is IAscc); }
private bool IsMappedToSup(SourceItem element) { object targetElement = GetTargetElement(element); return(targetElement != null && targetElement is ICdtSup); }
/// <exception cref="ArgumentException">The MapForce mapping does not contain any input schema components.</exception> public MapForceSourceItemTree(MapForceMapping mapForceMapping, XmlSchemaSet xmlSchemaSet) { this.mapForceMapping = mapForceMapping; xmlSchemaSet.Compile(); /// Retrieve the schema component containing the input schemas' root element. /// /// If there is only one input schema component, then this component is the root schema component. /// /// If there are more than one input schema components, we look for a constant component with value "Root: *", where "*" must /// be the name of the root XSD element of the input schemas. We then return the schema component containing this element as its root. var inputSchemaComponents = new List <SchemaComponent>(mapForceMapping.GetInputSchemaComponents()); var schemaComponentTrees = new List <SourceItem>(); foreach (SchemaComponent inputSchemaComponent in inputSchemaComponents) { XmlSchemaElement rootXsdElement = (XmlSchemaElement)xmlSchemaSet.GlobalElements[inputSchemaComponent.InstanceRoot]; if (rootXsdElement == null) { throw new MappingError("Root element of input schema component [" + inputSchemaComponent.InstanceRoot + "] not found in XSD global elements."); } SourceItem tree = CreateSourceItemTree(inputSchemaComponent.RootEntry, rootXsdElement); schemaComponentTrees.Add(tree); } if (schemaComponentTrees.Count == 0) { throw new MappingError("The MapForce mapping does not contain any input schema components."); } else if (schemaComponentTrees.Count == 1) { RootSourceItem = schemaComponentTrees[0]; } else { var rootElementName = mapForceMapping.GetConstant("Root"); if (string.IsNullOrEmpty(rootElementName)) { throw new MappingError("The MapForce mapping does not specify the root source element name."); } var nonRootElementTrees = new List <SourceItem>(); foreach (SourceItem tree in schemaComponentTrees) { if (tree.Name == rootElementName) { RootSourceItem = tree; } else { nonRootElementTrees.Add(tree); } } if (RootSourceItem == null) { throw new ArgumentException("The MapForce mapping does not contain an input schema component with the specified root element: " + rootElementName); } List <SourceItem> unattachedNonRootItemTrees = new List <SourceItem>(nonRootElementTrees); while (unattachedNonRootItemTrees.Count > 0) { bool atLeastOneTreeAttached = false; foreach (var nonRootElementTree in new List <SourceItem>(unattachedNonRootItemTrees)) { // TODO iteratively attach trees until no attachable trees are left if (AttachSubTree(nonRootElementTree, RootSourceItem)) { atLeastOneTreeAttached = true; unattachedNonRootItemTrees.Remove(nonRootElementTree); } } if (!atLeastOneTreeAttached) { break; } } if (unattachedNonRootItemTrees.Count > 0) { List <string> itemTreeNames = new List <string>(); foreach (SourceItem tree in unattachedNonRootItemTrees) { itemTreeNames.Add(tree.Name); } throw new MappingError("The following schema components could not be attached to the source item tree: " + string.Join(", ", itemTreeNames.ToArray())); } } }
private bool IsMappedToSplitFunction(SourceItem element) { MappingFunction mappingFunction = GetMappingFunction(element); return(mappingFunction != null && mappingFunction.IsSplit); }
private SourceItem CreateSourceItemTree(Entry mapForceEntry, XmlSchemaObject sourceXsdObject) { XmlSchemaType xsdType = GetXsdTypeForXsdObject(sourceXsdObject); var sourceItem = new SourceItem(mapForceEntry.Name, xsdType, mapForceEntry.XsdObjectType, mapForceMapping.GetMappingTargetKey(mapForceEntry.InputOutputKey.Value)); IEnumerable <XmlSchemaObject> childrenOfXsdType = GetChildElementsAndAttributesDefinedByXsdType(sourceItem.XsdType); //HashSet<string> childrenOfXsdTypeNames = new HashSet<string>(); //int unknownChildTypeCount = 0; //foreach (XmlSchemaObject xmlSchemaObject in childrenOfXsdType) //{ // if (xmlSchemaObject is XmlSchemaElement) // { // childrenOfXsdTypeNames.Add("E_" + ((XmlSchemaElement)xmlSchemaObject).QualifiedName.Name); // } // else if (xmlSchemaObject is XmlSchemaAttribute) // { // childrenOfXsdTypeNames.Add("A_" + ((XmlSchemaAttribute)xmlSchemaObject).QualifiedName.Name); // } // else // { // childrenOfXsdTypeNames.Add("Unknown Child Type["+(++unknownChildTypeCount)+"]: " + xmlSchemaObject.GetType().Name); // } //} //HashSet<string> childrenOfMapForceEntryNames = new HashSet<string>(); //foreach (Entry subEntry in mapForceEntry.SubEntries) //{ // switch (subEntry.XsdObjectType) // { // case XsdObjectType.Element: // childrenOfMapForceEntryNames.Add("E_" + subEntry.Name); // break; // case XsdObjectType.Attribute: // childrenOfMapForceEntryNames.Add("A_" + subEntry.Name); // break; // } //} //HashSet<string> mapForceEntriesNotFoundInXsd = new HashSet<string>(childrenOfMapForceEntryNames); //mapForceEntriesNotFoundInXsd.ExceptWith(childrenOfXsdTypeNames); //if (mapForceEntriesNotFoundInXsd.Count > 0) //{ // Console.Out.WriteLine("AAAHHHHHHHHH!!!!!!!!!!!!!!!!!!!!!!"); //} foreach (XmlSchemaObject childOfXsdType in childrenOfXsdType) { Entry mapForceSubEntry; if (childOfXsdType is XmlSchemaElement) { mapForceSubEntry = mapForceEntry.GetSubEntryForElement(((XmlSchemaElement)childOfXsdType).QualifiedName.Name); } else if (childOfXsdType is XmlSchemaAttribute) { mapForceSubEntry = mapForceEntry.GetSubEntryForAttribute(((XmlSchemaAttribute)childOfXsdType).QualifiedName.Name); } else { throw new Exception("Child of XSD Type is neither an XSD Element nor an XSD Attribute. The type of the Child is " + sourceXsdObject.GetType()); } if (mapForceSubEntry != null) { SourceItem sourceItemTreeForChild = CreateSourceItemTree(mapForceSubEntry, childOfXsdType); sourceItem.AddChild(sourceItemTreeForChild); } else { XmlSchemaType xsdTypeForChild = GetXsdTypeForXsdObject(childOfXsdType); if (childOfXsdType is XmlSchemaElement) { sourceItem.AddChild(new SourceItem(((XmlSchemaElement)childOfXsdType).QualifiedName.Name, xsdTypeForChild, XsdObjectType.Element, null)); } if (childOfXsdType is XmlSchemaAttribute) { sourceItem.AddChild(new SourceItem(((XmlSchemaAttribute)childOfXsdType).QualifiedName.Name, xsdTypeForChild, XsdObjectType.Attribute, null)); } } } return(sourceItem); }
protected ElementMapping(SourceItem sourceItem) { SourceItem = sourceItem; }