Class: Ea::Transformers::QeaToXmi::IdAllocator
- Inherits:
-
Object
- Object
- Ea::Transformers::QeaToXmi::IdAllocator
- 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 perTransformer#serializecall).<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_...). Whenparent_guidis 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
-
#allocate(prefix:, seed: nil, parent_guid: nil) ⇒ String
E.g.
-
#initialize ⇒ IdAllocator
constructor
A new instance of IdAllocator.
Constructor Details
#initialize ⇒ IdAllocator
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".
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 |