[rules-users] Access metadata of declared drools expert types in Java

Tobias Neef tobnee at gmail.com
Thu Dec 29 18:24:34 EST 2011


Hi,

First I have to say. Drools is a very nice tool with great
documentation. Thats the first time I have to use the ML because I
write a little framework which makes some obscure use of Drools expert
;).

But now my problem: I have a type which I declared like:

declare MyMarker
	@Marker	
	feature : String @Feature
end	

When I put an instance of that type into the KB I want to grab those
entries with a given @Marker / annotation. So I tried doing that with
reflection on the MyMarker class which did not work. Also when I try
to get a FactType instance I do not find a way to access those
metadata information. For the class annotation @Marker I see that the
FactType instance contains a private field annotation which includes
the correct type. But I see no way to access this information. The
feature field itself can be accessed but no annotation information is
available:

{feature=FieldDefinition{name='feature', type='java.lang.String',
key=false, inherited=false, index=1, initExpr='null',
annotations=null, accessor=[ClassFieldExtractor class=package.MyMarker
field=feature]}

A second minor problem is the way I access the fact type. Is there a
better way to do this?

for (Object object : result) {
 Class c = object.getClass();
 Package p = c.getPackage();
 String packagename = p.getName();
 String classname = c.getSimpleName();
 FactType ft = knowledgeBase.getFactType(packagename, classname);
if (ft!=null) {
 //stuff
}}}

Best Regards,
Tobias Neef



More information about the rules-users mailing list