///<summary>
        ///</summary>
        ///<param name="context"></param>
        public static void GenerateXSD(GeneratorContext context)
        {
            globalAsmas = new List <string>();
            IMa documentRoot = context.DocLibrary.DocumentRoot;
            var schema       = new XmlSchema
            {
                TargetNamespace = context.TargetNamespace
            };

            schema.Namespaces.Add(context.NamespacePrefix, context.TargetNamespace);
            schema.Namespaces.Add("xsd", "http://www.w3.org/2001/XMLSchema");
            schema.Namespaces.Add("ccts",
                                  "urn:un:unece:uncefact:documentation:standard:XMLNDRDocumentation:3");
            schema.Namespaces.Add(NSPREFIX_BDT, context.TargetNamespace);
            schema.Namespaces.Add(NSPREFIX_BIE, context.TargetNamespace);

            schema.ElementFormDefault   = XmlSchemaForm.Qualified;
            schema.AttributeFormDefault = XmlSchemaForm.Unqualified;
            schema.Version = context.DocLibrary.VersionIdentifier.DefaultTo("1");

            //TODO how do i now what schemas to include and what to import
            AddImports(schema, context, context.DocLibrary);
            AddIncludes(schema, context, context.DocLibrary);

            AddRootElementDeclaration(schema, documentRoot, context);
            AddRootTypeDefinition(schema, documentRoot, context, context.DocLibrary);

            IEnumerable <IMa> nonRootDocLibraryElements = context.DocLibrary.NonRootMas;

            AddGlobalElementDeclarations(schema, nonRootDocLibraryElements, context);
            AddGlobalTypeDefinitions(schema, nonRootDocLibraryElements, context);
            context.AddSchema(schema, documentRoot.Name + "_" + schema.Version + ".xsd");
        }
 private void followAsmasAndRemoveUnused(IMa rootMa)
 {
     foreach (IAsma asma in rootMa.Asmas)
     {
         if (asma.AssociatedBieAggregator.IsMa)
         {
             followAsmasAndRemoveUnused(asma.AssociatedBieAggregator.Ma);
         }
         if (asma.AssociatedBieAggregator.IsAbie)
         {
             List <CheckableTreeViewItem> result =
                 findCheckableTreeViewItems(asma.AssociatedBieAggregator.Abie.Name,
                                            mCandidateAbieItems);
             if (result == null)
             {
                 rootMa.RemoveAsma(asma);
             }
             else
             {
                 if (testIfAllCheckableTreeViewItemsAreUnchecked(result))
                 {
                     rootMa.RemoveAsma(asma);
                 }
             }
         }
     }
 }
        public static XmlSchema GenerateXSD(GeneratorContext context)
        {
            string targetNameSpace = NDR.getTargetNameSpace(context, false);
            IMa    documentRoot    = context.DocLibrary.DocumentRoot;
            var    schema          = new XmlSchema
            {
                TargetNamespace = targetNameSpace
            };

            //namespaces
            schema.Namespaces.Add("xsd", "http://www.w3.org/2001/XMLSchema");
            schema.Namespaces.Add(context.NamespacePrefix, targetNameSpace);
            //qualifiedSetting
            schema.ElementFormDefault   = XmlSchemaForm.Qualified;
            schema.AttributeFormDefault = XmlSchemaForm.Unqualified;
            //version
            schema.Version = context.DocLibrary.VersionIdentifier.DefaultTo("1");

            string schemaFileName = getSchemaFileName(context, false);

            AddRootElementDeclaration(schema, documentRoot, context);
            GenerateComplexTypeForMa(context, schema, documentRoot);

            //non root elements, not used
            IEnumerable <IMa> nonRootDocLibraryElements = context.DocLibrary.NonRootMas;

            AddGlobalTypeDefinitions(schema, nonRootDocLibraryElements, context);
            AddGlobalElementDeclarations(schema, nonRootDocLibraryElements, context);

            context.AddSchema(schema, schemaFileName, UpccSchematype.ROOT);
            return(schema);
        }
        private ObservableCollection <CheckableTreeViewItem> findChildren(CheckableTreeViewItem parent, IMa root)
        {
            var         tempList   = new ObservableCollection <CheckableTreeViewItem>();
            IEnumerator enumerator = root.Asmas.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var currentAsma = (IAsma)enumerator.Current;
                if (currentAsma.AssociatedBieAggregator.IsAbie)
                {
                    IAbie currentAbie = currentAsma.AssociatedBieAggregator.Abie;
                    if (findAbie(currentAbie.Name, rootElement.CandidateAbies) == null)
                    {
                        rootElement.CandidateAbies.Add(new CandidateAbie(currentAbie,
                                                                         AbieFindChildren(currentAbie)));
                    }
                    var currentItem = new CheckableTreeViewItem(true, currentAbie.Name, idCounter++);
                    currentItem.Children = findChildren(currentItem, currentAbie);
                    currentItem.Parent   = parent;
                    tempList.Add(currentItem);
                }
                else if (currentAsma.AssociatedBieAggregator.IsMa)
                {
                    IMa currentMa = currentAsma.AssociatedBieAggregator.Ma;

                    var currentItem = new CheckableTreeViewItem(currentMa.Name, idCounter++);
                    currentItem.Children = findChildren(currentItem, currentMa);
                    currentItem.Parent   = parent;
                    tempList.Add(currentItem);
                }
            }
            return(tempList);
        }
        private void CalculateDiffForMas(IMa maComplete, IMa maSubset, Dictionary <string, List <string> > diff)
        {
            Dictionary <string, IAsma> childAsmasOfSubset = new Dictionary <string, IAsma>();

            foreach (IAsma childAsmaOfSubset in maSubset.Asmas)
            {
                childAsmasOfSubset.Add(childAsmaOfSubset.Name, childAsmaOfSubset);
            }

            foreach (IAsma childAsmaOfComplete in maComplete.Asmas)
            {
                if (childAsmasOfSubset.ContainsKey(childAsmaOfComplete.Name))
                {
                    BieAggregator bieAggregatorOfComplete = childAsmaOfComplete.AssociatedBieAggregator;

                    if (bieAggregatorOfComplete.IsMa)
                    {
                        CalculateDiffForMas(bieAggregatorOfComplete.Ma, childAsmasOfSubset[childAsmaOfComplete.Name].AssociatedBieAggregator.Ma, diff);
                    }
                    else if (bieAggregatorOfComplete.IsAbie)
                    {
                        CalculateDiffForAbie(bieAggregatorOfComplete.Abie, childAsmasOfSubset[childAsmaOfComplete.Name].AssociatedBieAggregator.Abie, diff);
                    }
                }
                else
                {
                    // den subtree welcher am asma haengt entfernen
                }
            }
        }
 public static MaSpec CloneMa(IMa ma)
 {
     return(new MaSpec
     {
         Name = ma.Name,
         Asmas = new List <AsmaSpec>(ma.Asmas.Convert(o => AsmaSpec.CloneAsma(o))),
     });
 }
        private static void AddRootElementDeclaration(XmlSchema schema, IMa ma, GeneratorContext context)
        {
            var root = new XmlSchemaElement
            {
                Name           = ma.Name,
                SchemaTypeName =
                    new XmlQualifiedName(context.NamespacePrefix + ":" + ma.Name + "Type")
            };

            schema.Items.Add(root);
        }
        public Dictionary <string, List <string> > CalculateDiff()
        {
            Dictionary <string, List <string> > diff = new Dictionary <string, List <string> >();

            IMa documentRootComplete = docLibraryComplete.DocumentRoot;
            IMa documentRootSubset   = docLibrarySubset.DocumentRoot;

            CalculateDiffForMas(documentRootComplete, documentRootSubset, diff);

            return(diff);
        }
 private void LoadDOC(ICctsRepository repository)
 {
     DocL     = repository.GetDocLibraryById(Id);
     Document = DocL.DocumentRoot;
     if (_Document != null && _DocL != null)
     {
         DOC = new cDOC(Document.Name, Document.Id, CheckState.Unchecked, DocL.BaseURN, DocL.NamespacePrefix, this);
     }
     else
     {
         DOC = null;
     }
 }
        private static XmlSchemaAnnotation GetMaAnnotation(IMa ma)
        {
            // Contains all the documentation items such as DictionaryEntryName
            IList <XmlNode> documentation = new List <XmlNode>();

            BIESchemaGenerator.AddDocumentation(documentation, "ObjectClassTermName", ma.Name);
            BIESchemaGenerator.AddDocumentation(documentation, "AcronymCode", "MA");

            var annotation = new XmlSchemaAnnotation();

            annotation.Items.Add(new XmlSchemaDocumentation {
                Language = "en", Markup = documentation.ToArray()
            });

            return(annotation);
        }
Beispiel #11
0
 public void LoadDOC(ICctsRepository repository)
 {
     if (DOC == null)
     {
         IDocLibrary docl     = repository.GetDocLibraryById(Id);
         IMa         document = docl.DocumentRoot;
         if (document != null)
         {
             DOC = new cDOC(document.Name, document.Id, CheckState.Unchecked, docl.BaseURN, docl.NamespacePrefix);
         }
         else
         {
             throw new CacheException("No Document root found!");
         }
     }
 }
        private void Compile(IDocLibrary docLibrary)
        {
            IMa           documentRoot  = docLibrary.DocumentRoot;
            IAsma         asma          = documentRoot.Asmas.FirstOrDefault();
            BieAggregator bieAggregator = asma.AssociatedBieAggregator;

            if (bieAggregator.IsMa)
            {
                CompileXsdTypesFromMa(bieAggregator.Ma);
            }
            else if (bieAggregator.IsAbie)
            {
                CompileXsdTypesFromAbie(bieAggregator.Abie);
            }
            else
            {
                throw new Exception("The ASMA " + asma.Name + " of the Document Root Element " + documentRoot.Name + " neither aggregates a MA nor an ABIE.");
            }
        }
Beispiel #13
0
        private static bool PruneMa(IMa ma)
        {
            if (!alreadyPrunedItems.Contains(ma.Id))
            {
                alreadyPrunedItems.Add(ma.Id);

                List <IAsma> asmas = new List <IAsma>(ma.Asmas);

                foreach (IAsma asma in asmas)
                {
                    if (asma.AssociatedBieAggregator.IsMa)
                    {
                        IMa associatedMa = asma.AssociatedBieAggregator.Ma;

                        if (PruneMa(associatedMa))
                        {
                            masToBeRemoved.Add(associatedMa.Id);
                            ma.RemoveAsma(asma);
                        }
                    }
                    else if (asma.AssociatedBieAggregator.IsAbie)
                    {
                        IAbie abie = asma.AssociatedBieAggregator.Abie;

                        if (PruneAbie(abie))
                        {
                            abiesToBeRemoved.Add(abie.Id);
                            ma.RemoveAsma(asma);
                        }
                    }
                }

                if (ma.Asmas.Count() == 0)
                {
                    return(true);
                }

                return(false);
            }
            return(masToBeRemoved.Contains(ma.Id));
        }
        private void CompileXsdTypesFromMa(IMa ma)
        {
            if (!alreadyCompiledTypes.Contains(ma.Id))
            {
                alreadyCompiledTypes.Add(ma.Id);

                XsdType xsdType = AddXsdType(ma.Name);

                foreach (IAsma asma in ma.Asmas)
                {
                    BieAggregator bieAggregator = asma.AssociatedBieAggregator;

                    if (bieAggregator.IsMa)
                    {
                        xsdType.AddChild(asma.Name);

                        CompileXsdTypesFromMa(bieAggregator.Ma);
                    }
                    else if (bieAggregator.IsAbie)
                    {
                        //if (bieAggregator.Name == "PaymentConditionsType_PaymentTerms")
                        //{
                        //    int y = 1;
                        //}

                        // BUG FIX:
                        xsdType.AddChild(asma.Name);

                        // In case that trough the ASMA aggregated element is an ABIE,
                        // then the ASMA is not an actual complex element of the MA's
                        // complex type.
                        CompileXsdTypesFromAbie(bieAggregator.Abie);
                    }
                    else
                    {
                        throw new Exception("The ASMA " + asma.Name + " of the MA " + ma.Name +
                                            " neither aggregates a MA nor an ABIE.");
                    }
                }
            }
        }
        public void Test_mapping_complex_type_with_nested_complex_type_to_single_acc()
        {
            string mappingFile = TestUtils.PathToTestResource(@"XSDImporterTest\mapping\MappingImporterTests\mapping_complex_type_with_nested_complex_type_to_single_acc\mapping.mfd");

            string[] schemaFiles = new[] { TestUtils.PathToTestResource(@"XSDImporterTest\mapping\MappingImporterTests\mapping_complex_type_with_nested_complex_type_to_single_acc\source.xsd") };


            new MappingImporter(new[] { mappingFile }, schemaFiles, ccLibrary, bLibrary, DocLibraryName, BieLibraryName, BdtLibraryName, Qualifier, RootElementName, cctsRepository).ImportMapping();

            var bieLibrary = ShouldContainBieLibrary(BieLibraryName);
            var docLibrary = ShouldContainDocLibrary(DocLibraryName);

            IBdtLibrary bdtLibrary = ShouldContainBdtLibrary(BdtLibraryName);

            IBdt bdtText = ShouldContainBdt(bdtLibrary, "String_Text", "Text", null);

            Assert.That(bdtLibrary.Bdts.Count(), Is.EqualTo(1));

            IAbie bieAddress = ShouldContainAbie(bieLibrary, "AddressType_Address", "Address", new[] { new BbieDescriptor("Town_CityName", bdtText.Id) }, null);

            IAbie biePerson = ShouldContainAbie(bieLibrary, "PersonType_Party", "Party", new[] { new BbieDescriptor("Name_Name", bdtText.Id), }, new[]
            {
                new AsbieDescriptor("Address_Residence", bieAddress.Id),
            });



            IMa maInvoice = ShouldContainMa(docLibrary, "InvoiceType", new[]
            {
                new AsmaDescriptor("Person", biePerson.Id),
            });

            ShouldContainMa(docLibrary, "test_Invoice", new[]
            {
                new AsmaDescriptor("Invoice", maInvoice.Id),
            });
        }
Beispiel #16
0
 public CandidateRootElement(IMa ma)
 {
     OriginalMa     = ma;
     Selected       = false;
     CandidateAbies = null;
 }
        private static void GenerateComplexTypeForMa(GeneratorContext context, XmlSchema schema, IMa ma)
        {
            var maType = new XmlSchemaComplexType();

            maType.Name = ma.Name + "Type";

            var sequence = new XmlSchemaSequence();

            foreach (IAsma asma in ma.Asmas)
            {
                var rasmaElement = new XmlSchemaElement();
                rasmaElement.Name           = NDR.GetXsdElementNameFromAsma(asma);
                rasmaElement.SchemaTypeName = new XmlQualifiedName(context.NamespacePrefix + ":" +
                                                                   NDR.TrimElementName(asma.AssociatedBieAggregator.Name));
                // R 90F9: cardinality of elements within the ABIE
                rasmaElement.MinOccursString = AdjustBound(asma.LowerBound);
                rasmaElement.MaxOccursString = AdjustBound(asma.UpperBound);
                //add to the sequence
                sequence.Items.Add(rasmaElement);
            }
            //set the sequence as particle of the ma complex type
            maType.Particle = sequence;
            //add the maType to the schema
            schema.Items.Add(maType);
        }
Beispiel #18
0
 public UpccAsma(IUmlAssociation umlAssociation, IMa associatingMa) : base(umlAssociation, associatingMa)
 {
 }
        private static XmlSchemaComplexType GenerateComplexTypeForMa(GeneratorContext context, XmlSchema schema, IMa ma, string abiePrefix)
        {
            var maType = new XmlSchemaComplexType();

            maType.Name = ma.Name + "Type";

            var sequence = new XmlSchemaSequence();

            foreach (IAsma asma in ma.Asmas.OrderBy(a => a.Name))
            {
                XmlSchemaElement elementAsma = null;

                // Take care of ASMAS aggregating ABIEs
                if (asma.AssociatedBieAggregator.IsAbie)
                {
                    elementAsma = new XmlSchemaElement
                    {
                        Name           = NDR.GetXsdElementNameFromAsma(asma),
                        SchemaTypeName =
                            new XmlQualifiedName(NSPREFIX_BIE + ":" +
                                                 asma.AssociatedBieAggregator.Name +
                                                 "Type")
                    };
                }
                else if (asma.AssociatedBieAggregator.IsMa)
                {
                    elementAsma = new XmlSchemaElement
                    {
                        Name           = NDR.GetXsdElementNameFromAsma(asma),
                        SchemaTypeName =
                            new XmlQualifiedName(context.NamespacePrefix + ":" +
                                                 asma.AssociatedBieAggregator.Name +
                                                 "Type")
                    };
                }

                var refAsma = new XmlSchemaElement
                {
                    RefName =
                        new XmlQualifiedName(context.NamespacePrefix + ":" +
                                             NDR.GetXsdElementNameFromAsma(asma))
                };

                // every shared ASCC may only appear once in the XSD file
                if (!globalAsmas.Contains(elementAsma.Name))
                {
                    // R 9241: for ASBIEs with AggregationKind = shared a global element must be declared.
                    schema.Items.Add(elementAsma);
                    globalAsmas.Add(elementAsma.Name);
                }

                sequence.Items.Add(refAsma);
            }
            maType.Particle = sequence;
            if (context.Annotate)
            {
                maType.Annotation = GetMaAnnotation(ma);
            }

            return(maType);
        }
Beispiel #20
0
 /// <summary>
 /// Removes a MA from this DOCLibrary.
 /// <param name="ma">A MA.</param>
 /// </summary>
 public void RemoveMa(IMa ma)
 {
     UmlPackage.RemoveClass(((UpccMa)ma).UmlClass);
 }
Beispiel #21
0
 /// <summary>
 /// Updates a MA to match the given <paramref name="specification"/>.
 /// <param name="ma">A MA.</param>
 /// <param name="specification">A new specification for the given MA.</param>
 /// <returns>The updated MA. Depending on the implementation, this might be the same updated instance or a new instance!</returns>
 /// </summary>
 public IMa UpdateMa(IMa ma, MaSpec specification)
 {
     return(new UpccMa(UmlPackage.UpdateClass(((UpccMa)ma).UmlClass, MaSpecConverter.Convert(specification))));
 }
 public void RemoveMa(IMa ma)
 {
     throw new NotImplementedException();
 }
 private List <AsmaSpec> GenerateAsmaSpecsForMa(IMa ma)
 {
     return(asmasToGenerate.GetAndCreate(ma.Name).ConvertAll(asmaToGenerate => asmaToGenerate.GenerateSpec()));
 }
 /// <summary>
 /// Returns an array of the associated element IDs of all ASMAs of the given MA.
 /// </summary>
 /// <param name="ma"></param>
 /// <returns></returns>
 private static AsmaDescriptor[] AsmaDescriptors(IMa ma)
 {
     return((from asma in ma.Asmas select new AsmaDescriptor(asma.Name, asma.AssociatedBieAggregator.Id)).ToArray());
 }
 public IMa UpdateMa(IMa ma, MaSpec specification)
 {
     throw new NotImplementedException();
 }
Beispiel #26
0
 ///<summary>
 ///</summary>
 ///<param name="ma"></param>
 public static XmlSchemaAnnotation GetMaAnnotation(IMa ma)
 {
     //throw new NotImplementedException();
     return(null);
 }
Beispiel #27
0
 public UpccAsma(IUmlAssociation umlAssociation, IMa associatingMa)
 {
     UmlAssociation = umlAssociation;
     AssociatingMa  = associatingMa;
 }