-
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.
- Loading branch information
1 parent
64847f6
commit ca31122
Showing
24 changed files
with
2,499 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// <copyright file="ModelReader.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.Packages | ||
{ | ||
using System.Xml; | ||
|
||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
|
||
using uml4net.POCO.Packages; | ||
using uml4net.xmi.CommonStructure; | ||
|
||
/// <summary> | ||
/// The purpose of the <see cref="ModelReader"/> is to read an instance of <see cref="IModel"/> | ||
/// from the XMI document | ||
/// </summary> | ||
public class ModelReader | ||
{ | ||
/// <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<ModelReader> logger; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PackageReader"/> class. | ||
/// </summary> | ||
/// <param name="loggerFactory"> | ||
/// The (injected) <see cref="ILoggerFactory"/> used to setup logging | ||
/// </param> | ||
public ModelReader(ILoggerFactory loggerFactory = null) | ||
{ | ||
this.loggerFactory = loggerFactory; | ||
|
||
this.logger = this.loggerFactory == null ? NullLogger<ModelReader>.Instance : this.loggerFactory.CreateLogger<ModelReader>(); | ||
} | ||
|
||
/// <summary> | ||
/// Reads the <see cref="IPackage"/> object from its XML representation | ||
/// </summary> | ||
/// <param name="xmlreader"> | ||
/// an instance of <see cref="XmlReader"/> | ||
/// </param> | ||
/// <returns> | ||
/// an instance of <see cref="IPackage"/> | ||
/// </returns> | ||
public IModel Read(XmlReader xmlReader) | ||
{ | ||
IModel model = new Model(); | ||
|
||
if (xmlReader.MoveToContent() == XmlNodeType.Element) | ||
{ | ||
model.XmiId = xmlReader.GetAttribute("xmi:id"); | ||
model.Name = xmlReader.GetAttribute("name"); | ||
|
||
while (xmlReader.Read()) | ||
{ | ||
if (xmlReader.NodeType == XmlNodeType.Element) | ||
{ | ||
|
||
switch (xmlReader.LocalName) | ||
{ | ||
case "packageImport": | ||
using (var packageImportXmlReader = xmlReader.ReadSubtree()) | ||
{ | ||
var packageImportReader = new PackageImportReader(); | ||
var packageImport = packageImportReader.Read(packageImportXmlReader); | ||
model.PackageImport.Add(packageImport); | ||
} | ||
break; | ||
case "packagedElement": | ||
using (var packagedElementXmlReader = xmlReader.ReadSubtree()) | ||
{ | ||
this.logger.LogInformation("ModelReader.packagedElement not yet implemented"); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return model; | ||
} | ||
} | ||
} |
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,106 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// <copyright file="PackageReader.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.Packages | ||
{ | ||
using System.Xml; | ||
|
||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
|
||
using uml4net.POCO.Packages; | ||
using uml4net.xmi.CommonStructure; | ||
|
||
/// <summary> | ||
/// The purpose of the <see cref="PackageReader"/> is to read an instance of <see cref="IPackage"/> | ||
/// from the XMI document | ||
/// </summary> | ||
public class PackageReader | ||
{ | ||
/// <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<PackageReader> logger; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PackageReader"/> class. | ||
/// </summary> | ||
/// <param name="loggerFactory"> | ||
/// The (injected) <see cref="ILoggerFactory"/> used to setup logging | ||
/// </param> | ||
public PackageReader(ILoggerFactory loggerFactory = null) | ||
{ | ||
this.loggerFactory = loggerFactory; | ||
|
||
this.logger = this.loggerFactory == null ? NullLogger<PackageReader>.Instance : this.loggerFactory.CreateLogger<PackageReader>(); | ||
} | ||
|
||
/// <summary> | ||
/// Reads the <see cref="IPackage"/> object from its XML representation | ||
/// </summary> | ||
/// <param name="xmlreader"> | ||
/// an instance of <see cref="XmlReader"/> | ||
/// </param> | ||
/// <returns> | ||
/// an instance of <see cref="IPackage"/> | ||
/// </returns> | ||
public IPackage Read(XmlReader xmlReader) | ||
{ | ||
IPackage package = new Package(); | ||
|
||
if (xmlReader.MoveToContent() == XmlNodeType.Element) | ||
{ | ||
package.XmiId = xmlReader.GetAttribute("xmi:id"); | ||
package.Name = xmlReader.GetAttribute("name"); | ||
|
||
while (xmlReader.Read()) | ||
{ | ||
if (xmlReader.NodeType == XmlNodeType.Element) | ||
{ | ||
switch (xmlReader.LocalName) | ||
{ | ||
case "packageImport": | ||
using (var packageImportXmlReader = xmlReader.ReadSubtree()) | ||
{ | ||
var packageImportReader = new PackageImportReader(); | ||
var packageImport = packageImportReader.Read(packageImportXmlReader); | ||
package.PackageImport.Add(packageImport); | ||
} | ||
break; | ||
case "packagedElement": | ||
using (var packagedElementXmlReader = xmlReader.ReadSubtree()) | ||
{ | ||
this.logger.LogInformation("PackageReader.packagedElement not yet implemented"); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return package; | ||
} | ||
} | ||
} |
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.