-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactor] LiteralUnlimitedNatural to be of type string instead of in…
…teger
- Loading branch information
1 parent
b954b10
commit 71453f2
Showing
11 changed files
with
415 additions
and
146 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
192 changes: 192 additions & 0 deletions
192
uml4net.CodeGenerator.Tests/Expected/AutoGenXmiReaders/LiteralUnlimitedNaturalReader.cs
This file contains 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,192 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// <copyright file="LiteralUnlimitedNaturalReader.cs" company="Starion Group S.A."> | ||
// | ||
// Copyright (C) 2019-2024 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 uml4net.xmi.Readers | ||
{ | ||
using System; | ||
using System.Linq; | ||
using System.Xml; | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
using uml4net; | ||
using uml4net.Actions; | ||
using uml4net.Activities; | ||
using uml4net.Classification; | ||
using uml4net.CommonBehavior; | ||
using uml4net.CommonStructure; | ||
using uml4net.Deployments; | ||
using uml4net.InformationFlows; | ||
using uml4net.Interactions; | ||
using uml4net.Packages; | ||
using uml4net.SimpleClassifiers; | ||
using uml4net.StateMachines; | ||
using uml4net.StructuredClassifiers; | ||
using uml4net.UseCases; | ||
using uml4net.Utils; | ||
using uml4net.Values; | ||
using uml4net.xmi.Cache; | ||
|
||
/// <summary> | ||
/// The purpose of the <see cref="LiteralUnlimitedNaturalReader"/> is to read an instance of <see cref="ILiteralUnlimitedNatural"/> | ||
/// from the XMI document | ||
/// </summary> | ||
public class LiteralUnlimitedNaturalReader : XmiElementReader<ILiteralUnlimitedNatural>, IXmiElementReader<ILiteralUnlimitedNatural> | ||
{ | ||
private readonly IXmiElementReaderFacade xmiElementReaderFacade; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LiteralUnlimitedNaturalReader"/> class. | ||
/// </summary> | ||
/// <param name="cache"> | ||
/// The cache in which each <see cref="IXmiElement"/>> is stored | ||
/// </param> | ||
/// <param name="loggerFactory"> | ||
/// The (injected) <see cref="ILoggerFactory"/> used to set up logging | ||
/// </param> | ||
public LiteralUnlimitedNaturalReader(IXmiReaderCache cache, ILoggerFactory loggerFactory) | ||
: base(cache, loggerFactory) | ||
{ | ||
this.xmiElementReaderFacade = new XmiElementReaderFacade(); | ||
} | ||
|
||
/// <summary> | ||
/// Reads the <see cref="ILiteralUnlimitedNatural"/> object from its XML representation | ||
/// </summary> | ||
/// <param name="xmlReader"> | ||
/// an instance of <see cref="XmlReader"/> | ||
/// </param> | ||
/// <returns> | ||
/// an instance of <see cref="ILiteralUnlimitedNatural"/> | ||
/// </returns> | ||
public override ILiteralUnlimitedNatural Read(XmlReader xmlReader) | ||
{ | ||
if (xmlReader == null) | ||
{ | ||
throw new ArgumentNullException(nameof(xmlReader)); | ||
} | ||
|
||
var defaultLineInfo = xmlReader as IXmlLineInfo; | ||
|
||
ILiteralUnlimitedNatural poco = new LiteralUnlimitedNatural(); | ||
|
||
if (xmlReader.MoveToContent() == XmlNodeType.Element) | ||
{ | ||
var xmiType = xmlReader.GetAttribute("xmi:type"); | ||
|
||
if (!string.IsNullOrEmpty(xmiType) && xmiType != "uml:LiteralUnlimitedNatural") | ||
{ | ||
throw new XmlException($"The XmiType should be 'uml:LiteralUnlimitedNatural' while it is {xmiType}"); | ||
} | ||
else | ||
{ | ||
xmiType = "uml:LiteralUnlimitedNatural"; | ||
} | ||
|
||
poco.XmiType = xmiType; | ||
|
||
poco.XmiId = xmlReader.GetAttribute("xmi:id"); | ||
|
||
this.Cache.Add(poco.XmiId, poco); | ||
|
||
poco.Name = xmlReader.GetAttribute("name"); | ||
|
||
var owningTemplateParameterXmlAttribute = xmlReader.GetAttribute("owningTemplateParameter"); | ||
if (!string.IsNullOrEmpty(owningTemplateParameterXmlAttribute)) | ||
{ | ||
poco.SingleValueReferencePropertyIdentifiers.Add("owningTemplateParameter", owningTemplateParameterXmlAttribute); | ||
} | ||
|
||
var templateParameterXmlAttribute = xmlReader.GetAttribute("templateParameter"); | ||
if (!string.IsNullOrEmpty(templateParameterXmlAttribute)) | ||
{ | ||
poco.SingleValueReferencePropertyIdentifiers.Add("templateParameter", templateParameterXmlAttribute); | ||
} | ||
|
||
var typeXmlAttribute = xmlReader.GetAttribute("type"); | ||
if (!string.IsNullOrEmpty(typeXmlAttribute)) | ||
{ | ||
poco.SingleValueReferencePropertyIdentifiers.Add("type", typeXmlAttribute); | ||
} | ||
|
||
poco.Value = xmlReader.GetAttribute("value"); | ||
|
||
var visibilityXmlAttribute = xmlReader.GetAttribute("visibility"); | ||
if (!string.IsNullOrEmpty(visibilityXmlAttribute)) | ||
{ | ||
poco.Visibility = (VisibilityKind)Enum.Parse(typeof(VisibilityKind), visibilityXmlAttribute, true); | ||
} | ||
|
||
|
||
while (xmlReader.Read()) | ||
{ | ||
if (xmlReader.NodeType == XmlNodeType.Element) | ||
{ | ||
switch (xmlReader.LocalName) | ||
{ | ||
case "name": | ||
poco.Name = xmlReader.ReadElementContentAsString(); | ||
break; | ||
case "nameExpression": | ||
var nameExpressionValue = (IStringExpression)this.xmiElementReaderFacade.QueryXmiElement(xmlReader, this.Cache, this.LoggerFactory, "uml:StringExpression"); | ||
poco.NameExpression.Add(nameExpressionValue); | ||
break; | ||
case "ownedComment": | ||
var ownedCommentValue = (IComment)this.xmiElementReaderFacade.QueryXmiElement(xmlReader, this.Cache, this.LoggerFactory, "uml:Comment"); | ||
poco.OwnedComment.Add(ownedCommentValue); | ||
break; | ||
case "owningTemplateParameter": | ||
this.CollectSingleValueReferencePropertyIdentifier(xmlReader, poco, "owningTemplateParameter"); | ||
break; | ||
case "templateParameter": | ||
this.CollectSingleValueReferencePropertyIdentifier(xmlReader, poco, "templateParameter"); | ||
break; | ||
case "type": | ||
this.CollectSingleValueReferencePropertyIdentifier(xmlReader, poco, "type"); | ||
break; | ||
case "value": | ||
poco.Value = xmlReader.ReadElementContentAsString(); | ||
break; | ||
case "visibility": | ||
var visibilityValue = xmlReader.ReadElementContentAsString(); | ||
if (!string.IsNullOrEmpty(visibilityValue)) | ||
{ | ||
poco.Visibility = (VisibilityKind)Enum.Parse(typeof(VisibilityKind), visibilityValue, true); ; | ||
} | ||
break; | ||
default: | ||
throw new NotSupportedException($"LiteralUnlimitedNaturalReader: {xmlReader.LocalName} at line:position {defaultLineInfo.LineNumber}:{defaultLineInfo.LinePosition}"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return poco; | ||
} | ||
} | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------ | ||
// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- | ||
// ------------------------------------------------------------------------------------------------ |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.