Reflection information about the generated dynamic XML classes is accessible through metatype instances named IlrXmlClass and IlrXmlSimpleType. The package ilog.rules.xml.model provides schema model information at runtime through an API.
You can obtain the process reflection information for both simple types and complex types.
The following example shows how to obtain reflection information on an initialized data driver.
To obtain reflection information on a data driver:
import ilog.rules.xml.model.*;
IlrXmlDataDriver driver = ... // an initialized driver
IlrXmlModel reflect = driver.getXmlModel();
// obtaining class information
IlrXmlClass xmlClass = reflect.getClass ( "myClass" );
// obtaining simple type information
IlrXmlSimpleType xmlSimpleType = reflect.getSimpleType ( "mySimpleType" );
The following example shows how to obtain reflection information on a schema:
To obtain reflection information on a schema:
IlrContext context = ... //an initialized context
IlrXmlDataDriver driver = ... //an initialized driver
IlrXmlModel xmlModel = driver.getXmlModel();
//get information on simple types: facets
IlrXmlSimpleType sType = xmlModel.getSimpleType ( "myType" );
IlrXmlConstraints ctrs = sType.getLocalConstraints ();
//get XML information on complex types
IlrXmlClass cType = xmlModel.getClass ( "myClass" );
int minoccurs = cType.getAttributeMinOccurs ( "attr1" );
<schema targetNamespace="http://www.ilog.com/jrules/training/truck">
<element name = "TruckModel">
<element name="name" type="string"/>
<element name="licenseClass" type="string"/>
<element name="capacity" type="float"/>
<element name="thresholdFull" type="float"/>
?tm: TruckModel(capacity > 8000);
modify ?tm {thresholdFull = 0.9;}
The following example includes a schema and two rules displayZipCodePattern and displayInvalidIntervalFloat to show how to process reflection information on simple types.
To process reflection information on a user simple type:
-
Use the following schema:
<simpleType name="zip-code">
<restriction base="string">
<pattern value="[0-9]{5}" />
<simpleType name="interval">
<restriction base="float">
<minInclusive value="10"/>
<maxInclusive value="20"/>
rule displayZipCodePattern
s: IlrXmlSimpleType() from m.getSimpleType ( null, "zip-code" );
out.printn ( "zip-code pattern : " + s.getPattern() );
rule displayInvalidIntervalFloat
s: IlrXmlSimpleType() from m.getSimpleType ( "Interval" );
f: Float ( !s.isInstance ( this ) );
out.println ( "Invalid float " + f );
The following example includes a schema and two rules displayCollectionAttribute and displayIntXmlElement to show how to process reflection information on complex types.
To process reflection information on a user complex type:
-
Use the following schema:
<complexType name="person"/>
<element name="surname" maxOccurs="4"/>
<element name="age" type="int"/>
rule displayCollectionAttribute
c: IlrXmlClass() from m.getClass ( "Person" );
attr: String ( c.isUnaryAttribute(this) ) in c.getAttributes();
out.println ( "collection attribute : " + attr );
rule displayIntXmlElement
c: IlrXmlClass() from m.getClass ( "Person" );
attr: String ( ) in c.getAttributes();
IlrXmlType ( getXmlName() equals "int" )
from c.getAttributeComponentType ( attr );
out.println ( "int element : " + c.getAttributeXmlName ( attr ) );
Related Concepts
Related Tasks