ILOG JRules User Guide > Integrating Application Data > Tasks > Using the XML Binding API > Configuring XML Binding > Configuring the Mapping Between XML Schema and Dynamic Classes

XML binding provides a default mapping between the XML Schema and the Java model. The ilog.rules.xml.util.IlrXmlDefaultXomMapper class implements the default mapping behavior. However, you can modify this mapping by implementing a special interface ilog.rules.xml.util.IlrXmlXomMapper and the ilog.rules.xml.xomMapper property, and declaring it to the driver using the resource file.

In order to modify the way XML elements are mapped to Java identifiers, you can implement the following methods of the IlrXmlXomMapper interface:

The isInnerClass method indicates whether or not the XSD 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 ilog.rules.xml.IlrXmlObject. If you define a different mapping, the new mapping class must:

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:

The following procedure shows an example of a mapping that changes the default behavior slightly.

To configure the mapping to change default behavior:

  1. Do not use the default List suffix to map the collection element.
  2. Map the complex types on the MyXmlObject Java class, which inherits from ilog.rules.xml.IlrXmlObject.
  3. Map the XOM field xomField1 of type java.lang.String on the Java field javaField1 of the MyXmlObject class.
  4. The new mapper class is:
public class MyXmlXomMapper
   extends IlrXmlDefaultXomMapper
{
   public String formatFieldName ( String namespace,String xmlField,
          boolean flagIsUnary )
   {
      return ( formatJavaIdentifier ( xmlField, false ) );
   }
   public Class mapComplexType ( String namespace, String xmlComplexType ) 
   {
      return MyXmlObject.class;
   }
   public Field mapXomField ( IlrAttribute xomField,Class parentJavaClass )
    {
        try {
           return ( xomField.getName().equals ( "xomField1" ) ?
           parentJavaClass.getField ( "javaField1" ) : null );
        }
        catch (NoSuchFieldException e) {
           return null;
        }
    }
}
The new IlrXmlObject class is:
public class MyXmlObject
   extends IlrXmlObject
{
   public String javaField1 = null;
   public MyXmlObject ()
   {
      super ();
   }
   public String toString ()
   {
      return printToString ();
   }
}

Related Concepts

The Configuration Resource File
XML Binding

Related Tasks

Getting XPath Information on an IlrXmlObject
Inspecting an XML Model
Configuring an XML Data Driver
Getting XPath Information on an IlrXmlObject

Related Reference

Mapping Between XML Schema and Dynamic Classes