Look at this unit test for some examples:
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java

        // Retrieve the generated fact type
        FactType cheeseFact = ruleBase.getFactType( "org.drools.generatedbeans.Cheese" );

        // Create a new Fact instance
        Object cheese = cheeseFact.newInstance();

        // Set a field value using the more verbose method chain...
        // should we add short cuts?
        //        cheeseFact.getField( "type" ).getFieldAccessor().setValue( cheese,
        //                                                             "stilton" );

        cheeseFact.set( cheese,
                        "type",
                        "stilton" );
        assertEquals( "stilton",
                      cheeseFact.get( cheese,
                                      "type" ) );


On Tue, Jan 27, 2009 at 2:02 AM, Oleg Zenzin <zenzin@intalio.com> wrote:

There's now possibility to declare facts in the drl, like:

declare Person
 name: String
 age: int
end

My question is how do I instantiate this fact object during runtime? Do I still need to have class Person compiled and existing somewhere in classpath, or there's a helper class which I can use "fake the fact", something like:

  FakeFact person = FakeFact("Person");
  person.setField("name", "Oleg");
  person.setField("age", "42");
  session.insert(person);

Or there's another nicer way?

Thank you,
-Oleg Zenzin


_______________________________________________
rules-dev mailing list
rules-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev