Hi Tobias,
if you "declare" a type in a DRL file, a class is generated on the fly when
you add the resource to a knowledge base. To do so, internal representations
are created (TypeDeclaration, FieldDefinition, etc..) to help this code
generation process. The metadata themselves control the code generation and
are not usually attached to the final class. For example, the "@role(event)"
annotation instructs the engine to consider instances of the annotated class
as events, but is not reflected on the generated class.
(fyi, among other things it changes the type of HANDLE used to manage the
objects, but not the objects)
This said, annotations are indeed added to a generated class IF they
correspond to proper, resolvable java Annotations.
This means that, for you to be able to use reflection and find your @Marker
and @Feature Annotations, they 1) must have been created as java
Annotations, 2) ** their fully qualified name must be imported in the drl
like any other external class **
If this is not the case, please provide more details on your code and/or
open a jira.
if you want to see an example, here is another dark side of drools ;) where
reflection is applied directly in the LHS of some rules to detect the
presence of annotations:
https://github.com/droolsjbpm/drools-chance/blob/master/drools-informer/d...
https://github.com/droolsjbpm/drools-chance/blob/master/drools-informer/d...
An example of annotated class those rules would apply to is here:
https://github.com/Salaboy/drools-fipa-agents-impl/blob/master/clinical-d...
https://github.com/Salaboy/drools-fipa-agents-impl/blob/master/clinical-d...
As for the second question, no.. since the classes are generated at runtime,
reflection is the only way to access them and that's the syntax to get a
facttype from the KB. The only thing you can do is avoid the intermediate
variables :)
Best
Davide
--
View this message in context:
http://drools.46999.n3.nabble.com/rules-users-Access-metadata-of-declared...
Sent from the Drools: User forum mailing list archive at
Nabble.com.