List Info

Thread: Property Navigation




Property Navigation
country flaguser name
United States
2008-05-06 13:05:00
If  I've the simple classes:

public class ObjectBar{ public String name; gets/sets}

public class ObjectFoo{ public ObjectBar bar; gets/sets }

... and ObjectFoo this in WorkingMemory.

It's not possible navigate in objectFoo for make constraint
in objectBar?
Example:

rule "Teste"
no-loop true
    when
        $foo: ObjectFoo(objectBar.name !=
"foobar")
    then
        System.out.println($foo);
end   

... but:
org.drools.RuntimeDroolsException: Exception executing
predicate 
org.drools.base.mvel.MVELPredicateExpression18488ef
Caused by: org.mvel.CompileException: unable to resolve
property: nome
Caused by: org.mvel.PropertyAccessException: unable to
resolve property: 
nome

Thanks
Alessandro Lazarotti




_______________________________________________
rules-users mailing list
rules-userslists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users

Re: Property Navigation
country flaguser name
United States
2008-05-06 15:56:20
According to your error it appears you had a typo somewhere.
 The error you
pasted in was looking for the property nome instead of
name.



Alessandro Lazarotti wrote:
> 
> If  I've the simple classes:
> 
> public class ObjectBar{ public String name; gets/sets}
> 
> public class ObjectFoo{ public ObjectBar bar; gets/sets
}
> 
> ... and ObjectFoo this in WorkingMemory.
> 
> It's not possible navigate in objectFoo for make
constraint in objectBar?
> Example:
> 
> rule "Teste"
> no-loop true
>     when
>         $foo: ObjectFoo(objectBar.name !=
"foobar")
>     then
>         System.out.println($foo);
> end   
> 
> ... but:
> org.drools.RuntimeDroolsException: Exception executing
predicate 
> org.drools.base.mvel.MVELPredicateExpression18488ef
> Caused by: org.mvel.CompileException: unable to resolve
property: nome
> Caused by: org.mvel.PropertyAccessException: unable to
resolve property: 
> nome
> 
> Thanks
> Alessandro Lazarotti
> 
> 
> 
> 
> _______________________________________________
> rules-users mailing list
> rules-userslists.jboss.org
> 
https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 

-- 
View this message in context: http://www.nabble.com/Property-Navigation-tp17
089209p17092230.html
Sent from the drools - user mailing list archive at
Nabble.com.

_______________________________________________
rules-users mailing list
rules-userslists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users

Re: Property Navigation
country flaguser name
United States
2008-05-06 16:22:45
Hi, Michael...
The code that I wrote has a property "name" and not "nome". Sorry, the example not is the same that the Exception.
But ocurr the same error.

org.drools.RuntimeDroolsException: Exception executing predicate 
org.drools.base.mvel.MVELPredicateExpression18488ef
Caused by: org.mvel.CompileException: unable to resolve property: name
Caused by: org.mvel.PropertyAccessException: unable to resolve property:name




Michael B. escreveu:
talk.nabble.com" type="cite">
According to your error it appears you had a typo somewhere.  The error you
pasted in was looking for the property nome instead of name.




Alessandro Lazarotti wrote:
  
If  I've the simple classes:

public class ObjectBar{ public String name; gets/sets}

public class ObjectFoo{ public ObjectBar bar; gets/sets }

... and ObjectFoo this in WorkingMemory.

It's not possible navigate in objectFoo for make constraint in objectBar?
Example:


rule "Teste"
no-loop true
    when
        $foo: ObjectFoo(objectBar.name != "foobar")

    then
        System.out.println($foo);
end   

... but:
org.drools.RuntimeDroolsException: Exception executing predicate 
org.drools.base.mvel.MVELPredicateExpression18488ef
Caused by: org.mvel.CompileException: unable to resolve property: nome
Caused by: org.mvel.PropertyAccessException: unable to resolve property: 
nome

Thanks
Alessandro Lazarotti





_______________________________________________
rules-users mailing list
lists.jboss.org">rules-userslists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



    

  
Re: Property Navigation
country flaguser name
United States
2008-05-06 17:24:10
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());
        }

    }




-- 
View this message in context: http://www.nabble.com/Property-Navigation-tp17
089209p17093620.html
Sent from the drools - user mailing list archive at
Nabble.com.

_______________________________________________
rules-users mailing list
rules-userslists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users

Re: Property Navigation
country flaguser name
United States
2008-05-06 18:09:04
Alessandro:

I wrote a test case and some classes around your example and
mailed them to
you, I was not able to get them to post on this list for
some reason.

Thanks...Michael

Alessandro Lazarotti wrote:
> 
> 
> 
> 
>   
> 
> 
> Hi, Michael... 
> The code that I wrote has a property "name"
and not "nome". Sorry, the
> example not is the same that the Exception. 
> But ocurr the same error. 
> 
> org.drools.RuntimeDroolsException: Exception executing
predicate 
> org.drools.base.mvel.MVELPredicateExpression18488ef
> Caused by: org.mvel.CompileException: unable to resolve
property: name
> Caused by: org.mvel.PropertyAccessException: unable to
resolve
> property:name 
> 
> 
> 
> 
> Michael B. escreveu:
> 
>   According to your error it appears you had a typo
somewhere.  The error
> you
> pasted in was looking for the property nome instead of
name.
> 
> 
> 
> Alessandro Lazarotti wrote:
>   
>   
>     If  I've the simple classes:
> 
> public class ObjectBar{ public String name; gets/sets}
> 
> public class ObjectFoo{ public ObjectBar bar; gets/sets
}
> 
> ... and ObjectFoo this in WorkingMemory.
> 
> It's not possible navigate in objectFoo for make
constraint in objectBar?
> Example:
> 
> rule "Teste"
> no-loop true
>     when
>         $foo: ObjectFoo(objectBar.name !=
"foobar")
>     then
>         System.out.println($foo);
> end   
> 
> ... but:
> org.drools.RuntimeDroolsException: Exception executing
predicate 
> org.drools.base.mvel.MVELPredicateExpression18488ef
> Caused by: org.mvel.CompileException: unable to resolve
property: nome
> Caused by: org.mvel.PropertyAccessException: unable to
resolve property: 
> nome
> 
> Thanks
> Alessandro Lazarotti
> 
> 
> 
> 
> _______________________________________________
> rules-users mailing list
> rules-userslists.jboss.org 
> 
https://lists.jboss.org/mailman/listinfo/rules-users 
> 
> 
>     
>   
>   
>   
> 
> 
> 
> 
> _______________________________________________
> rules-users mailing list
> rules-userslists.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-tp17
089209p17093653.html
Sent from the drools - user mailing list archive at
Nabble.com.

_______________________________________________
rules-users mailing list
rules-userslists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users

Re: Property Navigation
country flaguser name
United States
2008-05-06 19:04:13
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-userslists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users

Re: Property Navigation
country flaguser name
United States
2008-05-07 09:34:46


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-userslists.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-tp17
089209p17106182.html
Sent from the drools - user mailing list archive at
Nabble.com.

_______________________________________________
rules-users mailing list
rules-userslists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users

Re: Property Navigation
user name
2008-05-07 13:19:13

   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 < alessandrosiq.com.br">alessandrosiq.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&quot;.
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(&quot;Test&quot;);
           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-userslists.jboss.org" target="_blank">rules-userslists.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
Re: Property Navigation
country flaguser name
United States
2008-05-07 14:50:39
Verified this, in my example if I change the line to
Bar.setFoo(null) I get
the following error in my test case:

Exception executing predicate
org.drools.base.mvel.MVELPredicateExpression6bade9
org.drools.RuntimeDroolsException: Exception executing
predicate
org.drools.base.mvel.MVELPredicateExpression6bade9
	at
org.drools.rule.PredicateConstraint.isAllowed(PredicateConst
raint.java:216)
	at
org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:132)

	at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObj
ect(SingleObjectSinkAdapter.java:22)
	at
org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode
.java:153)
	at org.drools.reteoo.Rete.assertObject(Rete.java:175)
	at
org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase
.java:192)
	at
org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorking
Memory.java:71)
	at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorki
ngMemory.java:909)
	at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorki
ngMemory.java:881)
	at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorki
ngMemory.java:682)
	at
mmg.cm.drools.FooBarTest.testProperties(FooBarTest.java:51)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce
ssorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe
thodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at
junit.framework.TestResult$1.protect(TestResult.java:106)
	at
junit.framework.TestResult.runProtected(TestResult.java:124)

	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer
ence.run(JUnit3TestReference.java:128)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test
Execution.java:38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
sts(RemoteTestRunner.java:460)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
sts(RemoteTestRunner.java:673)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R
emoteTestRunner.java:386)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
RemoteTestRunner.java:196)
Caused by: org.mvel.CompileException: unable to resolve
property: name
	at
org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.co
mpileGetChain(ReflectiveAccessorOptimizer.java:288)
	at
org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.op
timizeAccessor(ReflectiveAccessorOptimizer.java:109)
	at
org.mvel.ast.VariableDeepPropertyNode.getReducedValueAcceler
ated(VariableDeepPropertyNode.java:29)
	at
org.mvel.ast.PropertyASTNode.initializePropertyNode(Property
ASTNode.java:77)
	at
org.mvel.ast.PropertyASTNode.getReducedValueAccelerated(Prop
ertyASTNode.java:26)
	at
org.mvel.ast.BinaryOperation.getReducedValueAccelerated(Bina
ryOperation.java:21)
	at org.mvel.MVELRuntime.execute(MVELRuntime.java:88)
	at
org.mvel.CompiledExpression.getValue(CompiledExpression.java
:111)
	at org.mvel.MVEL.executeExpression(MVEL.java:235)
	at
org.drools.base.mvel.MVELPredicateExpression.evaluate(MVELPr
edicateExpression.java:36)
	at
org.drools.rule.PredicateConstraint.isAllowed(PredicateConst
raint.java:210)
	... 28 more
Caused by: org.mvel.PropertyAccessException: unable to
resolve property:
name
	at
org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.ge
tBeanProperty(ReflectiveAccessorOptimizer.java:382)
	at
org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.co
mpileGetChain(ReflectiveAccessorOptimizer.java:257)
	... 38 more



Edson Tirelli-3 wrote:
> 
>    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 <alessandrosiq.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-userslists.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
> 
> _______________________________________________
> rules-users mailing list
> rules-userslists.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-tp17
089209p17113250.html
Sent from the drools - user mailing list archive at
Nabble.com.

_______________________________________________
rules-users mailing list
rules-userslists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users

Re: Property Navigation
country flaguser name
United States
2008-05-07 16:29:43
Yes, it's same. ; See also, the name of rule with error not appear...

Edson, I describe this in Jira too?



Michael B. escreveu:
talk.nabble.com" type="cite">
Verified this, in my example if I change the line to Bar.setFoo(null) I get
the following error in my test case:

Exception executing predicate

org.drools.base.mvel.MVELPredicateExpression6bade9
org.drools.RuntimeDroolsException: Exception executing predicate

org.drools.base.mvel.MVELPredicateExpression6bade9
	at
org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:216)
	at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:132)
	at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:22)

	at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:153)
	at org.drools.reteoo.Rete.assertObject(Rete.java:175)
	at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
	at

org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:71)

	at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:909)
	at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:881)
	at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:682)
	at mmg.cm.drools.FooBarTest.testProperties(FooBarTest.java:51)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)

	at junit.framework.TestSuite.run(TestSuite.java:203)
	at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
	at

org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.mvel.CompileException: unable to resolve property: name
	at

org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:288)
	at
org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:109)
	at
org.mvel.ast.VariableDeepPropertyNode.getReducedValueAccelerated(VariableDeepPropertyNode.java:29)
	at
org.mvel.ast.PropertyASTNode.initializePropertyNode(PropertyASTNode.java:77)
	at
org.mvel.ast.PropertyASTNode.getReducedValueAccelerated(PropertyASTNode.java:26)
	at
org.mvel.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:21)

	at org.mvel.MVELRuntime.execute(MVELRuntime.java:88)
	at org.mvel.CompiledExpression.getValue(CompiledExpression.java:111)
	at org.mvel.MVEL.executeExpression(MVEL.java:235)
	at
org.drools.base.mvel.MVELPredicateExpression.evaluate(MVELPredicateExpression.java:36)
	at
org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:210)
	... 28 more
Caused by: org.mvel.PropertyAccessException: unable to resolve property:

name
	at

org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.getBeanProperty(ReflectiveAccessorOptimizer.java:382)
	at
org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:257)

	... 38 more



Edson Tirelli-3 wrote:
  
   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 siq.com.br"><alessandrosiq.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
lists.jboss.org">rules-userslists.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

_______________________________________________
rules-users mailing list
lists.jboss.org">rules-userslists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



    


-----
Drools Noob since 5/2008
  
[1-10]

about | contact  Other archives ( Real Estate discussion Medical topics )