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 — literal <lowerValue>/<upperValue>
bounds, instance slots and their values, return parameters.
EA's scheme, derived from examples/exports/*/model.xml:
EAID_<PREFIX><NNNNNN><SEP><TAIL27>
<PREFIX>is a Sparx-reserved literal prefix (LI, SL, OE, RT).<NNNNNN>is a 6-digit zero-padded counter. LI counts GLOBALLY from 1 in allocation order (lower before upper, destination end before source end, document walk order across owners). SL, OE and RT count from 0 PER OWNING ELEMENT (slots/values per InstanceSpecification, return parameters per operation).<TAIL27>is the owner ID's last 27 characters (the EA GUID minus its first segment).<SEP>is as many underscores as keep the synthesized ID the same total width as the owner ID (one for 41-char EAID_ owners, two for 42-char src/dst association-end owners).
The allocator memoizes by [owner_id, prefix, seed]: the same triple always returns the same ID without advancing any counter.
signature follows the transformer's needs, not semver.
Constant Summary collapse
- LITERAL_INTEGER =
Well-known prefixes Sparx uses for synthesized IDs.
"LI"- OPAQUE_EXPRESSION =
"OE"- SLOT =
"SL"- RETURN_PARAMETER =
"RT"- GLOBAL_PREFIXES =
Prefixes whose counter runs across the whole document, starting at 1. All other prefixes restart at 0 per owner.
[LITERAL_INTEGER].freeze
- TAIL_LENGTH =
27- HEAD_LENGTH =
"EAID_" plus the 8-character prefix+counter token.
13
Instance Method Summary collapse
-
#allocate(prefix:, owner_id:, seed:) ⇒ String
E.g.
-
#initialize ⇒ IdAllocator
constructor
A new instance of IdAllocator.
Constructor Details
#initialize ⇒ IdAllocator
Returns a new instance of IdAllocator.
46 47 48 49 50 |
# File 'lib/ea/transformers/qea_to_xmi/id_allocator.rb', line 46 def initialize @global_counters = Hash.new(0) @owner_counters = Hash.new(0) @assigned = {} end |
Instance Method Details
#allocate(prefix:, owner_id:, seed:) ⇒ String
Returns e.g. "EAID_LI000001__EEB1_4de7_98F5_670D6EE4A52B".
59 60 61 62 63 64 |
# File 'lib/ea/transformers/qea_to_xmi/id_allocator.rb', line 59 def allocate(prefix:, owner_id:, seed:) key = [owner_id, prefix, seed] return @assigned[key] if @assigned.key?(key) @assigned[key] = compose_id(prefix, next_counter(prefix, owner_id), owner_id) end |