Using XML objects as ruleset parameters

You can use XML objects as ruleset parameters.

Before you begin

You must first declare each parameter available for the rule session in Rule Designer.

About this task

With ruleset parameters, you can exchange data between your ruleset and an external application. There is no difference in the way XML objects and Java™ objects are handled.

Procedure

To set an XML object as a ruleset parameter:

  1. Create an XML object:
    IlrXmlObject xmlObject = ... //your object

    See also Reading XML documents (classic rule engine) or Reading XML documents (decision engine).

  2. When you use the classic rule engine, use the IlrContext class to declare an initialized context:
    IlrContext engine = ... //your engine
  3. Declare parameters directly to the rule engine.

    When you use the classic rule engine, set the parameters before setting the rules, and use the setParameterValue method to identify the name of each ruleset parameter.

    IlrContext engine = ...
    IlrXmlObject xmlObject = ...
    engine.setParameterValue( "myXmlParameter", xmlObject ) ;
    engine.execute ();

    When you use the decision engine, provide the parameters when you call the engine for rule execution as follows:

    IlrXmlObject xmlObject = ...
    engineInput.setParameter( "myXmlParameter", xmlObject ) ;
    engine.execute (myEngineInput);

    You can use the method setParameters to set parameters by providing a map. The map creates an association between the name and the value.

    When you work with the decision engine, the <EngineInput>.setParameters(map) method can be used in a similar way.

    When you use XML binding with Rule Execution Server, you can pass the parameters directly as String values. Pass the XML parameters as java.lang.String instances to the rule session API, which returns the output XML parameters as java.lang.String instances in its turn.

  4. To execute the rules in a stateful session, use the following method:
    IlrSessionResponse response = rulesession.execute(params);
  5. To execute the rules in a stateless session, use the following method:
    IlrSessionRequest request = ...;
    IlrSessionResponse response = rulesession.execute(request);

    For stateless sessions, you pass the path of the ruleset to be executed as follows:

    request.setRulesetPath(new IlrPath("/MyruleApp/Myruleset");

    You pass the session parameters in one of the following ways:

    request.setInputParameters(map);

    Or:

    request.getInputParameters().put("loan", createLoan());
    request.getInputParameters().put("borrower", createBorrower());

Results

When you use the XML binding API, you must pass only the String value. You do not have to deal with the XML driver. The rule session API provides access to the engine and as a result hides the IlrContext API, which is used to access the classic rule engine.