Atomic, User-Defined types

Atomic, user-defined types are specified in XSD using <xsd:simpleType> with <xsd:restriction>. The purpose is to further restrict some facet of the base type.

These XSD types are frequently defined anonymously. In that case, XBinder will generate validation code where the anonymous type is being used. If a named type is defined, XBinder will generate a corresponding class with static encode/decode methods. Validation logic will be generated into the encode/decode methods. In both cases, values of these types are represented according to the type mappings given in the table above (with the exception of enumerations; see Enumeration, below).

Example XSD: define an integer-based type that ranges from 27 to 65:

   <xsd:simpleType name="TwentySevenSixtyFive">
      <xsd:restriction base="xsd:integer">
         <xsd:minInclusive value="27"/>
         <xsd:maxInclusive value="65"/>
      </xsd:restriction>
   </xsd:simpleType>

C#:

   public class TwentySevenSixtyFive
   {
      public static readonly byte _MIN = 27;
      public static readonly byte _MAX = 65;

      //constructor
      private TwentySevenSixtyFive() {} 


      public static String encode(byte value, XBContext xbContext) {...}

      public static byte decode(String text, XBContext xbContext) {...}
   }

Java:

   public class TwentySevenSixtyFive
   {
      public static final byte _MIN = 27;
      public static final byte _MAX = 65;

      //constructor
      private TwentySevenSixtyFive() {} 


      public static String encode(byte value, XBContext xbContext) {...}

      public static byte decode(String text, XBContext xbContext) {...}
   }

The generate encode and decode methods validate the min/max facets, as well as converting between a value representation (byte) and lexical representation (String). As mentioned above, the encode/decode methods in this case are static; the class simply provides coding services and does not represent values of the type it supports.

Note that XBinder chose to represent values of this type using byte. Given the value range, XBinder determined this is the most appropriate representation. This selection can be overridden using a configuration file. As a quick example, to use a short instead of a byte in the above example, you would use the following configuration file:

   <bindings version="1.0">
      <schemaBindings schemaLocation="example.xsd">
         <nodeBindings node=
          "/xsd:schema/xsd:simpleType[@name=&quot;TwentySevenSixtyFive&quot;]">
            <javatype>int16</javatype>
            <cstype>int16</cstype>
         </nodeBindings>
      </schemaBindings>
   </bindings>

For more information on using configuration files, see the section "Configuration File".