//File Wall.java /** * Simple demonstration working with * Java semantec module * @authon Mikhail Podgurskij * 2006/03/05 */ import java.net.URL; import org.drools.RuleBase; import org.drools.WorkingMemory; import org.drools.io.RuleBaseLoader; public class Wall { public static URL ruleSource = Wall.class .getResource("bottles.java.drl"); private int bottles; public Wall(int bottles) { this.bottles = bottles; } public int getBottlesCount() { return bottles; } public void takeOne() { bottles--; } public static void main(String[] args) throws Exception { RuleBase ruleBase = RuleBaseLoader.loadFromUrl(ruleSource); WorkingMemory workingMemory = ruleBase.newWorkingMemory(); workingMemory.assertObject(new Wall(99)); workingMemory.fireAllRules(); } } //File bottles.java.drl Wall Wall wall.getBottlesCount() > 2 System.out.println(wall.getBottlesCount() + " bottles of beer on the wall. "+ wall.getBottlesCount()+ " bottles of beer"); System.out.println("Take one down and pass it around, "+ (wall.getBottlesCount()-1) + " bottles of beer on the wall"); System.out.println(); wall.takeOne(); drools.modifyObject(wall); Wall wall.getBottlesCount() == 2 System.out.println("2 bottles of beer on the wall. 2 bottles of beer"); System.out.println("Take one down and pass it around, 1 bottle of beer on the wall"); System.out.println(); wall.takeOne(); drools.modifyObject(wall); Wall wall.getBottlesCount() == 1 System.out.println("1 bottle of beer on the wall. 1 bottle of beer"); System.out.println("Take one down and pass it around, "+ "No more bottles of beer on the wall"); System.out.println(); wall.takeOne(); drools.modifyObject(wall); Wall wall.getBottlesCount() == 0 System.out.println("No more bottles of beer on the wall. No more bottles of beer"); System.out.println("Go to store and buy some more, "+ "99 bottles of beer on the wall"); wall.takeOne(); drools.modifyObject(wall);