<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:tahoma,new york,times,serif;font-size:10pt"><div>Wolfgang makes a good point. However, given the requirement that the value changes and is not truly static, I would recommend something like the following which, if your SearchParm loads the data from a persisted source you could change it's value without any code change.<br><br>Earnie!<br><br>package com.sample<br><br>rule "Test Rule"<br> <br> when<br> SearchParam($searchName : searchName)<br> $person : Person(name == $searchName)<br> then<br> System.out.println(drools.getRule().getName() + " [" + $searchName + "] [" + $person.getName() + "]");<br>
$person.setActivation(true); <br>end<br><br>package com.sample;<br><br>public class Person {<br> private String name;<br> private Boolean activation;<br><br> public Person(String name, Boolean activation) {<br> this.name = name;<br> this.activation = activation;<br> }<br><br> public String getName() {<br> return name;<br> }<br><br> public void setName(String name) {<br> this.name = name;<br> }<br><br> public Boolean getActivation() {<br> return activation;<br> }<br><br> public void setActivation(Boolean activation) {<br>
this.activation = activation;<br> }<br><br>}<br>package com.sample;<br><br>public class SearchParam {<br>private String searchName;<br><br>public SearchParam(String searchName) {<br> super();<br> this.searchName = searchName;<br>}<br><br>public String getSearchName() {<br> return searchName;<br>}<br><br>public void setSearchName(String searchName) {<br> this.searchName = searchName;<br>}<br><br>}<br><br></div><div style="font-family: tahoma,new york,times,serif; font-size: 10pt;">package com.sample;<br><br>import java.io.InputStreamReader;<br>import java.io.Reader;<br>import java.util.Properties;<br><br>import org.drools.RuleBase;<br>import org.drools.RuleBaseFactory;<br>import org.drools.StatefulSession;<br>import org.drools.compiler.PackageBuilder;<br>import org.drools.compiler.PackageBuilderConfiguration;<br>import
org.drools.rule.Package;<br>import org.drools.rule.builder.dialect.java.JavaDialectConfiguration;<br>import org.junit.Before;<br>import org.junit.Test;<br>import static org.junit.Assert.*;<br><br><br>public class GlobalTest {<br> private RuleBase ruleBase;<br><br> @Test<br> public void testWithGlobal() {<br> StatefulSession ss = ruleBase.newStatefulSession();<br> Person p = new Person("John",false);<br> ss.insert(p);<br> SearchParam sp = new SearchParam("John");<br> ss.insert(sp);<br> ss.fireAllRules();<br> assertTrue(p.getActivation().equals(true));<br> }<br> @Before<br> public void
buildRules() throws Exception {<br> Reader source = new InputStreamReader(this.getClass()<br> .getResourceAsStream("/test.drl"));<br><br> Properties props = new Properties();<br> props.setProperty("drools.dialect.java.compiler", "JANINO");<br> PackageBuilderConfiguration cfg = new PackageBuilderConfiguration(props);<br> JavaDialectConfiguration javaConf = (JavaDialectConfiguration) cfg<br> .getDialectConfiguration("java");<br> javaConf.setCompiler(JavaDialectConfiguration.JANINO);<br> PackageBuilder builder = new
PackageBuilder(cfg);<br><br> builder.addPackageFromDrl(source);<br><br> Package pkg = builder.getPackage();<br><br> ruleBase = RuleBaseFactory.newRuleBase();<br> ruleBase.addPackage(pkg);<br> }<br>}<br><br><div style="font-family: arial,helvetica,sans-serif; font-size: 13px;"><font size="2" face="Tahoma"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Wolfgang Laun <wolfgang.laun@gmail.com><br><b><span style="font-weight: bold;">To:</span></b> Rules Users List <rules-users@lists.jboss.org><br><b><span style="font-weight: bold;">Sent:</span></b> Monday, June 1, 2009 7:57:36 AM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: re[rules-users] move hardcoded values in DRL or have constants inside drl<br></font><br>
But assigning a value to a global isn't straightforward - you can't do<br>it in the declaration. You'll have to do it from the application (or<br>use some dirty hack, in a start-up rule); either way it's separate<br>from the declaration.<br><br>IMHO, using a Java class with public static final is definitely cleaner.<br><br>-W<br><br><br>2009/6/1 Earnest Dyke <<a ymailto="mailto:earniedyke@yahoo.com" href="mailto:earniedyke@yahoo.com">earniedyke@yahoo.com</a>>:<br>> How about adding them as Globals and referencing them that way? You should<br>> be able to put them in a map as well in a Global and reference them.<br>><br>> Earnie!<br>><br>> ________________________________<br>> From: karthizap <<a ymailto="mailto:karthizap@gmail.com" href="mailto:karthizap@gmail.com">karthizap@gmail.com</a>><br>> To: <a ymailto="mailto:rules-users@lists.jboss.org"
href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>> Sent: Monday, June 1, 2009 7:14:56 AM<br>> Subject: re[rules-users] move hardcoded values in DRL or have constants<br>> inside drl<br>><br>> Is there is anyway i can remove hardcoded values in the DRL file? Can I have<br>> the constants file(like data dictionary) inside drl/functions. I don't want<br>> to refer java constants class directly in drl file and would like to declare<br>> and refer those constants inside drl file.<br>> ________________________________<br>> View this message in context: remove hardcoded values in DRL or have<br>> constants inside drl<br>> Sent from the drools - user mailing list archive at <a target="_blank" href="http://Nabble.com">Nabble.com</a>.<br>><br>> _______________________________________________<br>> rules-users mailing list<br>> <a ymailto="mailto:rules-users@lists.jboss.org"
href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>><br>><br>_______________________________________________<br>rules-users mailing list<br><a ymailto="mailto:rules-users@lists.jboss.org" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br></div></div></div></body></html>