[rules-users] Property Navigation

Edson Tirelli tirelli at post.com
Wed May 7 14:19:13 EDT 2008


   Really? That is a surprise to me... we need to handle that...

   Maybe you can open a JIRA for us?

   Thanks,
      Edson

2008/5/6 Alessandro Lazarotti <alessandro at siq.com.br>:

> Thanks Michael, I simulate.. your rule fire with successful.
>
> I discovered the problem. The object in property (like Foo in your
> example), when null, it's not throws NullPointerException, but
> "org.mvel.PropertyAccessException: unable to resolve property".
> With that, I never imagined that the problem was nullPointer, but I
> thought about any access visibility (duh!).
>
> []'s
> Alessandro
>
>
>
> Michael B. escreveu:
>
>  Okay, I wrote a test case around the following and it works fine so let
> > me
> > know if this isnt what you are working with...
> >
> > Foo Class
> >
> > public class Foo {
> >        private String m_name;
> >        public String getName()
> >    {
> >        return m_name;            }
> >        public void setName(String nm)
> >    {
> >        m_name = nm;
> >    }
> >
> > }
> >
> >
> > Bar Class
> >
> > public class Bar {
> >        private Foo m_foo;
> >        public Foo getFoo()
> >    {
> >        return m_foo;
> >    }
> >        public void setFoo(Foo f)
> >    {
> >        m_foo = f;
> >    }
> >        public String toString()
> >    {
> >        return "I have a foo with a name of " + m_foo.getName();
> >    }
> >
> > }
> >
> > DRL Rule
> >
> > rule "FooBar Rule"
> >
> >        when
> >                $bar : Bar( foo.name != "Wrong" )
> >        then        System.out.println("Test Successful - " +
> > $bar.toString());
> >
> > end
> >
> >
> > Junit Test Case
> >
> >    public void testProperties()    {
> >        try
> >        {
> >            final Reader source = new InputStreamReader(
> > FooBarTest.class.getResourceAsStream( "FooBar.drl" ) );
> >            RuleBase ruleBase = RuleBaseFactory.newRuleBase();
> >            PackageBuilder builder = new PackageBuilder();
> >                        builder.addPackageFromDrl(source);
> >                        if ( builder.hasErrors() ) {
> >                System.out.println( builder.getErrors().toString() );
> >                throw new RuntimeException( "Unable to compile
> > \"FooBar.drl\".");
> >            }
> >                        //get the compiled package (which is
> > serializable)
> >            final Package pkg = builder.getPackage();
> >
> >            //add the package to a rulebase (deploy the rule package).
> >            ruleBase.addPackage( pkg );
> >            final StatefulSession session =
> > ruleBase.newStatefulSession();
> >                        Foo foo = new Foo();
> >            foo.setName("Test");
> >            Bar bar = new Bar();
> >            bar.setFoo(foo);
> >            session.insert(bar);
> >                        session.fireAllRules();
> >    }
> >        catch (Exception e)
> >        {
> >            System.out.println(e.getMessage());
> >            e.printStackTrace();
> >            fail(e.getMessage());
> >        }
> >
> >    }
> >
> >
> >
> >
> >
> >
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
Edson Tirelli
JBoss Drools Core Development
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20080507/64561335/attachment.html 


More information about the rules-users mailing list