Class: Ea::Transformers::QeaToXmi::IdAllocator

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/transformers/qea_to_xmi/id_allocator.rb

Overview

Allocates synthetic xmi:id values for elements that don't have a natural GUID-based one — e.g. literal <lowerValue> nodes, or <ownedComment> bodies synthesized from EA's Note objects.

Sparx's EAID format reserves prefixes like LI (LiteralInt), SL (Slot), NL (NameLabel), DB (DiagramBounds), OE (OpaqueExpr), RT (Return parameter) for these synthesized identifiers.

Output shape: EAID_<PREFIX><NNNNNN><GUID_TAIL> where:

  • EAID_ matches the prefix used by all other Sparx XMI element IDs.
  • <PREFIX> is a Sparx-reserved literal prefix (LI, SL, OE, ...).
  • <NNNNNN> is a 6-digit zero-padded counter, scoped to the IdAllocator instance (one per Transformer#serialize call).
  • <GUID_TAIL> is the parent element's EA GUID normalised to Sparx's wire form. The leading underscore from the opening brace of {GUID-...} is preserved so the output matches real Sparx XMI byte-for-byte (e.g. EAID_LI000001__EEB1_...). When parent_guid is nil, no tail is emitted.

The allocator is memoised by seed: same seed returns the same allocated ID. Different seeds get different counters.

Constant Summary collapse

LITERAL_INTEGER =

Well-known prefixes Sparx uses for synthesized IDs.

"LI"
OPAQUE_EXPRESSION =
"OE"
SLOT =
"SL"
NAME_LABEL =
"NL"
DIAGRAM_BOUNDS =
"DB"
RETURN_PARAMETER =
"RT"
GUID_BRACE_OR_DASH =

Leading-underscore-preserving normalisation: {AB-CD}_AB_CD. Matches the wire form Sparx emits for parent-guid-suffixed IDs.

/[-{}]/

Instance Method Summary collapse

Constructor Details

#initializeIdAllocator

Returns a new instance of IdAllocator.



41
42
43
44
# File 'lib/ea/transformers/qea_to_xmi/id_allocator.rb', line 41

def initialize
  @counter = 0
  @assigned = {}
end

Instance Method Details

#allocate(prefix:, seed: nil, parent_guid: nil) ⇒ String

Returns e.g. "EAID_LI000001__EEB1_4de7_98F5_670D6EE4A52B".

Parameters:

  • prefix (String)

    one of LITERAL_INTEGER, OPAQUE_EXPRESSION, ...

  • seed (String, nil) (defaults to: nil)

    stable seed for memoization (e.g. the source record's object_id). Same seed returns same allocated id.

  • parent_guid (String, nil) (defaults to: nil)

    the owning element's EA GUID (e.g. {EEB1-...}). When provided, the synthesised ID carries the parent GUID tail so it is traceable and round-trip-safe.

Returns:

  • (String)

    e.g. "EAID_LI000001__EEB1_4de7_98F5_670D6EE4A52B"



53
54
55
56
57
58
59
60
# File 'lib/ea/transformers/qea_to_xmi/id_allocator.rb', line 53

def allocate(prefix:, seed: nil, parent_guid: nil)
  return @assigned[seed] if seed && @assigned.key?(seed)

  @counter += 1
  id = compose_id(prefix: prefix, n: @counter, parent_guid: parent_guid)
  @assigned[seed] = id if seed
  id
end