Creating objects in the master ruleset and using them in the child ruleset

It is important to understand how objects that are created in the master ruleset are also used in the child ruleset.

Consider the following scenario:
  • The master ruleset creates an instance a of a class A, and passes it to the child ruleset.
  • The child ruleset has rules that use a.
Because both rulesets have rules that use the class A, the class A is included in the managed XOM for both rulesets.

Default relationship between the XOM class loaders of the rulesets
The class A is in the MXOM 1 class loader and the MXOM 2 class loader. Therefore, the instances of the class A from MXOM 1 and MXOM 2 are not the same.

When the master ruleset creates instances of A, they are in a different class loader from the one expected by the child ruleset. It might prevent the rules from working correctly.

The solution is to define the managed XOM class loader of the master ruleset (MXOM 1) as the parent of the managed XOM class loader of the child ruleset (MXOM 2). In a class loader mode parent first, the class loader loads the class of MXOM 1 class loader first, and then finds the class in MXOM 1.

Default relationship between the XOM class loaders of the rulesets

This is achieved by using the following code in the RulesetChildRunner class:
cfg.setXOMClassLoader(RulesetChildRunner.class.getClassLoader());
It assumes that the RulesetChildRunner class is in the managed XOM of the master ruleset. If it is not the case, you must use another way to get the class loader of the managed XOM of the master ruleset.