-
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.
[Add] EnumerationReader and EnumerationLiteralReader
- Loading branch information
1 parent
a14bb87
commit a3fe68c
Showing
8 changed files
with
315 additions
and
3 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
116 changes: 116 additions & 0 deletions
116
uml4net.xmireader/SimpleClassifiers/EnumerationLiteralReader.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,116 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// <copyright file="EnumerationLiteralReader.cs" company="Starion Group S.A."> | ||
// | ||
// Copyright 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, softwareUseCases | ||
// 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> | ||
// ------------------------------------------------------------------------------------------------ | ||
|
||
namespace uml4net.xmi.SimpleClassifiers | ||
{ | ||
using System; | ||
using System.Xml; | ||
|
||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
|
||
using uml4net.POCO.CommonStructure; | ||
using uml4net.POCO.SimpleClassifiers; | ||
using uml4net.POCO.StructuredClassifiers; | ||
using uml4net.xmi.Classification; | ||
using uml4net.xmi.CommonStructure; | ||
|
||
/// <summary> | ||
/// The purpose of the <see cref="EnumerationLiteralReader"/> is to read an instance of <see cref="IEnumerationLiteral"/> | ||
/// from the XMI document | ||
/// </summary> | ||
public class EnumerationLiteralReader | ||
{ | ||
/// <summary> | ||
/// The (injected) <see cref="ILoggerFactory"/> used to setup logging | ||
/// </summary> | ||
private readonly ILoggerFactory loggerFactory; | ||
|
||
/// <summary> | ||
/// The <see cref="ILogger"/> used to log | ||
/// </summary> | ||
private readonly ILogger<EnumerationLiteralReader> logger; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="EnumerationLiteralReader"/> class. | ||
/// </summary> | ||
/// <param name="loggerFactory"> | ||
/// The (injected) <see cref="ILoggerFactory"/> used to setup logging | ||
/// </param> | ||
public EnumerationLiteralReader(ILoggerFactory loggerFactory = null) | ||
{ | ||
this.loggerFactory = loggerFactory; | ||
|
||
this.logger = this.loggerFactory == null ? NullLogger<EnumerationLiteralReader>.Instance : this.loggerFactory.CreateLogger<EnumerationLiteralReader>(); | ||
} | ||
|
||
/// <summary> | ||
/// Reads the <see cref="IEnumeration"/> object from its XML representation | ||
/// </summary> | ||
/// <param name="xmlReader"> | ||
/// an instance of <see cref="XmlReader"/> | ||
/// </param> | ||
/// <returns> | ||
/// an instance of <see cref="IEnumeration"/> | ||
/// </returns> | ||
public IEnumerationLiteral Read(XmlReader xmlReader) | ||
{ | ||
IEnumerationLiteral enumerationLiteral = new EnumerationLiteral(); | ||
|
||
if (xmlReader.MoveToContent() == XmlNodeType.Element) | ||
{ | ||
enumerationLiteral.XmiId = xmlReader.GetAttribute("xmi:id"); | ||
|
||
var xmiType = xmlReader.GetAttribute("xmi:type"); | ||
|
||
if (xmiType != "uml:EnumerationLiteral") | ||
{ | ||
throw new XmlException($"The XmiType should be: uml:EnumerationLiteral while it is {xmiType}"); | ||
} | ||
|
||
enumerationLiteral.XmiType = xmlReader.GetAttribute("xmi:type"); | ||
|
||
enumerationLiteral.Name = xmlReader.GetAttribute("name"); | ||
|
||
while (xmlReader.Read()) | ||
{ | ||
if (xmlReader.NodeType == XmlNodeType.Element) | ||
{ | ||
switch (xmlReader.LocalName) | ||
{ | ||
case "ownedComment": | ||
using (var ownedCommentXmlReader = xmlReader.ReadSubtree()) | ||
{ | ||
var commentReader = new CommentReader(this.loggerFactory); | ||
var comment = commentReader.Read(ownedCommentXmlReader); | ||
enumerationLiteral.OwnedComment.Add(comment); | ||
} | ||
break; | ||
default: | ||
throw new NotImplementedException($"EnumerationLiteralReader: {xmlReader.LocalName}"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return enumerationLiteral; | ||
} | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
uml4net.xmireader/SimpleClassifiers/EnumerationReader.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,126 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// <copyright file="EnumerationReader.cs" company="Starion Group S.A."> | ||
// | ||
// Copyright 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, softwareUseCases | ||
// 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> | ||
// ------------------------------------------------------------------------------------------------ | ||
|
||
namespace uml4net.xmi.SimpleClassifiers | ||
{ | ||
using System; | ||
using System.Xml; | ||
|
||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
|
||
using uml4net.POCO.CommonStructure; | ||
using uml4net.POCO.SimpleClassifiers; | ||
using uml4net.POCO.StructuredClassifiers; | ||
using uml4net.xmi.Classification; | ||
using uml4net.xmi.CommonStructure; | ||
|
||
/// <summary> | ||
/// The purpose of the <see cref="EnumerationReader"/> is to read an instance of <see cref="IEnumeration"/> | ||
/// from the XMI document | ||
/// </summary> | ||
public class EnumerationReader | ||
{ | ||
/// <summary> | ||
/// The (injected) <see cref="ILoggerFactory"/> used to setup logging | ||
/// </summary> | ||
private readonly ILoggerFactory loggerFactory; | ||
|
||
/// <summary> | ||
/// The <see cref="ILogger"/> used to log | ||
/// </summary> | ||
private readonly ILogger<EnumerationReader> logger; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="EnumerationReader"/> class. | ||
/// </summary> | ||
/// <param name="loggerFactory"> | ||
/// The (injected) <see cref="ILoggerFactory"/> used to setup logging | ||
/// </param> | ||
public EnumerationReader(ILoggerFactory loggerFactory = null) | ||
{ | ||
this.loggerFactory = loggerFactory; | ||
|
||
this.logger = this.loggerFactory == null ? NullLogger<EnumerationReader>.Instance : this.loggerFactory.CreateLogger<EnumerationReader>(); | ||
} | ||
|
||
/// <summary> | ||
/// Reads the <see cref="IEnumeration"/> object from its XML representation | ||
/// </summary> | ||
/// <param name="xmlReader"> | ||
/// an instance of <see cref="XmlReader"/> | ||
/// </param> | ||
/// <returns> | ||
/// an instance of <see cref="IEnumeration"/> | ||
/// </returns> | ||
public IEnumeration Read(XmlReader xmlReader) | ||
{ | ||
IEnumeration enumeration = new Enumeration(); | ||
|
||
if (xmlReader.MoveToContent() == XmlNodeType.Element) | ||
{ | ||
enumeration.XmiId = xmlReader.GetAttribute("xmi:id"); | ||
|
||
var xmiType = xmlReader.GetAttribute("xmi:type"); | ||
|
||
if (xmiType != "uml:Enumeration") | ||
{ | ||
throw new XmlException($"The XmiType should be: uml:Enumeration while it is {xmiType}"); | ||
} | ||
|
||
enumeration.XmiType = xmlReader.GetAttribute("xmi:type"); | ||
|
||
enumeration.Name = xmlReader.GetAttribute("name"); | ||
|
||
while (xmlReader.Read()) | ||
{ | ||
if (xmlReader.NodeType == XmlNodeType.Element) | ||
{ | ||
switch (xmlReader.LocalName) | ||
{ | ||
case "ownedComment": | ||
using (var ownedCommentXmlReader = xmlReader.ReadSubtree()) | ||
{ | ||
var commentReader = new CommentReader(this.loggerFactory); | ||
var comment = commentReader.Read(ownedCommentXmlReader); | ||
enumeration.OwnedComment.Add(comment); | ||
} | ||
break; | ||
case "ownedLiteral": | ||
using (var ownedLiteralXmlReader = xmlReader.ReadSubtree()) | ||
{ | ||
var enumerationLiteralReader = new EnumerationLiteralReader(this.loggerFactory); | ||
var enumerationLiteral = enumerationLiteralReader.Read(ownedLiteralXmlReader); | ||
enumeration.OwnedLiteral.Add(enumerationLiteral); | ||
|
||
this.logger.LogInformation("ClassReader.ownedRule not yet implemented"); | ||
} | ||
break; | ||
default: | ||
throw new NotImplementedException($"ClassReader: {xmlReader.LocalName}"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return enumeration; | ||
} | ||
} | ||
} |
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
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