[rules-users] Setting strictTyping/strongTyping modes

Wolfgang Laun wolfgang.laun at gmail.com
Thu Mar 22 03:26:04 EDT 2012


The error is raised at a RHS statment not at all connected with any
fact type. foo is a function returning an Integer. Setting it in the
rule doesn't help.

then
    System.out.println( "Howdy!" + foo( "one" ).toString() );
end

But I suspect that this is due to a bug, because it happens when the
function in question is compiled with dialect "mvel" preceding it at
package level.
(See https://issues.jboss.org/browse/JBRULES-3433.) Here is trying to use it:

dialect "mvel"
function Integer foo(String s){
       return Integer.valueOf( 1 );
}
rule howdy
@typesafe(true)
when
then
    System.out.println( "Howdy!" + foo("one").toString() );
end

Below is the error. Note the funny package name for function foo!

Unable to Analyse Expression System.out.println( "Howdy!" +
foo("one").toString() );:
[Error: unable to resolve method using strict-mode:
org.drools.spi.KnowledgeHelper.foo(java.lang.String)]
[Near : {... System.out.println( "Howdy!" + foo("one").toString() ); ....}]
                                            ^
[Line: 19, Column: 0] : [Rule name='howdy']

-W



On 21/03/2012, Mark Proctor <mproctor at codehaus.org> wrote:
> On 21/03/2012 20:19, Wolfgang Laun wrote:
>> Yeah, but where would I put this @tpyesafe(true) thing, exactly? It
>> seems that this is available with DRL declares only. So, what do I do
>> with my pojo bean class?
>> -W
> declare also works to declare annotations for existings beans on your
> own classpath - as long you don't define any properties.
>
> Mark
>>
>>
>>
>> 2012/3/21 Mark Proctor <mproctor at codehaus.org
>> <mailto:mproctor at codehaus.org>>
>>
>>     On 21/03/2012 18:45, barnesjd wrote:
>>>     I'm trying to disable strictTyping for my MVEL rules, but I cannot
>>> figure out
>>>     how.http://mvel.codehaus.org/MVEL+2.0+Typing  The only example I've
>>> found
>>>     shows the use of the class ParserContext.  I'm using
>>> KnowledgeBuilder,
>>>     KnowledgeBase, StatefulKnowledgeSession, etc. to run my rules.  I
>>> don't see
>>>     any methods where I can disable strictTyping or get the
>>> ParserContext, so
>>>     I'm out of ideas.
>>>
>>>     Can anyone point me in the right direction?
>>
>> http://docs.jboss.org/drools/release/5.4.0.Beta2/knowledge-api-javadoc/org/drools/KnowledgeBaseConfiguration.html
>>     And MVEL supports the following configurations:
>>
>>       * drools.dialect.mvel.strict = <true|false>
>>
>>
>>     However we would recommend instead that you don't use that
>>     configuration and instead use the @typesafe annotation on class
>>     declarations. So you relax just specific classes, rather than
>>     relaxing everything.
>>
>> http://docs.jboss.org/drools/release/5.4.0.Beta2/drools-expert-docs/html_single/index.html
>>
>>
>>               5.7.2.1.2. @typesafe( <boolean> )
>>
>>     By default all type declarations are compiled with type safety
>>     enabled; @typesafe( false ) provides a means to override this
>>     behaviour by permitting a fall-back, to type unsafe evaluation
>>     where all constraints are generated as MVEL constraints and
>>     executed dynamically. This can be important when dealing with
>>     collections that do not have any generics or mixed type collections.
>>
>>
>>
>>>     Thanks!
>>>     Joe
>>>
>>>
>>>     --
>>>     View this message in
>>> context:http://drools.46999.n3.nabble.com/Setting-strictTyping-strongTyping-modes-tp3846477p3846477.html
>>>     Sent from the Drools: User forum mailing list archive at Nabble.com.
>>>     _______________________________________________
>>>     rules-users mailing list
>>>     rules-users at lists.jboss.org  <mailto:rules-users at lists.jboss.org>
>>>     https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>>     _______________________________________________
>>     rules-users mailing list
>>     rules-users at lists.jboss.org <mailto:rules-users at lists.jboss.org>
>>     https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>>
>>
>> _______________________________________________
>> 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