Storing configuration

Two ways of providing configuration to the rule engine are available:

  • Reading a file (with an absolute path or within the CLASSPATH)
  • Directly providing the XML content. This option is more test oriented.

Great are the chances that the application will store the configuration by other means, such as a database. It’s of course possible and facilitated by utilities. Configuration retrieval from DB will be encapsulated with an implementation of IRuleEngineConfigHolder. The abstract implementation AbstractRuleEngineConfigHolder, performing generic operations, is provided. Simply extend it with your own implementation.

Let’s consider that the rule engine configuration is stored in a DB table, with three columns:

  • A unique code.
  • A last update date.
  • The XML content.

The MyDatabaseXmlConfigHolder class will have to override / implement three methods:

  • init : Holder initialization with the “MyDatabaseXmlConfigHolder.code” parameter, containing the code.
  • getConfigHash : returning a String allowing to identify changes in configuration. Here, last update date is perfect.
  • build : building or retrieving the engine.

Example of implementation, redirecting DB access to the DBService class:

After this, retrieving the engine instance is done in a standard way, for example using injection: