System.out.println(sb.toString());
PackageBuilderConfiguration config = new PackageBuilderConfiguration
();
config.setClassLoader(this.getClass().getClassLoader());
// enable the Janino compiler instead of JDT for Java semantics
JavaDialectConfiguration javaConf = (JavaDialectConfiguration)
config
.getDialectConfiguration("java");
javaConf.setCompiler(JavaDialectConfiguration.JANINO);
PackageBuilder builder = new PackageBuilder(config);
builder.addPackageFromDrl(
new StringReader(sb.toString()));
if (builder.hasErrors()) {
System.err.print(builder.getErrors());
return -1;
}
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage(builder.getPackage());
StatelessSession session = ruleBase.newStatelessSession();
Order order = new Order();
order.setSumprice(33);
session.execute(Arrays.asList(new Object[] { order }));
System.out.println("DISCOUNT IS: " + order.getDiscounts());
供大家参考。
当然前提是这些groovy所需的类在classpath中,如果要大规模用的话,让用户可以上传jar或class,然后整一个基于db或其他机制的classloader也是必不可少的。
--------------------------------------------------
From: "xiyuan76" <weiho...@163.com>
Sent: Wednesday, November 25, 2009 1:17 PM
To: "Groovy用户组" <groo...@googlegroups.com>
Subject: [Groovy用户组] Drools 规则入库的使用
另外,再提供一个测试环境,可以象某些测试存储过程的IDE一样,根据存储过程的输入自动产生输入框,这样用户可以提供输入。
然后比较输出是否正确就可以了。
对于测试,我认为隔离性是最重要的。所有东西如果都染到一起,反而适得其反。
Drools强大的一点在于,对于单个规则的重用,同时还提供了规则流的概念,很好,很好哪。
对于那种特别强调策略的场合,如移动的各种套餐,打折等等,把这些策略单独剥离出来,应用规则引擎是非常好的……
--------------------------------------------------
From: "songwei" <song...@gmail.com>
Sent: Wednesday, November 25, 2009 1:48 PM
To: <groo...@googlegroups.com>
Subject: 答复: [Groovy用户组] Re: Drools 规则入库的使用
--------------------------------------------------
From: "foxgem" <jianh...@hotmail.com>
Sent: Wednesday, November 25, 2009 2:00 PM
To: <groo...@googlegroups.com>
Subject: [Groovy用户组] Re: Drools 规则入库的使用
--------------------------------------------------
From: "weihong" <weiho...@163.com>
Sent: Wednesday, November 25, 2009 3:54 PM