(Fact Templates are over and out.)<br><br>You create a TypeDeclaration by writing a DRL declare, which results in a considerable number of objects being created and available at run time: TypeDeclaration, ClassDefinition, FactField and FieldDeclaration and several other objects, the &quot;accessors&quot; So, you could create a piece of DRL text containing &quot;declare X ... end&quot; and pass this to the builder and add the resulting package to your Knowledge Base.<br>
<br>And then?<br><br>You&#39;ll need some code to get objects of type X into Working Memory, which you can do using the reflection-like methods of FactType and FactField, but this code still has to know about &quot;X&quot; and its field names.<br>
<br>OK, so you have some Xs in WM. And now?<br><br>You&#39;ll have to write some rules referring to X and its fields, and how can you do that? More DRL text?<br><br>True, rule patterns can use interface names as type names, but the DRL language doesn&#39;t let you declare a type with an &quot;implements&quot; clause, and therefore the Engine simply wouldn&#39;t know that your X implements anything.<br>
<br>Finally, a poster on this list has stated just a few days ago that declared types are considerably slower than Java types. This hasn&#39;t been confirmed or explained by one of the developers (although the additional layers mentioned previously are certainly not speeding things up).<br>
<br>I don&#39;t know enough about your problem to suggest anything. It could be that sticking with the Object/JavaBeans model and generating and compiling Java and DRL is best. Or it could be that an entirely different ontology model is advisable (even though the Drools fact model is clearly JavaBean-ish). Or maybe you shouldn&#39;t use rules at all ;-)<br>
<br>-W<br><br><br><div class="gmail_quote">On 9 February 2011 23:02, jwillans2 <span dir="ltr">&lt;<a href="mailto:james.willans@ceteva.com">james.willans@ceteva.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Hello,<br>
<br>
I am looking for an approach to defining fact types<br>
dynamically/programmatically.  Having hunted about, I can see a few ways of<br>
achieving this.  My preferred approach to doing this would be Fact Templates<br>
as described in the blog article here:<br>
<br>
<a href="http://orangemile.blogspot.com/2008/07/drools-fact-template-example.html" target="_blank">http://orangemile.blogspot.com/2008/07/drools-fact-template-example.html</a><br>
<br>
I can see two problems with this approaches.  Firstly, it seems to be an<br>
experimental feature and generally not supported.  Secondly, it only seems<br>
to work with primitive fields (perhaps I&#39;m wrong here?).  I get the<br>
impression that the preferred option is to use Type Declarations.  In the<br>
documentation for Type Declarations, it suggests that the rules evaluate<br>
against an interface rather than an actual Java object and that the<br>
interface can be implemented using different methods (POJO, reflection ..).<br>
Is there any examples or documentation on how to do this beyond generated<br>
Java bean class? Just to be clear, I am looking to define the fact types<br>
programmatic in a similar manner to that described in the above blog link,<br>
and I am eager to avoid a compilation/class loader step.<br>
<br>
Many thanks for any help that can be offered,<br>
<br>
James<br>
<font color="#888888">--<br>
View this message in context: <a href="http://drools-java-rules-engine.46999.n3.nabble.com/Dynamic-Fact-Types-tp2462037p2462037.html" target="_blank">http://drools-java-rules-engine.46999.n3.nabble.com/Dynamic-Fact-Types-tp2462037p2462037.html</a><br>

Sent from the Drools - User mailing list archive at Nabble.com.<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>
</font></blockquote></div><br>