Skip to content

element_registry

A registry for mapping element names to dataclasses.

CLASS DESCRIPTION
ElementDescriptor

A descriptor for a BPMN element.

ElementProperty

A property of a BPMN element.

ElementRegistry

A registry for BPMN elements.

FUNCTION DESCRIPTION
dataclass_fields

Get the fields of a dataclass.

descriptor_from_class

Create a descriptor from a BPMN element class.

get_base_type

Extract the most basic type from complex type annotations.

register_element

Register an element in the global element registry.

type_hint_to_property

Converts a type hint represented as a dictionary into an ElementProperty object.

Classes

ElementDescriptor dataclass

ElementDescriptor(
    type: Any,
    name: str,
    q_name: QName,
    properties: dict[QName, ElementProperty],
)

A descriptor for a BPMN element.

ATTRIBUTE DESCRIPTION
name

The XML name of the BPMN element.

TYPE: str

properties

A mapping of BPMN attribute names to ElementProperty objects.

TYPE: dict[QName, ElementProperty]

q_name

The qualified name of the BPMN element.

TYPE: QName

type

The class of the BPMN element.

TYPE: Any

Attributes

name instance-attribute
name: str

The XML name of the BPMN element.

properties instance-attribute
properties: dict[QName, ElementProperty]

A mapping of BPMN attribute names to ElementProperty objects.

q_name instance-attribute
q_name: QName

The qualified name of the BPMN element.

type instance-attribute
type: Any

The class of the BPMN element.

ElementProperty dataclass

ElementProperty(
    property_name: str,
    type: str,
    type_qname: Optional[QName] = None,
    is_attr: bool = False,
    is_many: bool = False,
    is_optional: bool = False,
    is_reference: bool = False,
)

A property of a BPMN element.

ATTRIBUTE DESCRIPTION
is_attr

Whether the attribute is serialized as an XML attribute.

TYPE: bool

is_many

Whether the attribute is an array or a single value. Automatically set based on the type.

TYPE: bool

is_optional

Whether the attribute is optional. Automatically set based on the type.

TYPE: bool

is_reference

Whether the attribute is a reference to another element.

TYPE: bool

property_name

The name of the attribute on the element class.

TYPE: str

type

The type of the attribute on the element class.

TYPE: str

type_qname

The base type of the attribute on the element class. Automatically set based on the type.

TYPE: Optional[QName]

Attributes

is_attr class-attribute instance-attribute
is_attr: bool = False

Whether the attribute is serialized as an XML attribute.

is_many class-attribute instance-attribute
is_many: bool = False

Whether the attribute is an array or a single value. Automatically set based on the type.

is_optional class-attribute instance-attribute
is_optional: bool = False

Whether the attribute is optional. Automatically set based on the type.

is_reference class-attribute instance-attribute
is_reference: bool = False

Whether the attribute is a reference to another element.

property_name instance-attribute
property_name: str

The name of the attribute on the element class.

type instance-attribute
type: str

The type of the attribute on the element class.

type_qname class-attribute instance-attribute
type_qname: Optional[QName] = None

The base type of the attribute on the element class. Automatically set based on the type.

ElementRegistry

ElementRegistry()

A registry for BPMN elements.

METHOD DESCRIPTION
register

Register an element in the registry.

Functions

register
register(element: Any) -> None

Register an element in the registry.

Functions

dataclass_fields

dataclass_fields(data_class: Any) -> dict[str, dict]

Get the fields of a dataclass.

descriptor_from_class

descriptor_from_class(element_class: Any) -> ElementDescriptor

Create a descriptor from a BPMN element class.

get_base_type

get_base_type(type_: type) -> Any

Extract the most basic type from complex type annotations.

This function handles various typing constructs including: - Optional types (Union[T, None]) - List types (list[T]) - Dictionary types (dict[K, V]) - Union types (Union[T1, T2, …])

Examples:

Optional[list[str]] -> str list[str] -> str str -> str list[dict[str, int]] -> dict Union[int, float] -> Raises ValueError (multiple non-None types)

PARAMETER DESCRIPTION
type_

The type annotation to extract the base type from

TYPE: type

RETURNS DESCRIPTION
Any

The base type

RAISES DESCRIPTION
ValueError

If Union contains multiple non-None types

register_element

register_element(element: Any) -> Any

Register an element in the global element registry.

type_hint_to_property

type_hint_to_property(
    name: str, type_hint: Any, field_metadata: dict[str, Any]
) -> ElementProperty

Converts a type hint represented as a dictionary into an ElementProperty object.

This function introspects a provided type hint, extracting metadata and attributes of the type hint to create an ElementProperty. The extracted information includes whether the type is optional, represents multiple items, or is associated with an attribute. The function relies on type inspection utilities to derive these characteristics and use them to initialize the ElementProperty.

PARAMETER DESCRIPTION
name

The name associated with the type hint or field.

TYPE: str

type_hint

The type hint which defines the expected type or structure.

TYPE: Any

field_metadata

Metadata associated with the field, containing information about whether the field is an attribute or an element.

TYPE: dict[str, Any]

RETURNS DESCRIPTION
ElementProperty

Returns an ElementProperty object that captures the metadata, name, and type information

ElementProperty

inferred from the type hint.