Skip to main content

Expansion Context

During expansion, the expanders-core framework will process each element in the model to run any Expanders, Features or expansion steps.

When an element is being processed, additional information is added in the form of an expansion context. It contains:

  • Information about the elements' ancestors in the model.
  • File locations of the sources and expansion.
  • The ExpansionConfiguration element.
  • A list of applicable layerTypes.

Program Expansion Context

The top expansion context is always a ProgramExpansionContext. The program is the main root of the model and this is where the expansion begins.

E.g. when expanding an Application euRentApp, there will be a ProgramExpansionContext containing the euRentApp ApplicationComposite.

The expansionDirectory will be set to the directory of the program. The sourceDirectory will point towards the location of the harvest and ext files of the program.

The expansion context also lists the layerImplementations applicable to the program. These can be used to expand build files, listing the required dependencies.

Accessing ProgramExpansionContext

Every expansion context contains a reference to the ProgramExpansionContext, which can be accessed via the Context object:

ProgramExpansionContext programExpansionContext = expansionContext.getContext()
.get(ProgramExpansionContext.class);

Module Expansion Context

Each program can have a number of modules. The modules provide their own expansionContext.

This ModuleExpansionContext contains a expansionDirectory, a sourceDirectory and layerImplementations similar to the ProgramExpansionContext. The directories point towards the sources and expansion specific to the module.

Accessing ModuleExpansionContext

Expansion context can contain a reference to a ModuleExpansionContext if one of the ancestors is a Module. It can also be accessed via the Context object.

Optional<ModuleExpansionContext> moduleExpansionContext = expansionContext.getContext()
.find(ModuleExpansionContext.class);

Element Expansion Context

Each element in the model is subsequently wrapped in an implementation of the ElementExpansionContext interface. However, this interface does not add a lot of useful information. In most cases, the expansion context can be handled as a CompositeExpansionContext instance, which is the root interface of all expansion context classes.

Parent Expansion Context

Though rarely used, the expansion context of the direct model parent can be accessed by casting the expansion context object to the SubExpansionContext interface.

LayerTypes

Every expansion context contains a list of layerTypes. These are the layerTypes that are applicable to the element instance.

In most cases, the layers are defined by the program or module ancestor. However, there are options that allow you to exclude certain layerTypes for an element and its children.

Expansion Configuration Expansion Context

Expansion contexts always contain a ExpansionConfigurationContext object. This object gives access to many of the technical expansion services.

See also: ExpansionConfigurationComposite


Custom Expansion Context classes

For backwards compatibility, it is possible to define ExpansionContext classes that replace the common ExpansionContext classes for specific elements.