ILOG JRules User Guide > Testing Rules with Rule Scenario Manager > Tasks > Defining Rule Scenario Manager Artifacts > BOMXML Serialization

Rule Scenario Manager can serialize from Excel input data. The Rule Scenario Manager generic converter works independently in the case of classes containing a default constructor and read/write attributes:

When a class contains attributes (which can be read-only) that are initialized by passing parameters to the constructors, you can mark a constructor as to be used for conversion by setting the property:

ilog.rules.engine.dataio.forConversion="true"

on this constructor. Note that there can be only one constructor marked in this way.

The converter uses the parameter names to retrieve the corresponding attributes, therefore you must ensure that the names of the parameters match the names of the attributes.

When writing XML, the attributes (which can be read-only) that correspond to the constructor's parameters are written as regular attributes.

When reading XML, the attributes that correspond to the constructor's parameters are read prior to creating the instance; therefore, they must not reference the instance currently being read. Then, the instance is created by invoking the constructor marked to be used for conversion. Finally, the remaining attributes are processed.

For example, consider the following business class:

class Person {
   Person(int age, java.lang.String name)
   property ilog.rules.engine.dataio.forConversion "true";
   readonly int age;
   readonly java.lang.String name;
   java.lang.String address;
}

The corresponding XML is:

<Person>
  <age>
    <int>50</int>
  </age>
  <name>
    <string>Popol</string>
  </name>
  <address>
    <string>PitchiPoï</string>
  </address>
</Person>

When read, the age and name are first converted to objects and passed to the Person constructor.

When written, the age and name read-only attributes are written because they are referenced in the forConversion constructor.

Note
This constructor could reference attributes that are not read-only.

Conversion of inner classes (non-static nested classes)

Consider the following inner class:

class Person {
  class Address {
    Address(Person person);
    java.lang.String street;
    int number;
  }
  Person();
  Person.Address address;
}

The generic converter does not directly support it, as the nested class does not provide access to the enclosing class in a public manner. To enable the conversion of such a class, the enclosing class must be retrieved, and a link between this attribute and the constructor parameter is required, as described previously.

So in this example you can rewrite the business class as:

class Person {
  class Address {
    Address(Person person)
    property ilog.rules.engine.dataio.forConversion "true";
    java.lang.String street;
    int number;
    readonly Person person;
  }
  Person();
  Person.Address address; 
}

In the corresponding Java class, if there is one, you need to add the getPerson method:

public class Person {
  public class Address {
    public Person getPerson() { return Person.this; }
    //...
  }
  //...
}

In this example, a Person and its Address will be serialized as:

<Person id="1">
<address>
<Person.Address>
<street><string>Sesame</string></street>
<number><int>1</int></number>
<person reference="1" />
</Person.Address>
</address>
</Person>

Related Concepts

Data and Datasets
Execution Trace

Related Tasks

Input and Output Parameters in Excel
RSMXML Serialization

Related Reference

Rule Scenario Manager XML and Java Artifacts

Related Samples

How to Test Rules in Rule Scenario Manager Using Java Binding
How to Test Rules in Rule Scenario Manager using XML Binding