How to get rule information programatically in JBoss BRMS 6.1?

Solution Unverified - Updated -

Environment

  • Red Hat JBoss BRMS (BRMS) 6.1

Issue

  • Is there any class to get information about business process, rules etc?
  • There is a need to read each and every rule and get the rule information like it's package, salience, rule flow group etc..
  • How to get information from rules programatically in JBoss BRMS 6.1?

Resolution

It is possible to get rule information by using org.drools.core.definitions.rule.impl.RuleImpl internal class that contains all data from a rule as follows:

    Collection<KiePackage> kPackages = kSession.getKieBase().getKiePackages();
    for (KiePackage nextPackage : kPackages) {
        Collection<Rule> rules = nextPackage.getRules();
        for (Rule nextRule : rules) {
        RuleImpl r = (RuleImpl) nextRule;
        System.out.println(" ------------------ ");
        System.out.println("Package: " + r.getPackageName() + " - Rule Name: " + r.getName() + " - Dialect: " + r.getDialect());
        }
    }

If you need further details from LHS/RHS data, in RuleImpl class it is possible to find a reference to the input stream of the given rule file. So you could also retrieve that data. Please see a sample (load-rule-content.zip) attached.

Note: Since it is an internal class its code can be changed in a next release or update. Therefore we can not guarantee that it will maintain the same code between updates.

Attachments

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments