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 for the decision engine.

  2. Declare parameters directly to the decision engine.
    Provide the following parameters when you call the engine for rule execution:
    IlrXmlObject xmlObject = ...
    engineInput.setParameter( "myXmlParameter", xmlObject ) ;
    engine.execute (myEngineInput);

    You can use the method IlrContext#setParameters(IlrParameterMap%20parameters) to set parameters by providing a map. The map creates an association between the name and the value. 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.

  3. To execute the rules in a stateful session, use the following method:
    IlrSessionResponse response = rulesession.execute(params);
  4. 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.