[rules-users] ClassCastException using memberOf operator

Wolfgang Laun wolfgang.laun at gmail.com
Thu Jan 24 14:25:49 EST 2013


Sorry for the (obvious) omission, that rule should be:
   Cont( name == "A", $coll: objects )
   i: Item ( f memberOf $coll )


On 24/01/2013, Wolfgang Laun <wolfgang.laun at gmail.com> wrote:
> A better approach for your use case would be to use additional facts:
>
> declare Cont
>   name: String
>   objects: Collection
> end
>
> rule "define Cont(s)"
> salience 999999999
> when
> then
>     insert( new Cont( "A", setOf(1, 2, 3) ) );
> end
>
> Cont( name == "A", $coll )
> i: Item ( f memberOf $coll )
>
> -W
>
>
> On 24/01/2013, Marco Malziotti <marco.malziotti at trs.it> wrote:
>> Thanks Wolfgang
>> In addition to using 'memberOf' operator, there is a way to retain in
>> RHS result from makeA(), without calling one more time makeA() function
>> ?
>> In consequence (then) of my example I want print 'a' that already holds
>> (?) the function result.
>> Once again thanks.
>>
>> Marco
>>
>> On Wed, 23 Jan 2013 17:49:04 +0100, Wolfgang Laun wrote:
>>> The simple
>>>   i: Item ( f memberOf (makeA()) )
>>> should do.
>>> -W
>>>
>>> On 23/01/2013, Marco Malziotti <marco.malziotti at trs.it> wrote:
>>>> Hello
>>>> I am a beginner in Drools 5.1.1 and try to use 'memberOf' operator.
>>>> Simply I want check whether a short field 'f' (belonging to Item
>>>> class)
>>>> is a member of an array 'a': retrieved by a function 'makeA'.
>>>> In my .drl file I try with :
>>>>
>>>> function Short[] makeA() {
>>>>    return  (new Short[] {1, 2, 3} );
>>>> }
>>>>
>>>> rule "chek"
>>>> when
>>>>    a: Short[]() from makeA()
>>>>    i: Item ( f memberOf a )
>>>> then
>>>> ... 'f' is member of array 'a' !
>>>> end
>>>>
>>>> I have following stack trace:
>>>> java.lang.ClassCastException: Can't check if an attribute is member
>>>> of
>>>> an object of class class java.lang.Short
>>>> at
>>>>
>>>> org.drools.base.evaluators.SetEvaluatorsDefinition$BaseMemberOfEvaluator.evaluateCachedRight(SetEvaluatorsDefinition.java:532)
>>>> at
>>>>
>>>> org.drools.rule.VariableRestriction.isAllowedCachedRight(VariableRestriction.java:117)
>>>> at
>>>>
>>>> org.drools.rule.VariableConstraint.isAllowedCachedRight(VariableConstraint.java:121)
>>>> at
>>>>
>>>> org.drools.common.SingleBetaConstraints.isAllowedCachedRight(SingleBetaConstraints.java:151)
>>>> at org.drools.reteoo.JoinNode.assertObject(JoinNode.java:125)
>>>> at
>>>>
>>>> org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:59)
>>>> at
>>>>
>>>> org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:190)
>>>> at
>>>>
>>>> org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:145)
>>>> at
>>>>
>>>> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1174)
>>>> at
>>>>
>>>> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1123)
>>>> at
>>>>
>>>> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:917)
>>>> at
>>>>
>>>> org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:251)
>>>>
>>>> In :
>>>>
>>>> http://lists.jboss.org/pipermail/rules-users/2008-October/006746.html
>>>> and
>>>>
>>>> http://lists.jboss.org/pipermail/rules-users/2007-September/003010.html
>>>> I haven't found the solution to my problem.
>>>>
>>>> I don't know if it is already open a related issue.
>>>>
>>>> Thanks for your attention.
>>>> Regards.
>>>>
>>>> Marco Malziotti
>>>> Tecnologie nelle Reti e nei Sistemi T.R.S. S.p.A.
>>>> Integration Test Engineer
>>>> Tel.  + 39 06.87281.407
>>>> Fax.  + 39 06.87281.550
>>>> E-mail: marco.malziotti at trs.it
>>>>
>>>>
>>>> Tecnologie nelle Reti e nei Sistemi T.R.S. SpA
>>>> Via della Bufalotta, 378 - 00139 Roma
>>>> Tel +39.06.87.28.1.1 - Fax +39.06.87.28.1.550
>>>>
>>>> -------------------------------------------------------
>>>>
>>>> Ai sensi del D.Lgs. 196/2003 si precisa che le informazioni
>>>> contenute in
>>>> questo messaggio
>>>> sono riservate ed a uso esclusivo del destinatario. Qualora il
>>>> messaggio in
>>>> parola Le
>>>> fosse pervenuto per errore, la preghiamo di eliminarlo senza
>>>> copiarlo e di
>>>> non inoltrarlo
>>>> a terzi, dandocene gentilmente comunicazione. Grazie.
>>>> This message, for the law 196/2003, may contain confidential and/or
>>>> privileged information.
>>>> If you are not the addressee or authorized to receive this for the
>>>> addressee, you must not
>>>> use, copy, disclose or take any action based on this message or any
>>>> information herein.
>>>> If you have received this message in error, please advise the sender
>>>> immediately by reply
>>>> e-mail and delete this message. Thank you for your cooperation.
>>>>
>>>> -------------------------------------------------------
>>>>
>>>> This message has been scanned for viruses and dangerous content by
>>>> MailScanner, and is believed to be clean.
>>>>
>>>>
>>>> _______________________________________________
>>>> rules-users mailing list
>>>> 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
>>
>>
>> Tecnologie nelle Reti e nei Sistemi T.R.S. SpA
>> Via della Bufalotta, 378 - 00139 Roma
>> Tel +39.06.87.28.1.1 - Fax +39.06.87.28.1.550
>>
>> -------------------------------------------------------
>>
>> Ai sensi del D.Lgs. 196/2003 si precisa che le informazioni contenute in
>> questo messaggio
>> sono riservate ed a uso esclusivo del destinatario. Qualora il messaggio
>> in
>> parola Le
>> fosse pervenuto per errore, la preghiamo di eliminarlo senza copiarlo e
>> di
>> non inoltrarlo
>> a terzi, dandocene gentilmente comunicazione. Grazie.
>> This message, for the law 196/2003, may contain confidential and/or
>> privileged information.
>> If you are not the addressee or authorized to receive this for the
>> addressee, you must not
>> use, copy, disclose or take any action based on this message or any
>> information herein.
>> If you have received this message in error, please advise the sender
>> immediately by reply
>> e-mail and delete this message. Thank you for your cooperation.
>>
>> -------------------------------------------------------
>>
>> This message has been scanned for viruses and dangerous content by
>> MailScanner, and is believed to be clean.
>>
>>
>> _______________________________________________
>> 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