Skip to main content

Using Layer Implementations in Expanders

Both the ProgramExpansionContext and ModuleExpansionContext interfaces support having a list of layerImplementations. These implementations are provided by the factories, which use a single class, LayerImplementationResolver, to fetch and filter them.

In mapping files, you can access them directly, though they might still need to be filtered on layerType:

<list name="implementations" eval="expansionContext.layerImplementations" param="layerImplementation">
<filter name="isControlLayerImplementation"
eval="layerImplementation.layerType eq controlLayer"/>
<value name="subdir" eval="layerImplementation.technology.subdir"/>
</list>
note

The layerImpls are only available on the programExpansionContext or moduleExpansionContext, so you will need to navigate to the correct context. In case of ApplicationInstance, you will need to access the parent context.

<let name="programExpansionContext" eval="expansionContext.parentExpansionContext"/>
<list name="implementations" eval="programExpansionContext.layerImplementations"
param="layerImplementation">

Tests

In tests, the layerImplementations will be constructed based on data-resources as during expansion. However, if you wish to have a more stable test, you can override the layerImplementations in the test.

  @Test
public void testBase() {
tester.extendContext(this::setLayerImplementations);
tester.testBase(baseModel());
}

private void setLayerImplementations(CompositeExpansionContext<?> expansionContext) {
ProgramExpansionContext<?> programExpansionContext = expansionContext.getContext().get(ProgramExpansionContext.class);
programExpansionContext.setLayerImplementations(
specBuilder.build(
layerImplementation("commonControl",
set("condition", "true"),
dataRef("layerType", "CONTROL_LAYER"),
dataRef("technology", "COMMON"),
layerSource("",
dataRef("sourceType", "SRC")),
layerSource("",
dataRef("sourceType", "RESOURCE"))),
layerImplementation("strutsControl",
set("condition", "true"),
dataRef("layerType", "CONTROL_LAYER"),
dataRef("technology", "STRUTS2"),
layerSource("",
dataRef("sourceType", "SRC")),
layerSource("",
dataRef("sourceType", "RESOURCE")))));
}