Java Semantic Module DRL Reference
Namespace URI

The Java Semantic Module is available through the Drools Rule Language (DRL) by binding the namespace of http://drools.org/semantics/java to either the default namespace or a specific prefix. Typically it is bound to the java prefix.

<rule-set xmlns:java="http://drools.org/semantics/java"
          ...>
Tag Reference
<java:class>

The <java:class> tag provides access to the ClassObjectType object-type differentiator based upon the Java class hierarchy.

The fully-qualified name of the class or interface to match is provided as the content of the tag.

<java:class>com.mycompany.Person</java:class>
<java:condition>

The <java:condition> tag provides access to the ExprCondition condition based upon Java boolean expressions.

An expression that yields a boolean result is the content of the tag. Currently logical-or (||) expressions are disallowed. Since valid java expressions may use the characters < and >, these characters must be escaped using their character entities, &lt; and &gt;, respectively.

<java:condition>employee.getSlackRatio() &gt; 0.25</java:condition>
<java:extractor>
<java:consequence>

The <java:consequence> tag provides access to the BlockConsequence consequence based upon a list of Java statements.

A Java statement block is the content of the tag. The block is eventually interpreted by BeanShell, so it's actually a super-set of Java. All fact objects are available within the consequence as is a special variable, appData, which is the application data object provided through the working-memory.

Three global functions are also available with the consequence:

  • assertObject(Object object)
    To assert a new object into the working-memory.
  • modifyObject(Object object)
    To assert a change in an existing fact in the working-memory.
  • modifyObject(Object oldObject, newObject)
    To assert a new value for an existing fact in the working-memory.
  • retractObject(Object object)
    To retract a fact from the working-memory.
<java:consequence>
  import com.mycompany.ChipperShredder;

  ChipperShredder.getInstance().accept( employee );

  modifyObject( employee );
</java:consequence>