[rules-users] How can i create a new object in consequence part

Michael Anstis michael.anstis at gmail.com
Tue Oct 19 03:07:02 EDT 2010


Don't forget when adding new objects; if you want them to be visible to the
rules you'll need to call "insert(XXX)" or "insertLogical(XXX)"

2010/10/19 Minh Huon <mhuon at dna20.com>

>  You have something similar to what you want.  If *resultState *is a
> global variable, there is nothing stopping you from writing any amount of
> java code you want in the consequence part.  Create whatever you want and
> then do *resultState.add(SOMEOBJECT);
>
> *You already perform a similar action with the code you have already:
>
> frontAxleAttributes.put("Capacity" ,new Double(c.attributes.Capacity));
>
> hth
> Minh
>
>
>
> On 10/18/2010 2:58 PM, Navdeep Kumar wrote:
>
> Hi..
>
>  After execution of each rule, i want to create a new object of a
> particular class and want to add that to the list. i know how to set the
> global list but i am not sure whether i can create a new instance in the
> consequence of the rule.
>
>
>  here is the rule file and description that what i am trying to do.
>
>  import java.util.Map;
> global java.util.HashMap availablity;
> global java.util.HashMap frontAxleAttributes;
> global java.util.HashMap frontSuspensionAttributes;
> global java.util.ArrayList resultState;
>
>
>
>
>  rule "FrontAxle:Capacity|FrontSuspension:Capacity"
> dialect "mvel"
>  when
>  b:Feature(featureClass.name=="FrontSuspension")
>  c:Feature(featureClass.name=="FrontAxle")
>  eval(b.attributes.Capacity>=c.attributes.Capacity)
>   then
>   System.out.println(b.attributes.Capacity);
>  frontAxleAttributes.put("Capacity" ,new Double(c.attributes.Capacity));
>  frontSuspensionAttributes.put("Capacity", new
> Double(b.attributes.Capacity));
>   frontAxleAttributes.put("Feature Code",b.getCode());
>  frontSuspensionAttributes.put("Feature Code",c.getCode());
>   availablity.put(b.featureClass.getName+"-"+c.getFeatureClass().getName(),new
> Double(b.attributes.Capacity));
>   * **// i want to create a new Object of a class named
> AvailabilityRuleState and want to add that in the list named resultState.
> *
> * *
>   end
>
>
>  *//resultState is a list of AvailabilityRuleState Class. Please do check
> the global declaration if that is wrong.*
>
>  will appreciate your help.
>
>  Thanks.
>
>
> _______________________________________________
> rules-users mailing listrules-users at lists.jboss.orghttps://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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20101019/5048854c/attachment.html 


More information about the rules-users mailing list