| ILOG JRules User Guide > Integrating Application Data > Reference > Mapping Between XML Schema and Dynamic Classes > Schema Types > Simple Types Derived from Other Simple Types |
Simple Types Derived from Other Simple Types |
PREVIOUS NEXT |
Deriving a simple type from another simple type implies incorporating restrictions to the more general simple type. This can be done using facets, a set of predefined constraints that help define new simple types by restricted built-in type. An example of a facet is a pattern where a zip code is defined as containing only five digits.
The following schema shows a simple type definition:
<simpleType name="myType">
<restriction base="string">
<pattern value="*A"/>
</restriction>
</simpleType>
<attribute name = "typeValue" type = "myType"/>
In this example, a simple type myType is defined as a subtype of string. The typeValue attribute will be mapped to a dynamic class field of type java.lang.String.
When simple type definitions are mapped to dynamic class types, the type hierarchy tree is searched. Starting from the most restrictive type, the hierarchy tree is searched upwards until a built-in type is found that maintains the mapping type as the simple type definition mapping.
The following zip code example shows how user schema simple types are represented in the XOM and which methods are generated to manipulate them. A set of static methods are declared that can be called from a rule. Two rules named checkFloatInInterval and findZipCodePattern are used to test the ZipCode objects.
Here is the schema:
<simpleType name="zip-code">
<restriction base="string">
<pattern value="A[0-9]{5}"/>
</restriction>
</simpleType>
<simpleType name="Interval">
<restriction base="float">
<minInclusive value="1.1"/>
<maxInclusive value="3.1"/>
</restriction>
</simpleType>
Here is the XOM representation:
class ZipCode extends IlrXmlObject
{
static String getPattern();
static int getMinLength();
static int getMaxLength();
static getLength();
static String[] getEnumerations();
}
class Interval
{
static String getPattern();
static int getMinLength();
static int getMaxLength();
static getLength();
static float[] getEnumerations();
static float getMinInclusive ();
static float getMaxInclusive ();
static float getMinExclusive ();
static float getMaxExclusive ();
static int getTotalDigits();
static int getFractionDigits();
}
And here are the rules:
rule checkFloatInInterval
{
when {
f: Float ( i: floatValue(); Interval.getMinInclusive() <= i;
i <= Internal.getMaxInclusive() );
}
then {
out.println ( f + " in Interval" );
}
}
rule findZipCodePattern
{
when {
s: String ( equals ZipCode.getPattern() );
}
then {
out.println ( s + " equals zip code pattern" );
}
}
The simple type dynamic method provides information on the type facets value. It returns the last facet definition in the type hierarchy. This means that if a facet is defined twice in the type hierarchy, the nearest definition is returned. If a facet is not defined, a special value (usually null) is returned depending on the facet type.
Types of facets include:
getMinInclusive, getMaxInclusive, getMinExclusive, getMaxExclusive.
getPattern, getMinLength, getMaxLength, getLength.
getEnumerations.
getTotalDigits, getFractionDigits.
The following table shows the returned values when the facet is not defined.
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |