[rules-users] Property Navigation

Michael B. michael.bain at mckesson.com
Wed May 7 10:34:46 EDT 2008




Alessandro Lazarotti wrote:
> 
> 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
> 
> 
> Glad it is working for you now, looks like I have to be more patient when
> posting to this board as I seem to have junked the thread up a bit lol 
> 
> 
> 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
> 
> 


-----
Drools Noob since 5/2008
-- 
View this message in context: http://www.nabble.com/Property-Navigation-tp17089209p17106182.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list