Search in sources :

Example 1 with RuleUnitExecutorImpl

use of org.drools.ruleunits.impl.sessions.RuleUnitExecutorImpl in project drools by kiegroup.

the class InterpretedRuleUnit method internalCreateInstance.

@Override
public RuleUnitInstance<T> internalCreateInstance(T data) {
    KnowledgeBuilder kBuilder = new KnowledgeBuilderImpl();
    Class<? extends RuleUnitData> wmClass = data.getClass();
    String canonicalName = wmClass.getCanonicalName();
    // transform foo.bar.Baz to /foo/bar/Baz.drl
    // this currently only works for single files
    InputStream resourceAsStream = wmClass.getResourceAsStream(String.format("/%s.drl", canonicalName.replace('.', '/')));
    kBuilder.add(new InputStreamResource(resourceAsStream), ResourceType.DRL);
    InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
    kBase.addPackages(kBuilder.getKnowledgePackages());
    ReteEvaluator reteEvaluator = new RuleUnitExecutorImpl(kBase);
    return new InterpretedRuleUnitInstance<>(this, data, reteEvaluator);
}
Also used : ReteEvaluator(org.drools.core.common.ReteEvaluator) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) RuleUnitExecutorImpl(org.drools.ruleunits.impl.sessions.RuleUnitExecutorImpl) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) InputStream(java.io.InputStream) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) InputStreamResource(org.drools.core.io.impl.InputStreamResource)

Aggregations

InputStream (java.io.InputStream)1 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)1 ReteEvaluator (org.drools.core.common.ReteEvaluator)1 InputStreamResource (org.drools.core.io.impl.InputStreamResource)1 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)1 RuleUnitExecutorImpl (org.drools.ruleunits.impl.sessions.RuleUnitExecutorImpl)1 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)1