Skip to content

Element <generator>

Purpose: Register a project-defined generator class under a descriptor-local identifier.

Why: Use it to bind a reusable generator expression to a project-local name.

Example

1
<generator name="id_generator" generator="IncrementGenerator(start=1)"/>

Decision guide

Business value: Lets several fields or tasks intentionally share one configured generator instance.

  • Use when

    • A stateful or expensive generator configuration must be reused by name.
  • Choose another approach when

    • Only one field uses the generator or independent instances are desired.
  • Prerequisites

    • Select a registered generator and a unique descriptor-local name.
  • Alternatives

    • Configure a one-off generator directly on key or id. (See: <key>)

Complete examples

Register and reuse one stateful generator instance

Use a named generator when several fields or tasks must deliberately share one configured generator instance rather than create independent instances.

named-generator/script/preflight.scr.py
1
assert 2 + 2 == 4
named-generator/datamimic.xml
1
2
3
4
5
6
7
<setup>
    <execute uri="script/preflight.scr.py"/>
    <generator name="document_sequence" generator="IncrementGenerator(start=100)"/>
    <generate name="documents" count="3" target="LogExporter">
        <id name="document_id" generator="document_sequence"/>
    </generate>
</setup>

Rules and invalid combinations

No additional element-specific rules. Required attributes, types, and supported values are shown below.

Allowed parents / Allowed children

Allowed parents: else, else-if, if, setup, while

Allowed children:

None

Attributes

Show all 2 attributes

generator

Generator expression to register.

required; string.

name

Name of the generator binding.

required; string.