Skip to content

Commit 0e9a730

Browse files
CodeGen resolve-reference for POCO on XMI process (#72)
1 parent 5a459b9 commit 0e9a730

196 files changed

Lines changed: 34303 additions & 77 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
// -------------------------------------------------------------------------------------------------
2+
// <copyright file="AnnotatingElementExtensions.cs" company="Starion Group S.A.">
3+
//
4+
// Copyright 2022-2026 Starion Group S.A.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// </copyright>
19+
// ------------------------------------------------------------------------------------------------
20+
21+
// ------------------------------------------------------------------------------------------------
22+
// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!--------
23+
// ------------------------------------------------------------------------------------------------
24+
25+
namespace SysML2.NET.Serializer.Xmi.Extensions
26+
{
27+
using System;
28+
using System.Collections.Generic;
29+
30+
using Microsoft.Extensions.Logging;
31+
32+
using SysML2.NET.Common;
33+
34+
/// <summary>
35+
/// Provides extensions methods for the <see cref="{SysML2.NET.Core.POCO.Root.Annotations.{this.Name}}"/> to help resolve reference for properties
36+
/// </summary>
37+
public static class AnnotatingElementExtensions
38+
{
39+
/// <summary>
40+
/// Resolve and assign single reference value for a specific property
41+
/// </summary>
42+
/// <param name="poco">The <see cref="SysML2.NET.Core.POCO.Root.Annotations.AnnotatingElement"/> that should have the value of a property to be set</param>
43+
/// <param name="propertyName">The name of the property</param>
44+
/// <param name="reference">The identifier of the <see cref="IData"/> value to set</param>
45+
/// <param name="xmiDataCache">The <see cref="IXmiDataCache"/></param>
46+
/// <param name="logger">The <see cref="ILogger" /> used to produce log statement</param>
47+
public static void ResolveAndAssignSingleValueReference(this SysML2.NET.Core.POCO.Root.Annotations.AnnotatingElement poco, string propertyName, Guid reference, IXmiDataCache xmiDataCache, ILogger logger)
48+
{
49+
if (poco == null)
50+
{
51+
throw new ArgumentNullException(nameof(poco));
52+
}
53+
54+
if (xmiDataCache == null)
55+
{
56+
throw new ArgumentNullException(nameof(xmiDataCache));
57+
}
58+
59+
if (logger == null)
60+
{
61+
throw new ArgumentNullException(nameof(logger));
62+
}
63+
64+
switch (propertyName)
65+
{
66+
case "owningRelationship":
67+
{
68+
if (!xmiDataCache.TryGetData(reference, out var referencedData))
69+
{
70+
logger.LogWarning("The reference to [{Reference}] for property [owningRelationship] on element type [AnnotatingElement] with id [{Id}] was not found in the cache, probably because its type is not supported.",
71+
reference, poco.Id);
72+
73+
return;
74+
}
75+
76+
if (referencedData is not SysML2.NET.Core.POCO.Root.Elements.IRelationship owningRelationshipReference)
77+
{
78+
throw new InvalidOperationException($"The referenced element with the id [{reference}] is a {referencedData.GetType().Name}, expected type: an IRelationship");
79+
}
80+
81+
poco.OwningRelationship = owningRelationshipReference;
82+
return;
83+
}
84+
85+
default:
86+
throw new ArgumentOutOfRangeException(nameof(propertyName), propertyName, "Unknown property name");
87+
}
88+
}
89+
90+
/// <summary>
91+
/// Resolve and assign multiple references value for a specific property
92+
/// </summary>
93+
/// <param name="poco">The <see cref="SysML2.NET.Core.POCO.Root.Annotations.AnnotatingElement"/> that should have the value of a property to be set</param>
94+
/// <param name="propertyName">The name of the property</param>
95+
/// <param name="references">The collection of identifier values to set</param>
96+
/// <param name="xmiDataCache">The <see cref="IXmiDataCache"/></param>
97+
/// <param name="logger">The <see cref="ILogger" /> used to produce log statement</param>
98+
public static void ResolveAndAssignMultipleValueReferences(this SysML2.NET.Core.POCO.Root.Annotations.AnnotatingElement poco, string propertyName, IReadOnlyCollection<Guid> references, IXmiDataCache xmiDataCache, ILogger logger)
99+
{
100+
if (poco == null)
101+
{
102+
throw new ArgumentNullException(nameof(poco));
103+
}
104+
105+
if (references == null)
106+
{
107+
throw new ArgumentNullException(nameof(references));
108+
}
109+
110+
if (xmiDataCache == null)
111+
{
112+
throw new ArgumentNullException(nameof(xmiDataCache));
113+
}
114+
115+
if (logger == null)
116+
{
117+
throw new ArgumentNullException(nameof(logger));
118+
}
119+
120+
switch (propertyName)
121+
{
122+
case "ownedRelationship":
123+
{
124+
foreach (var reference in references)
125+
{
126+
if (!xmiDataCache.TryGetData(reference, out var referencedData))
127+
{
128+
logger.LogWarning("The reference to [{Reference}] for property [ownedRelationship] on element type [AnnotatingElement] with id [{Id}] was not found in the cache, probably because its type is not supported.",
129+
reference, poco.Id);
130+
131+
continue;
132+
}
133+
134+
if (referencedData is not SysML2.NET.Core.POCO.Root.Elements.IRelationship ownedRelationshipReference)
135+
{
136+
throw new InvalidOperationException($"The referenced element with the id [{reference}] is a {referencedData.GetType().Name}, expected type: an IRelationship");
137+
}
138+
139+
poco.OwnedRelationship.Add(ownedRelationshipReference);
140+
}
141+
142+
return;
143+
}
144+
145+
default:
146+
throw new ArgumentOutOfRangeException(nameof(propertyName), propertyName, "Unknown property name");
147+
}
148+
}
149+
}
150+
}
151+
152+
// ------------------------------------------------------------------------------------------------
153+
// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!--------
154+
// ------------------------------------------------------------------------------------------------
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
// -------------------------------------------------------------------------------------------------
2+
// <copyright file="AssociationExtensions.cs" company="Starion Group S.A.">
3+
//
4+
// Copyright 2022-2026 Starion Group S.A.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// </copyright>
19+
// ------------------------------------------------------------------------------------------------
20+
21+
// ------------------------------------------------------------------------------------------------
22+
// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!--------
23+
// ------------------------------------------------------------------------------------------------
24+
25+
namespace SysML2.NET.Serializer.Xmi.Extensions
26+
{
27+
using System;
28+
using System.Collections.Generic;
29+
30+
using Microsoft.Extensions.Logging;
31+
32+
using SysML2.NET.Common;
33+
34+
/// <summary>
35+
/// Provides extensions methods for the <see cref="{SysML2.NET.Core.POCO.Kernel.Associations.{this.Name}}"/> to help resolve reference for properties
36+
/// </summary>
37+
public static class AssociationExtensions
38+
{
39+
/// <summary>
40+
/// Resolve and assign single reference value for a specific property
41+
/// </summary>
42+
/// <param name="poco">The <see cref="SysML2.NET.Core.POCO.Kernel.Associations.Association"/> that should have the value of a property to be set</param>
43+
/// <param name="propertyName">The name of the property</param>
44+
/// <param name="reference">The identifier of the <see cref="IData"/> value to set</param>
45+
/// <param name="xmiDataCache">The <see cref="IXmiDataCache"/></param>
46+
/// <param name="logger">The <see cref="ILogger" /> used to produce log statement</param>
47+
public static void ResolveAndAssignSingleValueReference(this SysML2.NET.Core.POCO.Kernel.Associations.Association poco, string propertyName, Guid reference, IXmiDataCache xmiDataCache, ILogger logger)
48+
{
49+
if (poco == null)
50+
{
51+
throw new ArgumentNullException(nameof(poco));
52+
}
53+
54+
if (xmiDataCache == null)
55+
{
56+
throw new ArgumentNullException(nameof(xmiDataCache));
57+
}
58+
59+
if (logger == null)
60+
{
61+
throw new ArgumentNullException(nameof(logger));
62+
}
63+
64+
switch (propertyName)
65+
{
66+
case "owningRelatedElement":
67+
{
68+
if (!xmiDataCache.TryGetData(reference, out var referencedData))
69+
{
70+
logger.LogWarning("The reference to [{Reference}] for property [owningRelatedElement] on element type [Association] with id [{Id}] was not found in the cache, probably because its type is not supported.",
71+
reference, poco.Id);
72+
73+
return;
74+
}
75+
76+
if (referencedData is not SysML2.NET.Core.POCO.Root.Elements.IElement owningRelatedElementReference)
77+
{
78+
throw new InvalidOperationException($"The referenced element with the id [{reference}] is a {referencedData.GetType().Name}, expected type: an IElement");
79+
}
80+
81+
poco.OwningRelatedElement = owningRelatedElementReference;
82+
return;
83+
}
84+
85+
case "owningRelationship":
86+
{
87+
if (!xmiDataCache.TryGetData(reference, out var referencedData))
88+
{
89+
logger.LogWarning("The reference to [{Reference}] for property [owningRelationship] on element type [Association] with id [{Id}] was not found in the cache, probably because its type is not supported.",
90+
reference, poco.Id);
91+
92+
return;
93+
}
94+
95+
if (referencedData is not SysML2.NET.Core.POCO.Root.Elements.IRelationship owningRelationshipReference)
96+
{
97+
throw new InvalidOperationException($"The referenced element with the id [{reference}] is a {referencedData.GetType().Name}, expected type: an IRelationship");
98+
}
99+
100+
poco.OwningRelationship = owningRelationshipReference;
101+
return;
102+
}
103+
104+
default:
105+
throw new ArgumentOutOfRangeException(nameof(propertyName), propertyName, "Unknown property name");
106+
}
107+
}
108+
109+
/// <summary>
110+
/// Resolve and assign multiple references value for a specific property
111+
/// </summary>
112+
/// <param name="poco">The <see cref="SysML2.NET.Core.POCO.Kernel.Associations.Association"/> that should have the value of a property to be set</param>
113+
/// <param name="propertyName">The name of the property</param>
114+
/// <param name="references">The collection of identifier values to set</param>
115+
/// <param name="xmiDataCache">The <see cref="IXmiDataCache"/></param>
116+
/// <param name="logger">The <see cref="ILogger" /> used to produce log statement</param>
117+
public static void ResolveAndAssignMultipleValueReferences(this SysML2.NET.Core.POCO.Kernel.Associations.Association poco, string propertyName, IReadOnlyCollection<Guid> references, IXmiDataCache xmiDataCache, ILogger logger)
118+
{
119+
if (poco == null)
120+
{
121+
throw new ArgumentNullException(nameof(poco));
122+
}
123+
124+
if (references == null)
125+
{
126+
throw new ArgumentNullException(nameof(references));
127+
}
128+
129+
if (xmiDataCache == null)
130+
{
131+
throw new ArgumentNullException(nameof(xmiDataCache));
132+
}
133+
134+
if (logger == null)
135+
{
136+
throw new ArgumentNullException(nameof(logger));
137+
}
138+
139+
switch (propertyName)
140+
{
141+
case "ownedRelatedElement":
142+
{
143+
foreach (var reference in references)
144+
{
145+
if (!xmiDataCache.TryGetData(reference, out var referencedData))
146+
{
147+
logger.LogWarning("The reference to [{Reference}] for property [ownedRelatedElement] on element type [Association] with id [{Id}] was not found in the cache, probably because its type is not supported.",
148+
reference, poco.Id);
149+
150+
continue;
151+
}
152+
153+
if (referencedData is not SysML2.NET.Core.POCO.Root.Elements.IElement ownedRelatedElementReference)
154+
{
155+
throw new InvalidOperationException($"The referenced element with the id [{reference}] is a {referencedData.GetType().Name}, expected type: an IElement");
156+
}
157+
158+
poco.OwnedRelatedElement.Add(ownedRelatedElementReference);
159+
}
160+
161+
return;
162+
}
163+
164+
case "ownedRelationship":
165+
{
166+
foreach (var reference in references)
167+
{
168+
if (!xmiDataCache.TryGetData(reference, out var referencedData))
169+
{
170+
logger.LogWarning("The reference to [{Reference}] for property [ownedRelationship] on element type [Association] with id [{Id}] was not found in the cache, probably because its type is not supported.",
171+
reference, poco.Id);
172+
173+
continue;
174+
}
175+
176+
if (referencedData is not SysML2.NET.Core.POCO.Root.Elements.IRelationship ownedRelationshipReference)
177+
{
178+
throw new InvalidOperationException($"The referenced element with the id [{reference}] is a {referencedData.GetType().Name}, expected type: an IRelationship");
179+
}
180+
181+
poco.OwnedRelationship.Add(ownedRelationshipReference);
182+
}
183+
184+
return;
185+
}
186+
187+
default:
188+
throw new ArgumentOutOfRangeException(nameof(propertyName), propertyName, "Unknown property name");
189+
}
190+
}
191+
}
192+
}
193+
194+
// ------------------------------------------------------------------------------------------------
195+
// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!--------
196+
// ------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)