Facet validation
A facet is a characteristic of a data type that restricts possible values. For example, setting a minimum value or matching a specific regular expression.
Gosu represents each facet as an element. Each facet element has a fixed attribute that is a Boolean value. All the facets for a simple type collectively define the set of legal values for that simple type.
Most schema facets are validated at property setting time. A few facets are not validated until serialization time to allow incremental construction of lists at runtime. This mostly affects facets relating to lengths of lists, and those that validate QName objects. Gosu cannot validate QName objects at property setting time because there is not enough information available. Guidewire recommends that you do not apply facets to QName objects.
Example
The following XSD contains defines an attribute that has restricted values.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Element1">
<xsd:complexType>
<xsd:attribute name="Attr1" type="AttrType"/>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="AttrType">
<xsd:restriction base="xsd:int">
<xsd:minInclusive value="0"/>
<xsd:maxInclusive value="5"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
The following code demonstrates the facet validation of the attribute that has restricted values.
uses examples.pl.gosu.xml.myschema.Element1
var xml = new Element1()
xml.Attr1 = 3 // Works!
xml.Attr1 = 6 // Fails with an exception.
This code prints the following:
gw.xml.XmlSimpleValueException: Value '6' violated one or more facet constraints
of simple type definition: value must be no greater than 5