<br> In current Drools versions, you will need to use some "internal APIs" for that, but we can probably add a higher level method call for the next version. <br> The LHS of a rule is a tree of RuleConditionElements. What you need to do is navigate the tree recursively using the getNestedElements() method and looking for Patterns. In pseudo algorithm:<br>
<br>***************<br>Package pkg = ...; // obtain a package from the package builder or from the rulebase<br><br>Set<Class<?>> usedClasses = new HashSet<Class<?>>();<br>
for( Rule rule : pkg.getRules() ) {<br> RuleConditionElement lhs = rule.getLhs();<br> collectUsedClasses( usedClasses, lhs );<br>}<br>**************<br><br>public void collectUsedClasses( Set<Class<?>> usedClasses, RuleConditionElement rce ) {<br>
if( rce instanceof Pattern ) {<br> ObjectType ot = ((Pattern)rce).getObjectType();<br> if( ot instanceof ClassObjectType ) {<br> usedClasses.add( ((ClassObjectType)ot).getClassType() );<br>
}<br> }<br> for( RuleConditionElement child : rce.getNestedElements() ) {<br> collectUsedClasses( usedClasses, child );<br> }<br>}<br><br>******************<br><br> I wrote the above code directly into the e-mail, so there might be some mistakes, but the idea is there... so you can probably figure out, based on that.<br>
<br> Edson<br><br><div class="gmail_quote">2009/11/24 Barry Kaplan <span dir="ltr"><<a href="mailto:groups1@memelet.com">groups1@memelet.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im"><br>
Ah, yes Edson. I didn't even think of that. That will probably force my hand<br>
to filter.<br>
<br>
But that then leaves me with how to determine the set of classes used in the<br>
rules. Doing it by textual inspection is not viable since rules can be added<br>
</div>as part of the application (by "users'). So that pointer on how to determine<br>
used fact types would be much appreciated.<br>
<div><div></div><div class="h5"><br>
--<br>
View this message in context: <a href="http://old.nabble.com/Does-Session-effeciently-filter-unused-facts%2C-or...-tp26489782p26507196.html" target="_blank">http://old.nabble.com/Does-Session-effeciently-filter-unused-facts%2C-or...-tp26489782p26507196.html</a><br>
Sent from the drools - user mailing list archive at Nabble.com.<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" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> JBoss by Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>