Werecat Rules

Werecat supports the following JSON format for defining rules.

{
  "top": "top node tag",
  "version": "1.0",
  "imports": [ "java.util.Calendar", ... ],
  "rules": {
    ...
  }
}

top is the default entry point for the rules engine. This is optional, but if it's not specified, you may not call the evaluate method in RuleEngine (instead, call getRule, and use the evaluate method of the rule you instead to start with).

version is for your own versioning (optional).

imports is an optional list of classes to import. You can import an entire package using .*, or a specific class, as per usual Java imports. This is identical to calling RuleFactory.addImport in your code, use whichever method you prefer.

rules is the list of rules (required).

Each rule should following the format below:

    "tag" {
        "description": "Some notes"
        "condition": "value != null"
        "accept": "actionlist"
        "decline": "actionlist"
    },

Each rule must be associated with a unique tag. This should generally look like an identifier, but the only real rule is that it cannot contain parentheses.

description is for your own use (optional).

condition is an expression (required). If you have no need for conditional logic, you may use the constant true for the expression.

accept is the list of actions to take when the condition is true (optional).

decline is the list of actions to take when the condition is false (optional).

The action list is a semicolon separated list of actions, which fall into one of two types. You may have any number of actions or either type, or none at all. If there are multiple actions, they will be evaluated in the order they appear in the rule.

tag An action may contain a tag. If the tag is present, then the rule engine will proceed to the named rule. If no tag is present in the action list, rule evaluation will stop with this rule.

call An action may contain a call. Each call may pass parameters and use expressions, but any arguments must be of the correct type to call the name function.

[Back to Werecat Home]