-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcapellacore.py
More file actions
420 lines (295 loc) · 11.5 KB
/
Copy pathcapellacore.py
File metadata and controls
420 lines (295 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# SPDX-FileCopyrightText: Copyright DB InfraGO AG
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations
import collections.abc as cabc
import enum
import sys
import typing as t
import warnings
import capellambse.model as m
from . import modellingcore
from . import namespaces as ns
if sys.version_info >= (3, 13):
from warnings import deprecated
else:
from typing_extensions import deprecated
NS = ns.CAPELLACORE
@m.stringy_enum
@enum.unique
class VisibilityKind(enum.Enum):
"""The possibilities regarding the visibility of a feature of a class."""
UNSET = "UNSET"
"""Visibility is not specified."""
PUBLIC = "PUBLIC"
"""The feature offers public access."""
PROTECTED = "PROTECTED"
"""The feature offers visibility only to children of the class."""
PRIVATE = "PRIVATE"
"""The feature is only visible/accessible from the class itself."""
PACKAGE = "PACKAGE"
"""The feature is accessible from any element within the same package."""
class CapellaElement(
modellingcore.TraceableElement,
modellingcore.PublishableElement,
abstract=True,
):
summary = m.StringPOD("summary")
"""Summary of the element."""
description = m.HTMLStringPOD("description")
"""Description of the Capella element."""
review = m.StringPOD("review")
"""Review description on the Capella element."""
property_values = m.Containment["AbstractPropertyValue"](
"ownedPropertyValues",
(NS, "AbstractPropertyValue"),
mapkey="name",
mapvalue="value",
)
enumeration_property_types = m.Containment["EnumerationPropertyType"](
"ownedEnumerationPropertyTypes", (NS, "EnumerationPropertyType")
)
applied_property_values = m.Association["AbstractPropertyValue"](
(NS, "AbstractPropertyValue"), "appliedPropertyValues"
)
property_value_groups = m.Containment["PropertyValueGroup"](
"ownedPropertyValueGroups",
(NS, "PropertyValueGroup"),
mapkey="name",
mapvalue="property_values",
)
applied_property_value_groups = m.Association["PropertyValueGroup"](
(NS, "PropertyValueGroup"), "appliedPropertyValueGroups"
)
status = m.Single["EnumerationPropertyLiteral"](
m.Association((NS, "EnumerationPropertyLiteral"), "status")
)
features = m.Association["EnumerationPropertyLiteral"](
(NS, "EnumerationPropertyLiteral"), "features"
)
owned_traces = m.Containment["capellacommon.TransfoLink"](
"ownedTraces", (ns.CAPELLACOMMON, "TransfoLink")
)
class NamedElement(
modellingcore.AbstractNamedElement, CapellaElement, abstract=True
):
pass
class Relationship(
modellingcore.AbstractRelationship, CapellaElement, abstract=True
):
pass
class Namespace(NamedElement, abstract=True):
traces = m.Containment["Trace"]("ownedTraces", (NS, "Trace"))
naming_rules = m.Containment["NamingRule"](
"namingRules", (NS, "NamingRule")
)
class NamedRelationship(Relationship, NamedElement, abstract=True):
naming_rules = m.Containment["NamingRule"](
"namingRules", (NS, "NamingRule")
)
class Structure(Namespace, abstract=True):
property_value_pkgs = m.Containment["PropertyValuePkg"](
"ownedPropertyValuePkgs",
(NS, "PropertyValuePkg"),
mapkey="name",
)
if not t.TYPE_CHECKING:
property_value_packages = m.DeprecatedAccessor("property_value_pkgs")
class ReuserStructure(Structure, abstract=True):
reuse_links = m.Association["ReuseLink"]((NS, "ReuseLink"), "reuseLinks")
owned_reuse_links = m.Containment["ReuseLink"](
"ownedReuseLinks", (NS, "ReuseLink")
)
class AbstractModellingStructure(ReuserStructure, abstract=True):
architectures = m.Containment["ModellingArchitecture"](
"ownedArchitectures", (NS, "ModellingArchitecture")
)
architecture_pkgs = m.Containment["ModellingArchitecturePkg"](
"ownedArchitecturePkgs", (NS, "ModellingArchitecturePkg")
)
class Type(modellingcore.AbstractType, Namespace, abstract=True):
"""Represents a set of values.
A typed element that has this type is constrained to represent
values within this set.
"""
class ModellingBlock(Type, abstract=True):
"""A modular unit that describes the structure of a system or element.
A class (or block) that cannot be directly instantiated. Contrast:
concrete class.
"""
class ModellingArchitecture(Structure, abstract=True):
"""Supports the definition of the model structure at a design level."""
class ModellingArchitecturePkg(Structure, abstract=True):
"""A container for modelling architectures."""
class TypedElement(
modellingcore.AbstractTypedElement, NamedElement, abstract=True
):
"""An element that has a type."""
class Trace(Relationship, modellingcore.AbstractTrace, abstract=True):
pass
class AbstractAnnotation(CapellaElement, abstract=True):
content = m.StringPOD("content")
class NamingRule(AbstractAnnotation):
target_type = m.StringPOD("targetType")
"""Type to whose instances the naming rule has to be applied."""
class Constraint(NamedElement, modellingcore.AbstractConstraint):
"""A condition or restriction.
The constraint is expressed in natural language text or in a machine
readable language for the purpose of declaring some of the semantics
of an element.
"""
_xmltag = "ownedConstraints"
class KeyValue(CapellaElement):
key = m.StringPOD("key")
value = m.StringPOD("value")
class ReuseLink(Relationship):
reused = m.Single["ReuseableStructure"](
m.Association((NS, "ReuseableStructure"), "reused")
)
reuser = m.Single["ReuserStructure"](
m.Association((NS, "ReuserStructure"), "reuser")
)
class ReuseableStructure(Structure, abstract=True):
"""A structure intended to be reused across various architectures."""
reuse_links = m.Association["ReuseLink"]((NS, "ReuseLink"), "reuseLinks")
class GeneralizableElement(Type, abstract=True):
"""A type than can be generalized."""
is_abstract = m.BoolPOD("abstract")
generalizations = m.Containment["Generalization"](
"ownedGeneralizations", (NS, "Generalization")
)
sub = m.Backref["GeneralizableElement"](
(NS, "GeneralizableElement"), "super", legacy_by_type=True
)
super = m.Single["GeneralizableElement"](
m.Allocation(
"ownedGeneralizations",
(NS, "Generalization"),
(NS, "GeneralizableElement"),
attr="super",
backattr="sub",
)
)
class Classifier(GeneralizableElement, abstract=True):
owned_features = m.Containment["Feature"]("ownedFeatures", (NS, "Feature"))
class GeneralClass(
Classifier, modellingcore.FinalizableElement, abstract=True
):
visibility = m.EnumPOD("visibility", VisibilityKind)
nested_classes = m.Containment["GeneralClass"](
"nestedGeneralClasses", (NS, "GeneralClass")
)
class Generalization(Relationship):
_xmltag = "ownedGeneralizations"
super = m.Single["GeneralizableElement"](
m.Association((NS, "GeneralizableElement"), "super")
)
sub = m.Single["GeneralizableElement"](
m.Association((NS, "GeneralizableElement"), "sub")
)
class Feature(NamedElement, abstract=True):
is_abstract = m.BoolPOD("isAbstract")
is_static = m.BoolPOD("isStatic")
visibility = m.EnumPOD("visibility", VisibilityKind)
class AbstractExchangeItemPkg(Structure, abstract=True):
exchange_items = m.Containment["information.ExchangeItem"](
"ownedExchangeItems", (ns.INFORMATION, "ExchangeItem")
)
class Allocation(Relationship, modellingcore.AbstractTrace, abstract=True):
pass
class Involvement(Relationship, abstract=True):
involved = m.Single["InvolvedElement"](
m.Association((NS, "InvolvedElement"), "involved")
)
@property
@deprecated("Synthetic names are deprecated", category=FutureWarning)
def name(self) -> str:
"""Return the name."""
direction = ""
try:
if self.involved is not None:
direction = f" to {self.involved.name} ({self.involved.uuid})"
except AttributeError:
pass
return f"[{self.__class__.__name__}]{direction}"
if not t.TYPE_CHECKING:
source = m.DeprecatedAccessor("parent")
target = m.DeprecatedAccessor("involved")
class InvolverElement(CapellaElement, abstract=True):
pass
class InvolvedElement(CapellaElement, abstract=True):
pass
class AbstractPropertyValue(NamedElement, abstract=True):
_xmltag = "ownedPropertyValues"
involved_elements = m.Association["CapellaElement"](
(NS, "CapellaElement"), "involvedElements"
)
if not t.TYPE_CHECKING:
enumerations = m.DeprecatedAccessor("enumeration_property_types")
class StringPropertyValue(AbstractPropertyValue):
"""A string property value."""
value = m.StringPOD("value")
class IntegerPropertyValue(AbstractPropertyValue):
"""An integer property value."""
value = m.IntPOD("value")
class BooleanPropertyValue(AbstractPropertyValue):
"""A boolean property value."""
value = m.BoolPOD("value")
class FloatPropertyValue(AbstractPropertyValue):
"""A floating point property value."""
value = m.FloatPOD("value")
class EnumerationPropertyValue(AbstractPropertyValue):
type = m.Single["EnumerationPropertyType"](
m.Association((NS, "EnumerationPropertyType"), "type")
)
value = m.Single["EnumerationPropertyLiteral"](
m.Association((NS, "EnumerationPropertyLiteral"), "value")
)
class EnumerationPropertyType(NamedElement):
_xmltag = "ownedEnumerationPropertyTypes"
literals = m.Containment["EnumerationPropertyLiteral"](
"ownedLiterals", (NS, "EnumerationPropertyLiteral")
)
class EnumerationPropertyLiteral(NamedElement):
"""A Literal for EnumerationPropertyType."""
_xmltag = "ownedLiterals"
class PropertyValueGroup(Namespace, cabc.MutableMapping[str, str]):
"""A group for PropertyValues."""
_xmltag = "ownedPropertyValueGroups"
def __getitem__(self, k: str, /) -> t.Any:
return self.property_values.by_name(k).value
def __setitem__(self, k: str, v: t.Any, /) -> None:
self.property_values.by_name(k).value = v
def __delitem__(self, k: str, /) -> None:
self.property_values.delete_all(name=k)
def __iter__(self) -> cabc.Iterator[str]:
for prop in self.property_values:
yield prop.name
def __len__(self) -> int:
return sum(1 for _ in self)
if not t.TYPE_CHECKING:
values = m.DeprecatedAccessor("property_values")
class PropertyValuePkg(Structure):
"""A Package for PropertyValues."""
_xmltag = "ownedPropertyValuePkgs"
packages = m.Alias["m.ElementList[PropertyValuePkg]"](
"property_value_pkgs", dirhide=False
)
groups = m.Alias["m.ElementList[PropertyValueGroup]"](
"property_value_groups", dirhide=False
)
values = m.Alias["m.ElementList[AbstractPropertyValue]"](
"property_values", dirhide=False
)
class AbstractDependenciesPkg(Structure, abstract=True):
pass
if not t.TYPE_CHECKING:
def __getattr__(attr):
if attr == "PropertyValue":
warnings.warn(
"PropertyValue has been renamed to AbstractPropertyValue",
DeprecationWarning,
stacklevel=2,
)
return AbstractPropertyValue
raise AttributeError(f"{__name__} has no attribute {attr}")
from . import information # noqa: F401