[rules-users] Drools get value from stateful session

Wolfgang Laun wolfgang.laun at gmail.com
Sun Nov 10 02:27:18 EST 2013


Digging a bit into Java's API always helps ;-) Note that
Class.getSimpleName() really does what it says, as opposed to
Class.getName().

It would be best to avoid the String representation:

Collection findFacts( StatefulKnowledgeSession session, Class factClass ){...
public boolean accept( Object object ){
   return object.getClass().( factClass );
}...}

-W

On 10/11/2013, forsakendoll <forsakendoll at hotmail.com> wrote:
> How can I get the value from a stateful session. As they say I can use
> this:
>
> protected Collection findFacts( final StatefulKnowledgeSession session,
> final String factClass )
> {
>         ObjectFilter filter = new ObjectFilter()
>         {
>             @Override
>             public boolean accept( Object object )
>             {
>                 return object.getClass().getSimpleName().equals( factClass
> );
>             }
>         };
>
>         Collection results = session.getObjects( filter );
>
>         return results;
> }
>
> to get the value from the rules. Given the fact the code already red the
> rules when I  tried this:
>
> StatefulKnowledgeSession ksession =
> aKnowledgeBase.newStatefulKnowledgeSession();
>
> ksession.insert( aBean );
> ksession.fireAllRules();
>
> Collection result = findFacts( ksession,
> "com.neu.als.thesis.db.beans.StudentBean" );
>
> ksession.dispose();
> for( Object test : result )
> {
>       System.out.println( test == null );
>       System.out.println( test );
> }
>
> Nothing is printed. What is the proper way to get bean that I inserted in
> the rules?
>
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Drools-get-value-from-stateful-session-tp4026712.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>


More information about the rules-users mailing list