drools中是否有任何API通过传递值动态创建drl文件? [英] Is there any API in drools to create the drl files dynamically by just passing values?

查看:1008
本文介绍了drools中是否有任何API通过传递值动态创建drl文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何使用所有方法在KIE工作台中创建DRL文件。但是我的问题是没有使用KIE工作台,我们可以使用我们要求的值创建 .drl 文件。如果有任何可能性,请建议我。同样的方式建议我任何API都与此有关。在此先感谢。

I know how to create DRL files inside KIE workbench by using all the methods. But what my problem is without using the KIE workbench, can we create the .drl file by using our required values.If any possibility is there please suggest me. Same way suggest me any API is regarding to that. Thanks in advance.

推荐答案

您可以使用 Drools Fluent API 。请尝试以下示例代码:

You can use Drools Fluent API. Try below sample code :

package com.sample;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

import org.drools.lang.DrlDumper;
import org.drools.lang.api.DescrFactory;
import org.drools.lang.descr.PackageDescr;

@SuppressWarnings("restriction")
public class Drl_Creator {
    public static void main(String str[]){
        PackageDescr pkg = DescrFactory.newPackage()
                   .name("org.drools.example")
                   .newRule().name("Xyz")
                       .attribute("ruleflow-grou","bla")
                   .lhs()
                       .and()
                           .pattern("Foo").id( "$foo", false ).constraint("bar==baz").constraint("x>y").end()
                           .not().pattern("Bar").constraint("a+b==c").end().end()
                       .end()
                   .end()
                   .rhs( "System.out.println();" ).end()
                   .getDescr();
        DrlDumper dumper=new DrlDumper();
        String drl=dumper.dump(pkg);
        System.out.print(drl);
        try{
            // create new file
            File file = new File("src/main/rules/test.drl");
            file.createNewFile();
            FileWriter fw = new FileWriter(file.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(drl);
            // close connection
            bw.close();
            System.out.println("File Created Successfully");
         }catch(Exception e){
             System.out.println(e);
         }
    }
}

这篇关于drools中是否有任何API通过传递值动态创建drl文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆