Skip to content

Commit

Permalink
[Implement] IProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
samatstariongroup committed Aug 11, 2024
1 parent 64847f6 commit ca31122
Show file tree
Hide file tree
Showing 24 changed files with 2,499 additions and 2 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ PublishScripts/

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
Expand Down
107 changes: 107 additions & 0 deletions uml4net.xmireader/Packages/ModelReader.cs
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;
}
}
}
106 changes: 106 additions & 0 deletions uml4net.xmireader/Packages/PackageReader.cs
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;
}
}
}
111 changes: 111 additions & 0 deletions uml4net/POCO/Classification/IProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@

namespace uml4net.POCO.Classification
{
using System.Collections.Generic;

using uml4net.Decorators;
using uml4net.POCO.Deployments;
using uml4net.POCO.SimpleClassifiers;
using uml4net.POCO.StructuredClassifiers;
using uml4net.POCO.Values;

/// <summary>
/// A Property is a StructuralFeature. A Property related by ownedAttribute to a Classifier
Expand All @@ -36,5 +41,111 @@ namespace uml4net.POCO.Classification
/// </summary>
public interface IProperty : IConnectableElement, IDeploymentTarget, IStructuralFeature
{
/// <summary>
/// Specifies the kind of aggregation that applies to the Property.
/// </summary>
[Property(aggregation: AggregationKind.None, lowerValue: 1, upperValue: 1, defaultValue: "AggregationKind.None")]
public AggregationKind Aggregation { get; set; }

/// <summary>
/// The Association of which this Property is a member, if any.
/// </summary>
[Property(aggregation: AggregationKind.None, lowerValue: 0, upperValue: 1)]
[SubsettedProperty("A_member_memberNamespace-memberNamespace")]
public IAssociation Association { get; set; }

/// <summary>
/// Designates the optional association end that owns a qualifier attribute.
/// </summary>
[Property(aggregation: AggregationKind.None, lowerValue: 0, upperValue: 1)]
[SubsettedProperty("Element-owner")]
public IProperty AssociationEnd { get; set; }

/// <summary>
/// The Class that owns this Property, if any.
/// </summary>
[Property(aggregation: AggregationKind.None, lowerValue: 0, upperValue: 1)]
[SubsettedProperty("A_attribute_classifier-classifier")]
[SubsettedProperty("A_ownedAttribute_structuredClassifier-structuredClassifier")]
[SubsettedProperty("NamedElement-namespace")]
public IClass Class { get; set; }

/// <summary>
/// The DataType that owns this Property, if any.
/// </summary>
[Property(aggregation: AggregationKind.None, lowerValue: 0, upperValue: 1)]
[SubsettedProperty("A_attribute_classifier-classifier")]
[SubsettedProperty("NamedElement-namespace")]
public IDataType DataType { get; set; }

/// <summary>
/// A ValueSpecification that is evaluated to give a default value for the Property
/// when an instance of the owning Classifier is instantiated.
/// </summary>
[Property(aggregation: AggregationKind.Composite, lowerValue: 0, upperValue: 1)]
[SubsettedProperty("Element-ownedElement")]
public IValueSpecification Default { get; set; }

/// <summary>
/// If isComposite is true, the object containing the attribute is a container for the
/// object or value contained in the attribute. This is a derived value, indicating
/// whether the aggregation of the Property is composite or not.
/// </summary>
[Property(aggregation: AggregationKind.None, lowerValue: 1, upperValue: 1, isDerived:true, defaultValue: "false")]
public bool IsComposite { get; }

/// <summary>
/// Specifies whether the Property is derived, i.e., whether its value or values can be computed from other information.
/// </summary>
[Property(aggregation: AggregationKind.None, lowerValue: 1, upperValue: 1, defaultValue: "false")]
public bool IsDerived { get; set; }

/// <summary>
/// Specifies whether the property is derived as the union of all of the Properties that are constrained to subset it.
/// </summary>
[Property(aggregation: AggregationKind.None, lowerValue: 1, upperValue: 1, defaultValue: "false")]
public bool IsDerivedUnion { get; set; }

/// <summary>
/// True indicates this property can be used to uniquely identify an instance of the containing Class.
/// </summary>
[Property(aggregation: AggregationKind.None, lowerValue: 1, upperValue: 1, defaultValue: "false")]
public bool IsID { get; set; }

/// <summary>
/// In the case where the Property is one end of a binary association this gives the other end.
/// </summary>
[Property(aggregation: AggregationKind.None, lowerValue: 0, upperValue: 1)]
public IProperty Opposite { get; }

/// <summary>
/// The owning association of this property, if any.
/// </summary>
[Property(aggregation: AggregationKind.None, lowerValue: 0, upperValue: 1)]
[SubsettedProperty("Feature-featuringClassifier")]
[SubsettedProperty("NamedElement-namespace")]
[SubsettedProperty("Property-association")]
[SubsettedProperty("RedefinableElement-redefinitionContext")]
public IAssociation OwningAssociation { get; set; }

/// <summary>
/// An optional list of ordered qualifier attributes for the end.
/// </summary>
[Property(aggregation: AggregationKind.Composite, lowerValue: 0, upperValue: int.MaxValue)]
[SubsettedProperty("Element-ownedElement")]
public List<IProperty> Qualifier { get; set; }

/// <summary>
/// The properties that are redefined by this property, if any.
/// </summary>
[Property(aggregation: AggregationKind.None, lowerValue: 0, upperValue: int.MaxValue)]
[SubsettedProperty("RedefinableElement-redefinedElement")]
public List<IProperty> RedefinedProperty { get; set; }

/// <summary>
/// The properties of which this Property is constrained to be a subset, if any.
/// </summary>
[Property(aggregation: AggregationKind.None, lowerValue: 0, upperValue: int.MaxValue)]
public List<IProperty> SubsettedProperty { get; set; }
}
}
Loading

0 comments on commit ca31122

Please sign in to comment.