JESS: [EXTERNAL] Code to convert a POJO to a template assertion?

"Grant Rettke" <[email protected]> Thu, 15 Nov 2012 15:47:45 -0600
Newsgroups gmane.comp.java.jess
Message-ID <CAAjq1mdYWrsT15KKFmwpcxy0uyaYGJc1qH2FyR9O4d9UcuQqbg@mail.gmail.com>
--047d7b33d942f2b37f04ce8f99eb
Content-Type: text/plain;
 charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi,

For whatever reason I don't want to use defclass and instead want to be
able to convert a POJO to a template assertion. There are helpers to write
converters like this but I'm wondering if someone has done it? Maybe it
could even define the deftemplate given the class.

It would be like:

class Person {
String name;
int age;
public void getName() { return name; }
public void getAge() {return age; }

The functions might do this:

pojoToTemplate(Object o) -> string

pojoToAssertion(Object o) -> string

Person p =3D new Person("Joe", 10);

pojoToTemplate(p) -> "(deftemplate (slot name) (slot age))

pojoToAssertion(p) -> "(assert (Person (name "Joe") (age 10))

Ok the reason is that I don't want or plan to deal with modifying any state
outside of the engine environment :).

Best wishes,

--=20
Grant Rettke | ACM, AMA, COG, IEEE
[email protected] | http://www.wisdomandwonder.com/
Wisdom begins in wonder.
((=CE=BB (x) (x x)) (=CE=BB (x) (x x)))

--047d7b33d942f2b37f04ce8f99eb
Content-Type: text/html;
 charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi,<div><br></div><div>For whatever reason I don&#39;t want to use defclass=
 and instead want to be able to convert a POJO to a template assertion. The=
re are helpers to write converters like this but I&#39;m wondering if someo=
ne has done it? Maybe it could even define the deftemplate given the class.=
</div>
<div><br></div><div>It would be like:</div><div><br></div><div>class Person=
 {</div><div>String name;</div><div>int age;</div><div>public void getName(=
) { return name; }</div><div>public void getAge() {return age; }<br clear=
=3D"all">
<div><br></div><div>The functions might do this:</div><div><br></div><div>p=
ojoToTemplate(Object o) -&gt; string</div><div><br></div><div>pojoToAsserti=
on(Object o) -&gt; string</div><div><br></div><div>Person p =3D new Person(=
&quot;Joe&quot;, 10);</div>
<div><br></div><div>pojoToTemplate(p) -&gt; &quot;(deftemplate (slot name) =
(slot age))</div><div><br></div><div>pojoToAssertion(p) -&gt; &quot;(assert=
 (Person (name &quot;Joe&quot;) (age 10))</div><div><br></div><div>Ok the r=
eason is that I don&#39;t want or plan to deal with modifying any state out=
side of the engine environment :).</div>
<div><br></div><div>Best wishes,</div><div><br></div>-- <br>Grant Rettke | =
ACM, AMA, COG, IEEE<br><a href=3D"mailto:[email protected]" target=3D"_blank"=
>[email protected]</a> | <a href=3D"http://www.wisdomandwonder.com/" target=
=3D"_blank">http://www.wisdomandwonder.com/</a><br>
Wisdom begins in wonder.<br>((=CE=BB (x) (x x)) (=CE=BB (x) (x x)))<br>
</div>

--047d7b33d942f2b37f04ce8f99eb--