<div dir="ltr"><br> Stephen,<br><br> Really glad to see you picking up this stuff. <br><br> Let me clarify something: "templates" were an experimental feature in Drools 4.0, and so far, will continue to be experimental in Drools 5.0 as we lack the manpower to move it ahead ourselves. If you are willing to move this ahead, we can provide all assistance/guidance you may need.<br>
<br> Having said that, lets split the template construct into concept and syntax. The syntax is being completely removed in Drools 5 and replaced by the TypeDeclaration syntax. The type declaration concept is more abstract than template (or should I say a super set?). Type declaration in drools 5 has 2 purposes: 1st it is a way to assign metadata to types, 2nd it is a way to declare/generate underlying structures for facts.<br>
<br> So talking about the first usage, as it is today, you can have an existing fact type (e.g. a class named StockTick) and assign metadata for it. For instance, saying it should be given "event semantics" in the system:<br>
<br>declare StockTick<br> @role( event ) <br>end<br><br> Talking about the second usage, the idea is that you can declare types that may have any underlying implementation would best fit you. So far, the underlying implementation that we have working and tested is POJO generation. <br>
<br>declare Address<br> line1 : String<br> line2 : String<br>end<br><br>declare Person<br> name : String<br> age : int<br> address : Address<br>end<br><br> Now, it is planned, though not implemented/wired/tested yet, that when you declare a type, you may inform the engine what is its underlying format and the engine will know how to handle it:<br>
<br>declare Address<br> @format( template ) <br>
line1 : String<br>
line2 : String<br>
end<br>
<br> Idea is that you could have any arbitrary underlying format for facts, like XML, JMS Messages, Database Records, CSV records, etc. <br><br> Anyway, that is the vision. If you look at the PackageBuilder.java, line 602, processTypeDeclaration() method, that is where the compilation/wiring process starts. We probably need to extract that method and create a separate API for it. The code there is not tested except for POJOs. If you look at the line 631, it has an "if" from the first idea we had, where you would use "template" construct to create a template and then a "declare" construct to assign metadata to it. We dropped this idea, since a unified approach is better, but that code is still there:<br>
<br> // is it a POJO or a template?<br> String templateName = typeDescr.getMetaAttribute( TypeDeclaration.ATTR_TEMPLATE );<br><br>
Also, just for the sake of completeness, the final vision is to allow both initialization expressions and attribute validation in the type declaration. For instance:<br><br>declare Person<br>
name : String( length < 30 ) @key<br> age : int( value >= 0 && < 150 ) = 0<br>
addresses : Map<String, Address> = {"home" : null, "business" : null}<br>
end<br><br> There are a few more bits like automatic creation of facts, but that is subject for another time.<br><br> There is a lot to do, but it can be easily split into an incremental approach. If you want to contribute working on this, it will be a pleasure to support you.<br>
<br> Cheers,<br> Edson<br>
<br> <br><br><br><div class="gmail_quote">2008/8/27 Stephen Kestle <span dir="ltr"><<a href="mailto:stephen.kestle@orionhealth.com">stephen.kestle@orionhealth.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div bgcolor="#ffffff" text="#000000">
I believe I have it... "declare" is meant to be used for easy
generation of java classes, so that rules can instantiate objects and
use them as such. For dynamic data models, "template" is a better fit,
as getField etc are geared towards map-like data structures.<br>
<br>
I believe that I could have :<br>
<br>
template "Address"<br>
String line1<br>
String line2<br>
end<br>
<br>
template "Person"<br>
String name<br>
int age<br>
Object address<br>
end<br>
<br>
rule "Test"<br>
when<br>
add: Address(line1 == "address")<br>
person: Person(address == add)<br>
then <br>
...<br>
<br>
Is this correct?<br>
<br>
Cheers <br>
<br>
Stephen Kestle wrote:
<blockquote type="cite"><div><div></div><div class="Wj3C7c">I'm
creating a type hierarchy using TypeDeclarations based on an
ontological model (analagous to an xml schema for the purposes of this
post).
<br>
<br>
If I declare a drl file to have the following declarations
<br>
<br>
declare Address
<br>
line1 : String
<br>
line2 : String
<br>
end
<br>
<br>
declare Person
<br>
name : String
<br>
age : int
<br>
address : Address
<br>
end
<br>
<br>
it will create Java Pojo classes for me. However, I had it all working
using fact templates, except for the address item. Is it possible to
insert fact implementations based on templates, while declaring
TypeDeclarations in the drl? (I now go to look for how to specify the
format = TEMPLATE for the drl)
<br>
<br>
I say this because I'm looking up values using id strings - e.g. the
exact same way that FactTemplate based Facts does accessing. I don't
want to have to convert all my String ids to reflectively call the set
methods on the created Pojo.
<br>
<br>
Hopefully this is enough info for you 5.0 developers - I'm still trying
to wrap my head around it all.
<br>
<br>
Cheers
<br>
<br>
Stephen
<br>
_______________________________________________
<br>
rules-users mailing list
<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
<br></div></div>
______________________________________________________________________
<br>
This email has been scanned by the MessageLabs Email Security System.
<br>
For more information please visit <a href="http://www.messagelabs.com/email" target="_blank">http://www.messagelabs.com/email</a>
______________________________________________________________________
<br>
</blockquote>
<br>
<div>-- <br>
<hr color="#007186" noshade>
<table align="center" border="0" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<td>
<div align="right"><font color="#007186" size="2" face="Verdana, Arial, Helvetica, sans-serif"><b><a href="http://www.orionhealth.com" target="_blank"><img border="0" width="150" height="50"></a></b></font></div>
</td>
<td bgcolor="#ef7224" width="1"><br>
</td>
<td>
<p><font face="Verdana, Arial, Helvetica, sans-serif"><b><font color="#ef7224" size="2">Stephen Kestle</font> <font color="#007186" size="2">Software Engineer</font></b><font color="#007186" size="2"><br>
<a href="mailto:stephen.kestle@orionhealth.com" target="_blank">stephen.kestle@orionhealth.com</a><br>
P: +64 9 638 0619<br>
M: +64 27 453 7853 <br>
F: +64 9 638 0699<br>
S: <a href="callto:skestle" target="_blank">skestle</a><br>
<a href="http://www.orionhealth.com" target="_blank">www.orionhealth.com</a></font>
</font></p>
</td>
</tr>
</tbody>
</table>
<br>
<div align="center"><font color="#cccccc" size="1" face="Verdana, Arial, Helvetica, sans-serif">This e-mail and
any attachments are intended only for the person to whom it is
addressed and may contain privileged, proprietary, or other data
protected from disclosure under applicable law. If you are not the
addressee or the person responsible for delivering this to the
addressee you are hereby notified that reading, copying or distributing
this transmission is prohibited. If you have received this e-mail in
error, please telephone us immediately and remove all copies of it from
your system. Thank you for your co-operation.</font></div>
</div>
</div>
<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>
<br></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>
</div>