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"
...>
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>
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,
<
and >
, respectively.
<java:condition>employee.getSlackRatio() > 0.25</java:condition>
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)
modifyObject(Object object)
modifyObject(Object oldObject, newObject)
retractObject(Object object)
<java:consequence>
import com.mycompany.ChipperShredder;
ChipperShredder.getInstance().accept( employee );
modifyObject( employee );
</java:consequence>