<br> Can you please provide an executable, self contained test case? I will take a look.<br><br> []s<br> Edson<br><br><div><span class="gmail_quote">2008/3/4, 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> I tried using the jars from the 4.0.x branch after building them and that<br> still doesnt seem to change the outcome. I see that the package builder has<br> the rule added to it and the count of the rules from it is incremented.<br>
<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>
//Building ruleDescriptor<br> RuleDescr ruleDescr = null;<br> <br> String consequence = "\t\t mediator.addedNewRule();\n";<br> <br> ruleDescr = new RuleDescr( "Added new Rule");<br>
AndDescr lhs = new AndDescr();<br> ruleDescr.setLhs( lhs );<br> <br> final PatternDescr pattern = new PatternDescr( "ApplicationEvent",<br> //.class.getName(),<br> "newAppEvent");<br>
lhs.addDescr( pattern );<br> <br> <br> final FieldConstraintDescr insertedValue = new FieldConstraintDescr(<br> "inserted" );<br> final LiteralRestrictionDescr insertedFieldRes = new<br>
LiteralRestrictionDescr("==", "false",<br> LiteralRestrictionDescr.TYPE_BOOLEAN);<br> insertedValue.addRestriction(insertedFieldRes);<br> pattern.addConstraint(insertedValue);<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>
<br> attributes.add(new AttributeDescr("salience", "101"));<br> <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> <br> packageDescr.addRule( ruleDescr );<br> builder.addPackage(packageDescr);<br> <br> <br> DrlDumper drlDumper = new DrlDumper();<br> <br> logger.warn("Dumping Package Descriptor for all rules: "+<br>
drlDumper.dump(packageDescr));<br> <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>
<br> logger.warn("Package after adding the rule : "+newRule.toString()+":<br> contains: "+pkg[0].getRules().length+" rules");<br> <br> }<br> }<br>
else<br> {<br> logger.warn("Error getting default package for adding rules");<br> }<br> <br> }<br> <br> <br>I am trying to figure out if I am doing something wrong or its an issue with<br>
Drools.<br> <br>--<br> View this message in context: <a href="http://www.nabble.com/Cant-seem-to-fire-a-dynamically-added-rule-tp15810172p15834611.html">http://www.nabble.com/Cant-seem-to-fire-a-dynamically-added-rule-tp15810172p15834611.html</a><br>
<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>