jeudi 12 mars 2020

Drools - How to get Enum values defined in drl file of drools from kie java api

I have following snippet in which i am trying to find out the emun from the facts and then get all the emun values from it -

private static void printEnums(KieContainer kContainer) throws Exception {
        KieBase kieBase = kContainer.getKieBase();
        Collection<KiePackage> packages = kieBase.getKiePackages();
        for (KiePackage kiePackage : packages) {
            Collection<FactType> facts = kiePackage.getFactTypes();
            for (FactType factType : facts) {
                if (factType.getSuperClass() != null && factType.getSuperClass().equalsIgnoreCase("java.lang.Enum")) {
                    if (factType.getSuperClass().equalsIgnoreCase("java.lang.Enum")) {
                        System.out.println("ENUM : " + factType.getName() + ", " + factType);
                        // TODO: Get all emun values
                    }
                }

            }
        }
    }

In above example the emum in defined in drl file of drools.

What i wated to do is something like - say if i had an enum defined in java say Category than i want to do something like floowing in TODO sectio n of above code snippet -

 for (Category type : Category.values()) {
          kieSession.insert(type);
  }

How can i do this for non java ENUM which is declared in drl file itself ?





Aucun commentaire:

Enregistrer un commentaire