Skip to main content

Transmuters for Model Extensions

Using extensions in Composite Builders

A metamodel can allow for extensions. For example the Component element is extendable, so you can add custom metamodels as its children. The component doesn't need to know about your metamodel for this to work. Because of that, the composite builder classes do not provide direct access to extensions.

To use the composite builder with extensions, the metamodel providing the extension can also provide adapters for the builder. If you're creating a metamodel, you can find more information on creating model builders here.

As an example, the Workflow metamodel is an extension to Component. The Workflow metamodel provides a WorkflowCompositeExtensionAdapter which can be used to transmute workflow elements. The following example adds a workflow element named ExampleFlow.

ComponentCompositeBuilder.merge(flowElement.getComponent(), context, component -> {
component.extensions(new WorkflowCompositeExtensionAdapter(), workflow -> {
workflow.name("ExampleFlow");
});
});

Transmuting abstract elements

Abstract elements can be defined in metamodels to create polymorphic relations.

E.g. the SimpleValueType has a relation to the abstract ValueTypeRestriction element. This type is not sealed meaning any other metamodel can add subtypes to this element. You could for example add a DateInMonth restriction which only accepts dates in a specific month.

Similarly to extensions, a DateInMonthCompositeAdapter can be provided to safely transmute this newly created subtype onto a SimpleValueType. The following example adds a DateInMonth element as a ValueTypeRestriction to a SimpleValueType.

SimpleValueTypeCompositeBuilder.merge(simpleValueType, context, valueType -> {
valueType.restrictions(new DateInMonthCompositeAdapter(), dateInMonth -> {
dateInMonth.month("april");
});
});