private void GenerateRootABIE()
        {
            var rootElementMapping = schemaMapping.RootElementMapping;

            if (rootElementMapping is AsmaMapping)
            {
                AsmaMapping asmaMapping = (AsmaMapping)rootElementMapping;
                var         ma          = docLibrary.CreateMa(new MaSpec
                {
                    Name = qualifier + "_" + rootElementName,
                });
                AsmaSpec asmaSpec = new AsmaSpec
                {
                    Name = asmaMapping.SourceElementName,
                };
                if (asmaMapping.TargetMapping is ComplexTypeToAccMapping)
                {
                    asmaSpec.AssociatedBieAggregator =
                        new BieAggregator(bieLibrary.GetAbieByName(asmaMapping.TargetMapping.BIEName));
                }
                else
                {
                    asmaSpec.AssociatedBieAggregator =
                        new BieAggregator(docLibrary.GetMaByName(asmaMapping.TargetMapping.BIEName));
                }
                ma.CreateAsma(asmaSpec);
            }
            else if (rootElementMapping is AttributeOrSimpleElementOrComplexElementToBccMapping)
            {
                var bccMapping = (AttributeOrSimpleElementOrComplexElementToBccMapping)rootElementMapping;
                var abie       = bieLibrary.CreateAbie(new AbieSpec
                {
                    BasedOn = bccMapping.Acc,
                    Name    = qualifier + "_" + bccMapping.Acc.Name,
                    Bbies   = new List <BbieSpec>(GenerateBbieSpecs(new List <AttributeOrSimpleElementOrComplexElementToBccMapping> {
                        bccMapping
                    })),
                });
                var ma = docLibrary.CreateMa(new MaSpec
                {
                    Name = qualifier + "_" + rootElementName,
                });
                ma.CreateAsma(new AsmaSpec
                {
                    Name = abie.Name,
                    AssociatedBieAggregator = new BieAggregator(abie),
                });
            }
            else
            {
                throw new MappingError("Root element can only be mapped to BCC, but is mapped to something else.");
            }
        }
        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);
        }