-
-
Save mackaypeter/d8b576ce34d42794da559308b1854aff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Test { | |
/** | |
* Unable to Analyse Expression this.getName() == "joe": | |
* [Error: unable to resolve method using strict-mode: org.drools.compiler.oopath.MyTest$Parent.getName()] | |
* [Near : {... this.getName() == "joe" ....}] | |
* ^ | |
* [Line: 4, Column: 2] : [Rule name='R'] | |
*/ | |
@Test | |
public void test() { | |
final String drl = | |
"import "+ Parent.class.getCanonicalName() +";\n" + | |
"import "+ Child.class.getCanonicalName() +";\n" + | |
"rule R " + | |
"when\n" + | |
// using [name==\"joe\"] works OK | |
" Parent( $child : /children, $child.getName() == \"joe\" )\n" + | |
"then\n" + | |
" System.out.println( $child );\n" + | |
"end\n"; | |
final KieSession ksession = new KieHelper().addContent( drl, ResourceType.DRL ) | |
.build() | |
.newKieSession(); | |
Child joe = new Child("joe"); | |
Child jack = new Child("jack"); | |
Parent parent = new Parent(Arrays.asList(joe, jack)); | |
ksession.insert(parent); | |
ksession.fireAllRules(); | |
} | |
public class Child { | |
private String name; | |
public Child(String name) { | |
this.name = name; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public String toString() { | |
return this.name; | |
} | |
} | |
public class Parent { | |
private List<Child> children; | |
public Parent(List<Child> children) { | |
this.children = children; | |
} | |
public List<Child> getChildren() { | |
return children; | |
} | |
public void setChildren(List<Child> children) { | |
this.children = children; | |
} | |
// If this is uncommented, the rule works | |
//public String getName() { | |
// return "definitelyNotJoe"; | |
//} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment