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.
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:
***************
Package pkg = ...; // obtain a package from the package builder or from the
rulebase
Set<Class<?>> usedClasses = new HashSet<Class<?>>();
for( Rule rule : pkg.getRules() ) {
RuleConditionElement lhs = rule.getLhs();
collectUsedClasses( usedClasses, lhs );
}
**************
public void collectUsedClasses( Set<Class<?>> usedClasses,
RuleConditionElement rce ) {
if( rce instanceof Pattern ) {
ObjectType ot = ((Pattern)rce).getObjectType();
if( ot instanceof ClassObjectType ) {
usedClasses.add( ((ClassObjectType)ot).getClassType() );
}
}
for( RuleConditionElement child : rce.getNestedElements() ) {
collectUsedClasses( usedClasses, child );
}
}
******************
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.
Edson
2009/11/24 Barry Kaplan <groups1(a)memelet.com>
Ah, yes Edson. I didn't even think of that. That will probably force my
hand
to filter.
But that then leaves me with how to determine the set of classes used in
the
rules. Doing it by textual inspection is not viable since rules can be
added
as part of the application (by "users'). So that pointer on how to
determine
used fact types would be much appreciated.
--
View this message in context:
http://old.nabble.com/Does-Session-effeciently-filter-unused-facts%2C-or....
Sent from the drools - user mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
JBoss Drools Core Development
JBoss by Red Hat @
www.jboss.com