I'm exploring the possibility of using a dynamic bean as fact object as my fact object is very dynamic in nature.
<div>I came across posts where people had recommended using BeanGenerator from CGLIB.</div><div><br></div><div>This blog does a very good job of explaining the details of classloader etc.</div><div><br></div><div><a href="http://blog.athico.com/2006/12/dynamically-generated-class-beans-as.html">http://blog.athico.com/2006/12/dynamically-generated-class-beans-as.html</a></div>
<div><br></div><div>From what I can gather ( I'm new to both CGLIB and drools ) CGLIB seems to have the lowest lerning curve to achieve this.</div><div><br></div><div>I have the below sample on creating a dynamic bean with CGLIB</div>
<div><br></div><div><div>BeanGenerator bg = new BeanGenerator();</div><div> bg.setSuperclass(FactContextPlaceHolder.class);</div><div> bg.setNamingPolicy(new net.sf.cglib.core.NamingPolicy() {</div><div> public String getClassName(String prefix, String source, Object key, Predicate names) {</div>
<div> return prefix + "Impl";</div><div> }</div><div> });</div><div><br></div><div><br></div><div><div> bg.addProperty("foo", Double.TYPE);</div><div> g.addProperty("bar", String.class);</div>
<div> FactContextPlaceHolder beanInst = (FactContextPlaceHolder)bg.create();</div></div></div><div><br></div><div><br></div><div>Here com.drools.test.FactContextPlaceHolder is set as super class and the generated class is obtained as com.drools.test.FactContextPlaceHolderImpl</div>
<div><br></div><div>I have two basic question I am unable to find some answers on.</div><div><br></div><div>1) Once I create an object, how do I actually set the state of this object with fact values before setting it as fact object to drools session?</div>
<div>In the above example how do I set value of foo to "foot-test1" and value of bar to "bar-test1" on the beanInst.</div><div><br></div><div>2) In DRL if I set the package to some path say com.drools.test</div>
<div> Should I then use FactContextPlaceHolderImpl as my fact Object?</div><div><br></div><div><br></div><div>Thanks</div><div>Kumar </div><div><br></div>