Configuring the mapping between XML schema and dynamic classes
You can configure the mapping between the XML schema and the XOM by API.
About this task
XML binding provides a default mapping between XML schemas and the Java™ model. The IlrXmlDefaultXomMapper class implements the default mapping behavior. However, you can modify this mapping by implementing a special interface IlrXmlXomMapper and the ilog.rules.xml.xomMapper property, and declaring it to the driver by using the resource file.
In order to modify how XML elements are mapped to Java identifiers, you can implement the following methods of the IlrXmlXomMapper interface:
-
formatClassName
-
formatSimpleTypeName
-
formatFieldName
-
formatAnyFieldName
-
formatNewIdentifier
-
formatContentFieldName
The isInnerClass method indicates whether the schema local types are mapped to dynamic inner Java types and the mapComplexType method indicates which Java class maps to a given complex type.
The default mapping is the IlrXmlObject. If you define a different mapping, the new mapping class must satisfy the following conditions:
-
The mapping class must inherit from IlrXmlObject, directly or indirectly.
-
The mapping class must be defined as public and composed of a public void constructor.
If the new mapping class contains Java fields, you can map XML attributes or elements to these fields. The mapXomField method indicates for each XOM field their related Java field as a java.lang.reflect.Field instance. If the mapping is dynamic, the method should return a null value.
In addition, the Java field must satisfy the following conditions:
-
Belong to the Java class mapped on the related XOM class. This Java class is given as a mapXomField parameter
-
Be a subtype of the XOM field type
-
Be public
The following procedure shows an example of a mapping that changes the default behavior slightly.
Procedure
To configure the mapping to change default behavior:
Results
Here is the new IlrXmlObject class.
public class MyXmlObject
extends IlrXmlObject
{
public String javaField1 = null;
public MyXmlObject ()
{
super ();
}
public String toString ()
{
return printToString ();
}
}