Serialization¶
etcion.serialization.xml
¶
XML serialization for the ArchiMate Exchange Format.
Reference: ADR-031.
serialize_element(elem)
¶
Serialize a single Element to an lxml element node.
Source code in src/etcion/serialization/xml.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
serialize_relationship(rel)
¶
Serialize a single Relationship to an lxml element node.
Source code in src/etcion/serialization/xml.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
serialize_model(model, *, model_name='Untitled Model')
¶
Serialize a Model to a complete Exchange Format ElementTree.
Source code in src/etcion/serialization/xml.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
write_model(model, path, *, model_name='Untitled Model')
¶
Write a Model to an XML file in Exchange Format.
Source code in src/etcion/serialization/xml.py
107 108 109 110 111 112 113 114 115 116 | |
deserialize_model(tree)
¶
Deserialize an Exchange Format :class:lxml.etree._ElementTree into a
:class:~etcion.metamodel.model.Model.
Uses a two-phase approach:
- Parse all
<element>nodes and build anid_mapkeyed by the exchange-format identifier (id-<uuid>). - Parse all
<relationship>nodes, resolvingsource/targetreferences againstid_map.
Source code in src/etcion/serialization/xml.py
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 | |
read_model(path)
¶
Parse an Exchange Format XML file from path and return a
:class:~etcion.metamodel.model.Model.
Source code in src/etcion/serialization/xml.py
223 224 225 226 227 228 | |
validate_exchange_format(tree)
¶
Validate a serialized Exchange Format tree against the bundled XSD.
Returns a list of validation error strings (empty list means valid).
Raises :exc:FileNotFoundError if the XSD has not been bundled yet.
Source code in src/etcion/serialization/xml.py
238 239 240 241 242 243 244 245 246 247 248 249 | |
etcion.serialization.json
¶
JSON serialization for etcion models.
Reference: ADR-031 Decision 9.
model_to_dict(model)
¶
Serialize a :class:~etcion.metamodel.model.Model to a JSON-compatible dictionary.
The returned structure is::
{
"elements": [<element dict>, ...],
"relationships": [<relationship dict>, ...],
}
Every entry carries a _type key whose value is the ArchiMate
type name string (e.g. "BusinessActor"), used as a discriminator
during deserialization.
Source code in src/etcion/serialization/json.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
model_from_dict(data)
¶
Reconstruct a :class:~etcion.metamodel.model.Model from a JSON-compatible dictionary.
Deserialization is two-phase:
- Elements — each element dict is validated into its correct
concrete class and added to the model; an
id_mapis built for cross-reference resolution. - Relationships — the
sourceandtargetbare ID strings are resolved to the corresponding :class:~etcion.metamodel.concepts.Conceptinstances before the relationship is validated and added.
:raises KeyError: if a _type value is not present in
:data:_NAME_TO_TYPE or a relationship references an unknown element ID.
Source code in src/etcion/serialization/json.py
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 | |
etcion.serialization.registry
¶
External TypeRegistry mapping Concept subclasses to XML descriptors.
Reference: ADR-031 Decision 3.
TypeDescriptor(xml_tag, extra_attrs=dict())
dataclass
¶
Maps a Concept subclass to its Exchange Format XML representation.
register_element_type(cls, xml_tag, extra_attrs=None)
¶
Register a custom Element subclass with the serialization layer.
.. warning:: Models containing custom types are not portable to other ArchiMate tools. Prefer Profiles for spec-compliant extension.
:param cls: A concrete Element subclass (must define _type_name).
:param xml_tag: The XML tag name used in Exchange Format serialization.
:param extra_attrs: Optional dict mapping XML attribute names to
callables that extract the attribute value from an instance.
:raises TypeError: If cls is not a concrete Element subclass.
:raises ValueError: If cls is already registered.
Source code in src/etcion/serialization/registry.py
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 | |