ILOG JRules User Guide > Integrating Application Data > Tasks > Using the XML Binding API > Configuring XML Binding > Configuring an XML Data Driver

You can configure an XML data driving using a configuration file, or using an XML helper. You can also use a resource file to parameterize an XML data driver, and use synchronization to make the data driver multi thread safe.

To configure an XML data driver using a configuration file:

import ilog.rules.util.resources.IlrResources;
 
IlrReflect reflect = ... // coming from somewhere
IlrResources res = reflect.getResources();
res.putString( "ilog.rules.xml.errorHandlerClass", "MyXmlErrorHandler" );
try {
IlrXmlDataDriver driver = IlrXmlHelper.createDataDriver ( reflect );
} catch ( IlrXmlErrorException e) {}
      // process creation error
   }
}
else {
   // process error
}
The following example shows the resource file:
node ilog.rules.xml
{
  element errorHandlerClass = "MyXmlErrorHandler";
}

Note
The XML parser property is set using the Java API and not directly in the file.

The following example shows how to create and configure an XML driver using an XML helper.

To configure an XML data driver using an XML helper:

// configuration setting
IlrXmlHelper.Config config = new IlrXmlHelper.Config ();
config.schemaParser = ...;
...
try {   IlrXmlDataDriver driver = IlrXmlHelper.createDataDriver ( config );
 } 
catch ( IlrXmlErrorException e ) {  
// some parsing error
}
See IlrXmlDataDriver and IlrXmlHelper.

You can parameterize an XML data driver using a resource file, which consists of named and valued properties.

To parameterize an XML data driver:

  1. If you do not already have a resource file, create one.
  2. Add the properties you require to the resource file.
  3. The following properties are processed by the XML binding:
    1. ilog.rules.xml.xomMapperClass property. The fully qualified class name of the schema-XOM mapper.
    2. ilog.rules.xml.errorHandlerClass property. The fully qualified class name of the error handler.
    3. ilog.rules.xml.schemaParserClass property. The fully qualified class name of the XML parser class used to parse the XML schema.
    4. ilog.rules.xml.documentParserClass property. The fully qualified class name of the XML parser class used to parse the XML document.
  4. Use the contents of the resource file to create an instance of the XML data driver.

When an XML data driver is created without specifying a resource file, the resource related to its XOM IlrReflect instances is used, if it exists. In this way, any XML data driver may be parameterized through the global engine resource file.

An IlrXmlDefaultDataDriver instance is only multi-thread safe if wrapped by an instance of ilog.rules.xml.util.IlrXmlSynchronizer. The synchronization may also include the XOM by using the class IlrXmlSynchronizer.IlrXmlDataDriver.

To make the XML data driver multi-thread safe:

IlrXmlDataDriver stdDriver = new IlrXmlDefaultDataDriver();
IlrXmlDataDriver syncDriver = new IlrXmlSynchronizer ( stdDriver, true );
// The syncDriver is now multithead safe.
syncDriver.loadModel ( ... );
Setting this parameter makes sure that the XOM and the data driver are multithread safe during all data driver operations. If the XOM is not synchronized in this way, mapping operations involving access to the XOM will not be multithread safe.
Note
The driver will be multithread safe for these mapping operations if the XOM is accessed independently from the XML driver.

Related Concepts

The Configuration Resource File
XML Binding
Web Service Binding

Related Tasks

Getting XPath Information on an IlrXmlObject