-
Notifications
You must be signed in to change notification settings - Fork 6
55 feature implement xmi deserializer #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
antoineatstariongroup
merged 5 commits into
development
from
55-feature-implement-xmi-deserializer
Feb 9, 2026
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
255555f
WIP: CodeGen part done, need to implement deserializer logic
antoineatstariongroup 866306f
WIP: DeSerializer nearly completed
antoineatstariongroup 1e9dbb7
Finalizes XMI Reader
antoineatstariongroup 74a33b3
Bump targetFramework post rebase
antoineatstariongroup 9814d99
Update year in header file
antoineatstariongroup File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
299 changes: 299 additions & 0 deletions
299
SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenReaders/AnnotatingElementReader.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,299 @@ | ||
| // ------------------------------------------------------------------------------------------------- | ||
| // <copyright file="AnnotatingElementReader.cs" company="Starion Group S.A."> | ||
| // | ||
| // Copyright 2022-2025 Starion Group S.A. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // </copyright> | ||
| // ------------------------------------------------------------------------------------------------ | ||
|
|
||
| // ------------------------------------------------------------------------------------------------ | ||
| // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- | ||
| // ------------------------------------------------------------------------------------------------ | ||
|
|
||
| namespace SysML2.NET.Serializer.Xmi.Readers | ||
| { | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Xml; | ||
|
|
||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Extensions.Logging.Abstractions; | ||
|
|
||
| using SysML2.NET.Common; | ||
| using SysML2.NET.Core.POCO.Root.Elements; | ||
| using SysML2.NET.Core.POCO.Root.Namespaces; | ||
| using SysML2.NET.Core.POCO.Root.Annotations; | ||
|
|
||
| /// <summary> | ||
| /// The purpose of the <see cref="{this.Name}}Reader" /> is to read an instance of <see cref="I{this.Name}}" /> | ||
| /// from the XMI document | ||
| /// </summary> | ||
| public class AnnotatingElementReader : XmiDataReader<IAnnotatingElement> | ||
| { | ||
| /// <summary> | ||
| /// The instantiated logger from the injected <see cref="ILoggerFactory" /> | ||
| /// </summary> | ||
| private readonly ILogger<AnnotatingElementReader> logger; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AnnotatingElementReader" /> | ||
| /// </summary> | ||
| /// <param name="cache"> | ||
| /// The injected <see cref="IXmiDataCache" /> used cache to store and resolve <see cref="IData" /> | ||
| /// </param> | ||
| /// <param name="xmiDataReaderFacade"> | ||
| /// The injected <see cref="IXmiDataReaderFacade" /> that provides | ||
| /// <see cref="XmiDataReader{TData}" /> resolve | ||
| /// </param> | ||
| /// <param name="externalReferenceService">The injected <see cref="IExternalReferenceService"/> used to register and process external references</param> | ||
| /// <param name="loggerFactory">The injected <see cref="ILoggerFactory" /> used to set up logging</param> | ||
| public AnnotatingElementReader(IXmiDataCache cache, IXmiDataReaderFacade xmiDataReaderFacade, IExternalReferenceService externalReferenceService, ILoggerFactory loggerFactory) : base(cache, xmiDataReaderFacade, externalReferenceService, loggerFactory) | ||
| { | ||
| this.logger = loggerFactory == null ? NullLogger<AnnotatingElementReader>.Instance : loggerFactory.CreateLogger<AnnotatingElementReader>(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Reads the <see cref="IAnnotatingElement" /> object from its XML representation | ||
| /// </summary> | ||
| /// <param name="xmiReader">An instance of <see cref="XmlReader" /></param> | ||
| /// <param name="currentLocation">The <see cref="Uri" /> that keep tracks of the current location</param> | ||
| /// <returns>The read <see cref="IAnnotatingElement" /></returns> | ||
| public override IAnnotatingElement Read(XmlReader xmiReader, Uri currentLocation) | ||
| { | ||
| if (xmiReader == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(xmiReader)); | ||
| } | ||
|
|
||
| var xmlLineInfo = xmiReader as IXmlLineInfo; | ||
|
|
||
| IAnnotatingElement poco = new SysML2.NET.Core.POCO.Root.Annotations.AnnotatingElement(); | ||
|
|
||
| if (xmiReader.MoveToContent() == XmlNodeType.Element) | ||
| { | ||
| this.logger.LogTrace("reading AnnotatingElement at line:position {LineNumber}:{LinePosition}", xmlLineInfo?.LineNumber, xmlLineInfo?.LinePosition); | ||
| var xsiType = xmiReader.GetAttribute("xsi:type"); | ||
|
|
||
| if (!string.IsNullOrEmpty(xsiType) && xsiType != "sysml:AnnotatingElement") | ||
| { | ||
| throw new InvalidOperationException($"The xsi:type {xsiType} is not supported by the AnnotatingElementReader"); | ||
| } | ||
|
|
||
| var xmiId = xmiReader.GetAttribute("xmi:id"); | ||
|
|
||
| if (!Guid.TryParse(xmiId, out var guid)) | ||
| { | ||
| throw new InvalidOperationException($"The xmi:id {xmiId} could not be parsed"); | ||
| } | ||
|
|
||
| poco.Id = guid; | ||
|
|
||
| if (!this.Cache.TryAdd(poco) && this.logger.IsEnabled(LogLevel.Critical)) | ||
| { | ||
| this.logger.LogCritical("Failed to add element type [{Poco}] with id [{Id}] as it was already in the Cache. The XMI document seems to have duplicate xmi:id values", "AnnotatingElement", poco.Id); | ||
| } | ||
|
|
||
| var aliasIdsXmlAttribute = xmiReader.GetAttribute("aliasIds"); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(aliasIdsXmlAttribute)) | ||
| { | ||
| foreach (var aliasIdsXmlAttributeValue in aliasIdsXmlAttribute.Split(SplitMultiReference, StringSplitOptions.RemoveEmptyEntries)) | ||
| { | ||
| poco.AliasIds.Add(aliasIdsXmlAttributeValue); | ||
| } | ||
| } | ||
|
|
||
| var declaredNameXmlAttribute = xmiReader.GetAttribute("declaredName"); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(declaredNameXmlAttribute)) | ||
| { | ||
| poco.DeclaredName = declaredNameXmlAttribute; | ||
| } | ||
|
|
||
| var declaredShortNameXmlAttribute = xmiReader.GetAttribute("declaredShortName"); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(declaredShortNameXmlAttribute)) | ||
| { | ||
| poco.DeclaredShortName = declaredShortNameXmlAttribute; | ||
| } | ||
|
|
||
| var elementIdXmlAttribute = xmiReader.GetAttribute("elementId"); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(elementIdXmlAttribute)) | ||
| { | ||
| poco.ElementId = elementIdXmlAttribute; | ||
| } | ||
|
|
||
| var isImpliedIncludedXmlAttribute = xmiReader.GetAttribute("isImpliedIncluded"); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(isImpliedIncludedXmlAttribute)) | ||
| { | ||
| if (bool.TryParse(isImpliedIncludedXmlAttribute, out var isImpliedIncludedXmlAttributeAsBool)) | ||
| { | ||
| poco.IsImpliedIncluded = isImpliedIncludedXmlAttributeAsBool; | ||
| } | ||
| } | ||
|
|
||
| var ownedRelationshipXmlAttribute = xmiReader.GetAttribute("ownedRelationship"); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(ownedRelationshipXmlAttribute)) | ||
| { | ||
| var ownedRelationshipXmlAttributeReferences = new List<Guid>(); | ||
|
|
||
| foreach (var ownedRelationshipXmlAttributeValue in ownedRelationshipXmlAttribute.Split(SplitMultiReference, StringSplitOptions.RemoveEmptyEntries)) | ||
| { | ||
| if (Guid.TryParse(ownedRelationshipXmlAttributeValue, out var ownedRelationshipXmlAttributeReference)) | ||
| { | ||
| ownedRelationshipXmlAttributeReferences.Add(ownedRelationshipXmlAttributeReference); | ||
| } | ||
| } | ||
|
|
||
| if (ownedRelationshipXmlAttributeReferences.Count != 0) | ||
| { | ||
| this.Cache.AddMultipleValueReferencePropertyIdentifiers(poco.Id, "ownedRelationship", ownedRelationshipXmlAttributeReferences); | ||
| } | ||
| } | ||
|
|
||
| var owningRelationshipXmlAttribute = xmiReader.GetAttribute("owningRelationship"); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(owningRelationshipXmlAttribute)) | ||
| { | ||
| if (Guid.TryParse(owningRelationshipXmlAttribute, out var owningRelationshipXmlAttributeReference)) | ||
| { | ||
| this.Cache.AddSingleValueReferencePropertyIdentifier(poco.Id, "owningRelationship", owningRelationshipXmlAttributeReference); | ||
| } | ||
| } | ||
|
|
||
| while (xmiReader.Read()) | ||
| { | ||
| if (xmiReader.NodeType == XmlNodeType.Element) | ||
| { | ||
| switch (xmiReader.LocalName) | ||
| { | ||
| case "aliasIds": | ||
| { | ||
| var aliasIdsValue = xmiReader.ReadElementContentAsString(); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(aliasIdsValue)) | ||
| { | ||
| poco.AliasIds.Add(aliasIdsValue); | ||
| } | ||
|
|
||
| break; | ||
| } | ||
|
|
||
| case "declaredName": | ||
| { | ||
| var declaredNameValue = xmiReader.ReadElementContentAsString(); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(declaredNameValue)) | ||
| { | ||
| poco.DeclaredName = declaredNameValue; | ||
| } | ||
|
|
||
| break; | ||
| } | ||
|
|
||
| case "declaredShortName": | ||
| { | ||
| var declaredShortNameValue = xmiReader.ReadElementContentAsString(); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(declaredShortNameValue)) | ||
| { | ||
| poco.DeclaredShortName = declaredShortNameValue; | ||
| } | ||
|
|
||
| break; | ||
| } | ||
|
|
||
| case "elementId": | ||
| { | ||
| var elementIdValue = xmiReader.ReadElementContentAsString(); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(elementIdValue)) | ||
| { | ||
| poco.ElementId = elementIdValue; | ||
| } | ||
|
|
||
| break; | ||
| } | ||
|
|
||
| case "isImpliedIncluded": | ||
| { | ||
| var isImpliedIncludedValue = xmiReader.ReadElementContentAsString(); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(isImpliedIncludedValue)) | ||
| { | ||
| poco.IsImpliedIncluded = bool.Parse(isImpliedIncludedValue); | ||
| } | ||
|
|
||
| break; | ||
| } | ||
|
|
||
| case "ownedRelationship": | ||
| { | ||
| var hrefAttribute = xmiReader.GetAttribute("href"); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(hrefAttribute)) | ||
| { | ||
| var hrefSplit = hrefAttribute.Split('#'); | ||
| this.ExternalReferenceService.AddExternalReferenceToProcess(currentLocation, hrefSplit[0]); | ||
| var ownedRelationshipId = Guid.Parse(hrefSplit[1]); | ||
| this.Cache.AddMultipleValueReferencePropertyIdentifiers(poco.Id, "ownedRelationship", ownedRelationshipId); | ||
| } | ||
| else | ||
| { | ||
| var ownedRelationshipValue = (IRelationship)this.XmiDataReaderFacade.QueryXmiData(xmiReader, this.Cache, currentLocation, this.ExternalReferenceService, this.LoggerFactory); | ||
|
|
||
| poco.OwnedRelationship.Add(ownedRelationshipValue); | ||
| } | ||
|
|
||
| break; | ||
| } | ||
|
|
||
| case "owningRelationship": | ||
| { | ||
| var hrefAttribute = xmiReader.GetAttribute("href"); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(hrefAttribute)) | ||
| { | ||
| var hrefSplit = hrefAttribute.Split('#'); | ||
| this.ExternalReferenceService.AddExternalReferenceToProcess(currentLocation, hrefSplit[0]); | ||
| var owningRelationshipId = Guid.Parse(hrefSplit[1]); | ||
| this.Cache.AddSingleValueReferencePropertyIdentifier(poco.Id, "owningRelationship", owningRelationshipId); | ||
| } | ||
| else | ||
| { | ||
| var owningRelationshipValue = (IRelationship)this.XmiDataReaderFacade.QueryXmiData(xmiReader, this.Cache, currentLocation, this.ExternalReferenceService, this.LoggerFactory); | ||
|
|
||
| poco.OwningRelationship = owningRelationshipValue; | ||
| } | ||
|
|
||
| break; | ||
| } | ||
|
|
||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return poco; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // ------------------------------------------------------------------------------------------------ | ||
| // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- | ||
| // ------------------------------------------------------------------------------------------------ | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2026 please