ModelLoadingListeners
ModelLoadingListeners are custom logic that hook into the Model Loading logic.
Listeners can be defined in DataResources, they describe a ModelLoadingStep to which to subscribe and an implementation that point to a java class. After the step in the model loading process has been performed, all listeners subscribed to that step will be executed.
You can subscribe to any of these steps:
- ExtractResourcesStep
- PrepareModelStep
- ReadModelStep
- ConvertModelStep
- EnrichModelStep
- ConfigureExpansionStep
- modelLoadingListeners.xml
- MyModelLoaderListener.java
Add a DataResource file to your expansion-resource:
<dataResource type="expansionControl::ModelLoadingListener">
<modelLoadingListener name="MyModelLoaderListener">
<modelLoadingStep name="ExtractResourcesStep"/>
<implementation>org.example.MyModelLoaderListener</implementation>
</modelLoadingListener>
</dataResource>
Provide a java class that implements the ModelLoadingStepListener
interface.
The interface is typed with the result class of the step (always named after the step, but replace Step with Result).
import net.democritus.model.common.ModelLoadingContext;
import net.democritus.model.common.ModelLoadingStepListener;
import net.democritus.model.resources.ExtractResourcesResult;
public class MyModelLoaderListener implements ModelLoadingStepListener\<ExtractResourcesResult> {
@Override
public void afterStep(ExtractResourcesResult result, ModelLoadingContext context) {
// Do stuff
}
}
The net.democritus.mapping.CompositeElementFinder
class has a findAll()
method that can be used to find all
instances of a composite in a ExpansionCompositeModel
object, which can otherwise be hard to traverse.
Set<ValueFieldComposite> valueFields = CompositeElementFinder
.findAll(result.getExpansionCompositeModel(), ValueFieldComposite.class);