[rules-users] How to create object model (parse into object) from mvel string in drl file?

neal swapnilaute at gmail.com
Tue Jan 21 08:45:10 EST 2014


Below is the template to generate the rule statement (It is basic one).
What I want to do is to read the string and convert into object.

package @{package};

@foreach{importEntry : imports}
import @{importEntry};
@end{}

@foreach{importEntry : staticImports}
import static @{importEntry};
@end{}

rule "@{ruleName}"

dialect "@{dialectName}"
salience @{salienceValue}
enabled @{enableValue}

when
@foreach{modelObject : modelObjects} @{modelObject.referenceName} :
@{modelObject.referenceType} ( @foreach{ attribute : modelObject.attributes}
@{attribute.name} @{attribute.operator} "@{attribute.value}" @end{} ) @end{}

then
// tempate data to set attribute
end

/ code to run the tempate
TemplateRegistry RULE_REGISTRY = new SimpleTemplateRegistry();

RULE_REGISTRY.addNamedTemplate( "rules",
getCompiledTemplate(prepareSimpleTemplate()));
System.out.println(TemplateRuntime.execute(
RULE_REGISTRY.getNamedTemplate( "rules" ),
getMap(),RULE_REGISTRY ));
}


// method to get tempate in string
public static String prepareSimpleTemplate() {
return StringUtils.readFileAsString(new InputStreamReader(
       MvelDemo.class.getResourceAsStream("RuleTemplate.mvel")));
}

The rule statement generated is:

package some;

import rout.Vo;

rule "Row_001"

dialect "mvel"
salience 10
enabled true

when
 vo : Vo (  type_code == "S"  ) 
then
 vo.a_name = "X" 
end

How to generate object model from String generated from MVEL template? Is
there any parser available to convert String into Object model in MVEL?



--
View this message in context: http://drools.46999.n3.nabble.com/How-to-create-object-model-parse-into-object-from-mvel-string-in-drl-file-tp4027793.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list