[rules-users] DRL authoring help

Smitha Bhat bhat_smitha at yahoo.com
Mon Jun 18 12:01:17 EDT 2007


Hi Krishnan,
  I need the class itself to be global as I might have to access other functions of it as I go along in the effort. 
  I cannot seem to be able to call the methods of this global class. I have also added a snippet of the code.
   
  Thanks
   Smitha
  Here is my drl
   
   
  drl=
  package test.tools.rulesengine
  import test.tools.rulesengine.Utilities;
  global test.tools.rulesengine.Utilities util;
  rule "Rule1"
  when
  $Position1 : PosReport()
  eval($Position1.getName() == "POS_0_1")
  then
  
  util.setColor($Position1, "red");
  end
   
   
   
  try {
     builder.addPackageFromDrl(new StringReader( drl) );
     
    
      if(firstCall){
        ruleBase = RuleBaseFactory.newRuleBase();
        ruleBase.addPackage( builder.getPackage() );
        workingMemory = ruleBase.newWorkingMemory();
        Utilities util = new Utilities();
        workingMemory.setGlobal("util", util);
               
        firstCall = false;
      }else
           ruleBase.addPackage( builder.getPackage() );
     //workingMemory = ruleBase.newWorkingMemory();
    } catch (DroolsParserException e1) {
     // TODO Auto-generated catch block
     e1.printStackTrace();
    } catch (IOException e1) {
     // TODO Auto-generated catch block
     e1.printStackTrace();
    } catch (Exception e1) {
     // TODO Auto-generated catch block
     e1.printStackTrace();
    }
  

Krishnan <krishiyer at gmail.com> wrote:
  
Hi Smitha, 

They way I understand, in the then clause you would like to call a static function from some class. So, then you can add that to the import and access it directly. It does not have to be global. However, if for some reason you do need to add it as a global,, let me know. 

send that when part of the rule again. 

-Krishnan. 

  On 6/18/07, Smitha Bhat <bhat_smitha at yahoo.com > wrote:    Hi Krishnan,
  I need the functionality of being able to call methods of a global class in the 'then' piece of the drl. I had defined the drl file as: 
   
  package test.tools.rulesengine
  import test.tools.rulesengine.Utilities;
  global test.tools.rulesengine.Utilities util;
   
  rule "Rule1"................. 
   
  When I debug the 'when' piece, I see that the method to check the name is being called, but tfter that, the global util's class method is not called. Any pointers would be helpful.
   
  Thanks,
  Smitha  

Krishnan < krishiyer at gmail.com> wrote:

    Hi Smitha, 

Rewrite the rule as follows :- 

  rule "Rule1"
  when
  $Position1 : Position ( name matches "POS-RPT_0_1" ) 
then 

  $Position.setColor("red");
  end

Note : You had something called util, unless it is a global, it will not work. 


-Krishnan. 

  On 6/18/07, Smitha Bhat < bhat_smitha at yahoo.com> wrote:     Hi,
  I am new to JBoss rules. I have a .drl as given below: 
   
  rule "Rule1"
  when 
  $Position1 : Position()
  eval($Position1.getName() contains "POS-RPT_0_1")
  then
  
  util.setColor($Position1, "red");
  end
   
  Before firing the rules, I assert my object as 
   
  posIn = new Position(name,
     id,
     symbolCode,
     lonDouble,
     latDouble,
     elevDouble,
     reportDate,
     this);
    workingMemory.assertObject ( posIn );
    workingMemory.fireAllRules(); 
   
  I get the following error.
   
  org.drools.rule.InvalidRulePackage: Rule Compilation error The left-hand side of an assignment must be a variable Syntax error on token "contains", invalid AssignmentOperator 
  at org.drools.rule.Package.checkValidity(Unknown Source)
  at org.drools.common.AbstractRuleBase.addPackage(Unknown Source)
   
  What is wrong with my drl? I have a Utilities class that I have defined as global. 
   
  Thanks
   
  
  
---------------------------------
  Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase.   

_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users 





-- 
Sivaramakrishna Iyer Krishnan (Anand) 

Never assume the obvious is true. 

- William Safire _______________________________________________ 
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

  
  
---------------------------------
  Need a vacation? Get great deals to amazing places on Yahoo! Travel.   

_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users 





-- 
Sivaramakrishna Iyer Krishnan (Anand) 

Never assume the obvious is true. 
- William Safire _______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


       
---------------------------------
Get the Yahoo! toolbar and be alerted to new email wherever you're surfing. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070618/93629e26/attachment.html 


More information about the rules-users mailing list