<br> Samir,<br><br> First thing to try is to use DRLDumper to dump your descriptor to DRL source... it will be easy to "see" if you are doing anything wrong with the descriptor classes...<br><br> []s<br> Edson<br>
<br><div><span class="gmail_quote">2008/3/3, samirsss <<a href="mailto:samirsavla@gmail.com">samirsavla@gmail.com</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br> Hi,<br> <br> Here's the source code of the rule I am trying to add:<br> <br> public void testDynamicRules()<br> {<br> //Create a rule dynamically and check if it fired from log statements<br> RuleBase ruleBase = wm.getRuleBase();<br>
Package[] pkg = ruleBase.getPackages();<br> if(pkg[0] != null)<br> {<br> logger.warn("Package size before adding the rule :<br> "+pkg[0].getRules().length);<br> //Building a new package<br>
final PackageDescr packageDescr = new PackageDescr(pkg[0].getName() );<br> <br> //Building ruleDescriptor<br> RuleDescr ruleDescr = null;<br> String consequence = "mediator.addedNewRule();\n";<br>
//String consequence = "logger.warn(\"New rule just got fired\");";<br> ruleDescr = new RuleDescr( "Added new Rule");<br> AndDescr lhs = new AndDescr();<br>
ruleDescr.setLhs( lhs );<br> <br> final PatternDescr pattern = new PatternDescr(<br> ApplicationEvent.class.getName(),<br> "newAppEvent");<br> lhs.addDescr( pattern );<br>
<br> <br> final LiteralRestrictionDescr restrictionMessage = new<br> LiteralRestrictionDescr("==", "Test2", LiteralRestrictionDescr.TYPE_STRING);<br> final FieldConstraintDescr returnValue = new FieldConstraintDescr(<br>
"messageId" );<br> returnValue.addRestriction(restrictionMessage);<br> <br> pattern.addConstraint(returnValue);<br> <br> ruleDescr.setConsequence( consequence );<br> List attributes = new ArrayList<AttributeDescr>();<br>
attributes.add(new AttributeDescr("salience", "98"));<br> attributes.add(new AttributeDescr("enabled", "true"));<br> ruleDescr.addAttribute( new AttributeDescr("dialect", "java") );<br>
ruleDescr.setAttributes(attributes);<br> <br> Package defaultPackage = pkg[0];<br> PackageBuilderConfiguration conf = new PackageBuilderConfiguration();<br> PackageBuilder builder = new PackageBuilder( defaultPackage, conf );<br>
<br> //Adding rule to the package<br> packageDescr.addRule( ruleDescr );<br> builder.addPackage(packageDescr);<br> int errors = builder.getErrors().getErrors().length;<br>
if(errors > 0)<br> {<br> //TODO remove the recently added rule or reload all the rules from<br> the DRL file<br> logger.warn("Error while adding a rule");<br>
<br> }<br> else<br> {<br> Rule newRule = builder.getPackage().getRule(ruleDescr.getName());<br> //String ruleFlowName = newRule.getRuleFlowGroup()<br>
//newRule.get<br> //Check is the rule got added<br> logger.warn("Package size after adding the rule :<br> "+pkg[0].getRules().length);<br> }<br>
}<br> else<br> {<br> logger.warn("Error getting default package for adding rules");<br> }<br> <br> }<br> <br> <br> public void addedNewRule()<br> {<br> //Just testing addition of new rules.<br>
logger.warn("New rule just got fired");<br> }<br> <br> I cant seem to get the consequence to get fired. I have a similar rule in my<br> drl file where the messageID == "Test" and it works fine.<br>
<br> Any help is really helpful here cause I am stuck at this point and might<br> have to go to creating xml files for the rules and parsing that.<br> <br> Thanks<br> Samir<br> <br><br> --<br> View this message in context: <a href="http://www.nabble.com/Cant-seem-to-fire-a-dynamically-added-rule-tp15810172p15810172.html">http://www.nabble.com/Cant-seem-to-fire-a-dynamically-added-rule-tp15810172p15810172.html</a><br>
Sent from the drools - user mailing list archive at <a href="http://Nabble.com">Nabble.com</a>.<br> <br> _______________________________________________<br> rules-users mailing list<br> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br> </blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br>
Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>