ILOG JRules User Guide > Integrating Application Data > Reference > Mapping Between XML Schema and Dynamic Classes > Schema Types > Simple Types Derived from Other Simple Types

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:

The following table shows the returned values when the facet is not defined.

Table 3 Returned Values with Undefined Facet 
Types 
getMinInclusive getMinExclusive 
GetMaxInclusive getMaxExclusive 
getMinLength getMaxLength  
getLength getTotalDigits getFractionDigits 
getEnumerations 
float 
-Float.MAX_VALUE 
Float.MAX_VALUE 
IlrXmlObject.UNKNOWN_ 
POSITIVE_VALUE 
float[0] 
double 
-Double.MAX_VALUE 
Double.MAX_VALUE 
double[0] 
byte 
Byte.MIN_VALUE 
Byte.MAX_VALUE 
byte[0] 
int 
Integer.MIN_VALUE 
Integer.MAX_VALUE 
int[0] 
long 
Long.MIN_VALUE 
Long.MAX_VALUE 
long[0] 
Object 
null 
null 
Object[0] 

Related Reference

Built-in Simple Types
Simple Type Mapping
List and Union Types
Local Simple Types Mapped onto Inner Classes
Complex Types
Extension of Simple Type Content in Complex Types
Complex Type Restriction
Complex Type Extension
Local Complex Types Mapped to Inner Classes
Default Constructor Dynamic Methods
Type Identifier Mapping