[rules-users] How to generate rule statements using MVEL 2.0 template?
Mark Proctor
mproctor at codehaus.org
Wed Jan 15 07:52:27 EST 2014
It’s a bit low level, but this is how we generate stuff in drools;
https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/main/java/org/drools/compiler/rule/builder/dialect/java/JavaRuleBuilderHelper.java
https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/main/resources/org/drools/compiler/rule/builder/dialect/java/javaRule.mvel
I would avoid drools-templates, stick directly with MVEL templates.
Mark
On 15 Jan 2014, at 09:24, Michael Anstis <michael.anstis at gmail.com> wrote:
> You could take a look at drools-templates, and relevant sections in the user guide, as a starter.
>
> If that does not cover your requirements take a look at drools-templates source code on github.
>
> Alternatively have a look for MVEL templates on Google (other search engines are available).
>
> With kind regards,
>
> Mike
>
> Sent on the move
>
> On 15 Jan 2014 09:20, "neal" <swapnilaute at gmail.com> wrote:
> I came to know through drool user forum that a drl file can be created using
> recursive MVEL 2.0 template.
> I am trying like below.
>
> public static String prepareRule(String RuleName){
> String template = "\n rule \""+RuleName+"\" "+
> "\n dialect \"mvel\" "+
> "\n salience \"10\" " +
> "\n when" +
> "\n demo : Demo( one == \"N\" , two == \"C\" , three == 1005 )" +
> "\n then" +
> "\n demo.setFirst( 4003 );" +
> "\n demo.setLast( 4003 );" +
> "\n demo.setRuleID( \"SEQ_1\" );";
> return template;
> }
>
> public static String getRuleAsString(String template){
> Map vars = new HashMap();
> return (String) TemplateRuntime.eval(template,vars);
> }
>
> public static void main(String[] args) {
>
> System.out.println(getRuleAsString(prepareRule("Rule 1")));
> }
>
> When i am printing it out, It is generating rule skeleton. I am planning to
> create whole rule stuff passing arguments like rule name in the example. Am
> i doing correct?
> How to do it correctly?
>
>
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/How-to-generate-rule-statements-using-MVEL-2-0-template-tp4027692.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20140115/c0c2da05/attachment-0001.html
More information about the rules-users
mailing list