XML serialization of ruleset XOMs
In the REST service for ruleset execution, primitive Java™ types, XSD types, and Java XOM classes are serialized differently.
Ruleset parameters are handled differently depending on whether they are expressed as XML elements or as Java types.
Primitive types
Primitives types are Java types and classes that can be written as inline strings. The XML element that is used to serialize a primitive type as a ruleset parameter is the name of the ruleset parameter in the parameter namespace.
- Changing target namespaces explains how to customize the parameter namespace from the Ruleset View in the Rule Execution Server console.
- XML serialization of Java types shows the XML types and Java Architecture for XML Binding (JAXB) annotations for Java primitive types and simple types.
Dynamic XOM
For dynamic XOMs, the root element depends on how the ruleset parameters are defined. The XML description is serialized from the original XSD code of the dynamic XOM on which the ruleset is based.
- Name of the root element
- For rulesets that are based on a dynamic XOM, the root element name is determined as follows:
- If the parameter is an XML element in the ruleset signature, that element is used as the root element name of the parameter in requests and responses.
- If the parameter is a complex or primitive Java type, the parameter name is used as the
root element name of the parameter in requests and responses, within
the configured param namespace.Note: A ruleset parameter is declared from an XML element if it meets the following condition: that parameter uses an XML complex type for which an XML element was declared from that complex type in the original imported XSD file. For example, starting from the following XSD definition:
the ruleset parameter is declared from the MyConference XML element:<xsd:element name="MyConference"> <xsd:complexType> <xsd:sequence> <xsd:element name="session" type="session" maxOccurs="unbounded"/> <xsd:element name="participant" type="participant" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element>
<par:Request xmlns:par="http://www.ibm.com/rules/decisionservice/myruleapp/myruleset/param" xmlns:jav="http://www.acme.com/myconference"> <jav:MyConference> <jav:session> […] <jav:session> <jav:MyConference> </par:Request>
- Serialization
- The root element depends on your XML types.
- For XML complex types, the parameter declaration uses the parameter name (in the parameter namespace) as the root element.
- For XML elements, the parameter declaration uses the defined XML element as the root element in the original namespace. In this case, the name of the parameter that is attached to each node is provided in the WADL code as a comment message.
Java XOM
- Name of the root element
For rulesets that are based on a Java XOM, the parameter declaration uses the parameter name (in the parameter namespace) as the root element.
- Serialization
- The XML structure of Java XOM
classes is serialized through the standard JAXB process. If the default
serialization does not provide the results that you expect for your
classes, you can customize the serialization process by using JAXB
annotations. Note: A parameter is visible as an XML element only if you specify it with an XmlElement annotation or if valid getXXX and setXXX methods apply to the parameter.
- Arrays as ruleset parameters
- In Java XOM, you can specify ruleset parameters as simple or multidimensional arrays. XML serialization is processed differently for each type of arrays:
- If the ruleset parameter is a simple array, the parameter name repeats as a standard array in XML.
- If the ruleset parameter is a multidimensional array, the parameter
name repeats as a standard array type in XML for the first dimension
and then uses item elements for the subsequent dimensions.
For example:
<myMultiDimArrayParam> <item>1</item> <item>2</item> </myMultiDimArrayParam> <myMultiDimArrayParam> <item>3</item> <item>4</item> <item>5</item> </myMultiDimArrayParam>