Application Data allows for objects to be made available to Conditions and Consequences without having to assert them into the Working Memory.
To use Application Data you must first declare them in your DRL, after any import declarations.
The above lets my Rule Set know that a variable named "amount" is available in each condition and consequence and is of the type java.lang.Integer. With the Application Data now declared we can set their values in the Working Memory, the method signature is:
Only objects can be added to the Application Data; primitives must be wrapped:
If you are using the Java semantic you must unwrap your primitives on comparisons:
However Groovy performs autoboxing so the following is possible:
Any object can be made available and is automagically bound to the variable name specified.
If an identifier is not declared in a Rule Set it will not be available to any Conditions or Consequences, even if another Rule Set declares it and sets the value in the Working Memory.
If an Application Data identifier is declared more than once for different Rule Sets in a single RuleBase then they reference the same object in the Working Memory and must be of the same type - a RuntimeException is thrown if the types are different.
The Pet Store Example illustrates Application Data being used to pass a JFrame reference to a Consequence to allow user feedback.