Skip to: Site menu | Main content


Java Rules Engine

House Example Print


The House example is a very simple Domain Specific Language example (DSL). The DSL in the example creates and maps custom xml elements to java conditions and consequences.

Running the House Example

D:\java\workspaces\drools-2.0\drools-examples>maven house
 __  __
|  \/  |__ _Apache__ ___
| |\/| / _` \ V / -_) ' \  ~ intelligent projects ~
|_|  |_\__,_|\_/\___|_||_|  v. 1.0

(bunch of output)

Total time: 21 seconds
Finished at: Tue Mar 22 21:32:19 CET 2005

Understanding the House Example

The first rule turns the heating off when the temperature is greater than 20 degrees celsius.

The second rule turns the heating on when the temperature is less than 20 degrees celsius.

To get a DSL working in drools first register the configuration file in the drools.conf file:


This tells the Semantics Module Framework (SMF) to load the drools-house SMF configuration file at startup:


Condition(condition) :
Consequence(actions) :

This configuration file tells drools which factories to use for conditions and actions in the namespace house. Notice that the xml name for consequences and conditions are configurable and in this case the consequence is referred to as actions.

The contents of each condition or actions element is recorded in a Configuration object, which is a hierarchical representation of the sub elements, and then passed to the specified factory implemention to create the underlying condition or consequence. To understand how Configuration object is interpreted and the conditions and consequences made see HouseConditionFactory and HouseConsequenceFactory.