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 override bool ResolveTypeMapping(SchemaMapping schemaMapping)
        {
            if (BccTypeMapping == null)
            {
                //complexTypeName + ((IBcc)GetTargetElement(sourceElement)).Cdt.Name

                ComplexTypeMapping complexTypeMapping =
                    schemaMapping.GetComplexTypeToCdtMapping(SourceItem.XsdTypeName + Bcc.Cdt.Name);


                //ComplexTypeMapping complexTypeMapping = schemaMapping.GetComplexTypeMapping(sourceElement.XsdType);

                if (!complexTypeMapping.IsMappedToCdt)
                {
                    throw new MappingError("Complex typed element '" + SourceItem.Path +
                                           "' mapped to BCC, but the complex type is not mapped to a CDT.");
                }
                if (complexTypeMapping.TargetCdt.Id != Bcc.Cdt.Id)
                {
                    throw new MappingError("Complex typed element '" + SourceItem.Path +
                                           "' mapped to BCC with CDT other than the target CDT for the complex type.");
                }
                BccTypeMapping = complexTypeMapping;
            }
            return(true);
        }
 protected bool ChildrenEqual(ComplexTypeMapping other)
 {
     if (other.children.Count != children.Count)
     {
         return(false);
     }
     for (int i = 0; i < children.Count; i++)
     {
         if (!Equals(other.children[i], children[i]))
         {
             return(false);
         }
     }
     return(true);
 }
        private AbieSpec GenerateAbieSpec(ComplexTypeMapping complexTypeMapping, IAcc acc, string name)
        {
            List <BbieSpec> bbieSpecs = new List <BbieSpec>();

            bbieSpecs.AddRange(GenerateBbieSpecs(complexTypeMapping.BccMappings(acc)));
            bbieSpecs.AddRange(GenerateBbieSpecs(complexTypeMapping.SplitMappings(), acc));

            var abieSpec = new AbieSpec
            {
                BasedOn = acc,
                Name    = name,
                Bbies   = bbieSpecs,
            };

            abieSpecs.Add(abieSpec);
            asbiesToGenerate.GetAndCreate(name).AddRange(DetermineAsbiesToGenerate(complexTypeMapping.AsccMappings(acc)));
            return(abieSpec);
        }
        private static ComplexTypeMapping GetComplexTypeMappingWithMostChildren(List <ComplexTypeMapping> mappings)
        {
            if (mappings.Count > 0)
            {
                ComplexTypeMapping complexTypeMapping = mappings[0];

                foreach (ComplexTypeMapping mapping in mappings)
                {
                    if (mapping.NumberOfChildren > complexTypeMapping.NumberOfChildren)
                    {
                        complexTypeMapping = mapping;
                    }
                }

                return(complexTypeMapping);
            }
            return(ComplexTypeMapping.NullComplexTypeMapping);
        }
        public override bool ResolveTypeMapping(SchemaMapping schemaMapping)
        {
            ComplexTypeMapping complexTypeMapping = schemaMapping.GetComplexTypeMapping(SourceItem.XsdType);

            if (!complexTypeMapping.IsMappedToSingleACC)
            {
                throw new MappingError("Complex typed element '" + SourceItem.Path +
                                       "' mapped to ASCC, but the complex type is not mapped to a single ACC: TargetACCs: [" + string.Join(", ", complexTypeMapping.TargetACCs.Select(acc => acc.Name).ToArray()) + "], number of children mapped to ASMAs: " + complexTypeMapping.AsmaMappings.Count() + ".");
            }
            IAcc complexTypeACC = complexTypeMapping.TargetACCs.ElementAt(0);

            if (complexTypeACC.Id != Ascc.AssociatedAcc.Id)
            {
                throw new MappingError("Complex typed element '" + SourceItem.Path +
                                       "' mapped to ASCC with associated ACC other than the target ACC for the complex type.");
            }
            TargetMapping = complexTypeMapping;
            return(true);
        }
        private void GenerateBdtSpecsFromComplexTypeMapping(ComplexTypeMapping complexTypeMapping)
        {
            if (complexTypeMapping is ComplexTypeToCdtMapping)
            {
                ComplexTypeToCdtMapping cdtMapping = (ComplexTypeToCdtMapping)complexTypeMapping;

                List <BdtSupSpec> supSpecs = new List <BdtSupSpec>();

                foreach (AttributeOrSimpleElementToSupMapping supMapping in cdtMapping.GetSupMappings())
                {
                    BdtSupSpec bdtSupSpec = BdtSpec.CloneCdtSup(supMapping.Sup);
                    bdtSupSpec.Name = supMapping.BIEName;
                    supSpecs.Add(bdtSupSpec);
                }

                BdtSpec bdtSpec = BdtSpec.CloneCdt(complexTypeMapping.TargetCdt, complexTypeMapping.BIEName);

                bdtSpec.Sups = supSpecs;

                bdtSpecs.Add(bdtSpec);
            }
        }
        private void GenerateAbieAndMaSpecsFromComplexTypeMapping(ComplexTypeMapping complexTypeMapping)
        {
            if (complexTypeMapping is ComplexTypeToAccMapping)
            {
                GenerateAbieSpec(complexTypeMapping, complexTypeMapping.TargetACCs.ElementAt(0), complexTypeMapping.BIEName);
            }
            else if (complexTypeMapping is ComplexTypeToMaMapping)
            {
                string maName = complexTypeMapping.ComplexTypeName;

                maSpecs.Add(new MaSpec
                {
                    Name = maName,
                });

                List <AsmaToGenerate> asmasToGenerateForThisMa = asmasToGenerate.GetAndCreate(maName);

                foreach (IAcc acc in complexTypeMapping.TargetACCs)
                {
                    var accABIESpec = GenerateAbieSpec(complexTypeMapping, acc, complexTypeMapping.ComplexTypeName + "_" + acc.Name);
                    asmasToGenerateForThisMa.Add(new AsmaToGenerate(bieLibrary, acc.Name, accABIESpec.Name));
                }

                foreach (var asmaMapping in complexTypeMapping.AsmaMappings)
                {
                    if (asmaMapping.TargetMapping is ComplexTypeToAccMapping)
                    {
                        asmasToGenerateForThisMa.Add(new AsmaToGenerate(bieLibrary, asmaMapping.BIEName,
                                                                        asmaMapping.TargetMapping.BIEName));
                    }
                    else
                    {
                        asmasToGenerateForThisMa.Add(new AsmaToGenerate(docLibrary, asmaMapping.BIEName,
                                                                        asmaMapping.TargetMapping.BIEName));
                    }
                }
            }
        }
        public SchemaMapping(MapForceMapping mapForceMapping, XmlSchemaSet xmlSchemaSet, ICcLibrary ccLibrary, ICctsRepository cctsRepository)
        {
            sourceItemStore = new MapForceSourceItemTree(mapForceMapping, xmlSchemaSet);

            targetElementStore = new TargetElementStore(mapForceMapping, ccLibrary, cctsRepository);

            mappingFunctionStore = new MappingFunctionStore(mapForceMapping, targetElementStore);

            RootElementMapping = MapElement(sourceItemStore.RootSourceItem, "/" + sourceItemStore.RootSourceItem.Name, new Stack <XmlQualifiedName>());

            elementMappings.Add(RootElementMapping);

            elementMappings = new List <ElementMapping>(ResolveTypeMappings(elementMappings));

            foreach (KeyValuePair <string, List <ComplexTypeMapping> > pair in complexTypeMappings)
            {
                foreach (ComplexTypeMapping complexTypeMapping in pair.Value)
                {
                    complexTypeMapping.RemoveInvalidAsmaMappings();
                }
            }

            Dictionary <string, List <ComplexTypeMapping> > relevantComplexTypeMappings = new Dictionary <string, List <ComplexTypeMapping> >();

            foreach (KeyValuePair <string, List <ComplexTypeMapping> > pair in complexTypeMappings)
            {
                string             complexTypeName = pair.Key;
                ComplexTypeMapping relevantMapping = GetComplexTypeMappingWithMostChildren(pair.Value);
                if (relevantMapping is ComplexTypeToMaMapping)
                {
                    relevantMapping = CreateComplexTypeMappingForChildMappings(relevantMapping.Children, complexTypeName, relevantMapping.SourceElementName);
                }
                if (relevantMapping != null)
                {
                    relevantComplexTypeMappings[complexTypeName] = new List <ComplexTypeMapping> {
                        relevantMapping
                    };
                }
            }
            complexTypeMappings = relevantComplexTypeMappings;

            foreach (ElementMapping elementMapping in elementMappings)
            {
                if (elementMapping is AsmaMapping)
                {
                    AsmaMapping        asmaMapping        = (AsmaMapping)elementMapping;
                    ComplexTypeMapping complexTypeMapping = CreateComplexTypeMappingForChildMappings(asmaMapping.TargetMapping.Children, asmaMapping.TargetMapping.ComplexTypeName, asmaMapping.TargetMapping.SourceElementName);
                    asmaMapping.TargetMapping = complexTypeMapping;
                }
            }

            foreach (KeyValuePair <string, List <ComplexTypeMapping> > pair in complexTypeMappings)
            {
                foreach (ComplexTypeMapping complexTypeMapping in pair.Value)
                {
                    complexTypeMapping.RemoveInvalidAsmaMappings();
                }
            }


            // The following lines of code were used for the CEC 2010 paper evaluation.

            //Console.Out.WriteLine("Kennzahl 3 (implizite Mappings): haendisch");
            //Console.Out.WriteLine("Kennzahl 4 (Anzahl der gemappten Elemente)): " + (elementMappings.Count + simpleTypeMappings.Count + complexTypeMappings.Count));

            //Console.Out.WriteLine("Importer Kennzahl 3a (anhand elementMapping variable): " + elementMappings.Count);
            //Console.Out.WriteLine("Importer Kennzahl 3b (anhand simpleTypeMappings): " + simpleTypeMappings.Count);
            //Console.Out.WriteLine("Importer Kennzahl 3c (anhand complexTypeMappings): " + complexTypeMappings.Count);
        }