[rules-users] Iterating facts

Davide Sottara dsotty at gmail.com
Fri Oct 12 13:03:42 EDT 2012


FactType (and FactField etc..) are an internal representation of a declared
type's CLASS, hence you can get names, types, etc.. but obviously NOT any
instance's values from there. 

You'll need something like this:

FactType factType = ksession.getKnowledgeBase().getFactType(pckg, "Project")
List<FactField> fFields =  factType.getFields(); 

// get all Project INSTANCES currently in the WM
Collection objs = kSession.getObjects( new ClassObjectFilter(
factType.getFactClass() );
for ( Object o : objs ) 
  for ( FactField field : fFields )  
    Object fieldValue = factType.get( o, field.getName() );


FactType exposes generic "get" and "set" methods which use a reflection-like
mechanism to operate on instances extracted from the WM. Notice that since
declared types are transformed into classes at RUNTIME, there is no way to
do it at compile time without this "meta" approach.

Best
Davide







--
View this message in context: http://drools.46999.n3.nabble.com/Iterating-facts-tp4020214p4020254.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list