Class Facet

java.lang.Object
com.saxonica.ee.schema.Facet
Direct Known Subclasses:
AssertionFacet, DigitsFacet, DistinctFacet, EnumerationFacet, EnumerationFacetSet, ExplicitTimezoneFacet, LengthRangeFacet, OrderFacet, PatternFacet, PreprocessFacet, ValueRangeFacet, WhitespaceFacet

public abstract class Facet extends Object
Represents an XML Schema Facet. Most facets are represented by subclasses of this class, the only exception is whiteSpace.
  • Constructor Details

    • Facet

      public Facet()
  • Method Details

    • setFixed

      public void setFixed(boolean fixed)
      Say whether the facet is defined as fixed
      Parameters:
      fixed - true if the facet is fixed
    • isFixed

      public boolean isFixed()
      Ask whether the facet is defined in the schema with fixed="true"
      Returns:
      true if fixed
    • isConstraining

      public boolean isConstraining()
      Ask whether this is a constraining facet (as distinct from a pre-lexical facet)
      Returns:
      true if this is a constraining facet
    • setMessage

      public void setMessage(String message)
      Set the message to be used when this facet is violated. If no message is supplied, a generic message is constructed, for example "the value does not match the pattern XYZ".
      Parameters:
      message - the message to be used
    • getMessage

      public String getMessage()
      Get the message to be used when this facet is violated.
      Returns:
      the message, if one has been set, or null otherwise
    • getName

      public abstract String getName()
      Returns the name of this Facet
      Returns:
      the name of this Facet
    • getConstraintName

      public String getConstraintName()
      Get the name of the XSD constraint associated with this facet
      Returns:
      the XSD constraint name, for example cvc-maxExclusive-valid
    • getValue

      public abstract UnicodeString getValue()
      Returns the lexical representation of the value of this facet
      Returns:
      the value of this facet, as a string
    • toLong

      public long toLong() throws NumberFormatException
      Returns the numeric value of this facet, for facets where this is appropriate
      Returns:
      a long representation of the value of this facet
      Throws:
      NumberFormatException - if the value is not numeric
    • checkFacetRestriction

      public void checkFacetRestriction(UserSimpleType type, SimpleType base, SchemaCompiler compiler) throws SchemaException, ValidationException
      Check that this facet is legal when used on a type derived by restriction
      Parameters:
      type - the type on which the facet is defined
      base - the type from which the restricted type is derived
      compiler - the schema compiler
      Throws:
      SchemaException - if the facet is not legal
      ValidationException - if a value is found that does not conform to the facet
    • isNewlyIntroduced

      public boolean isNewlyIntroduced(SimpleType base)
      Test whether this facet is newly introduced on this type, that is, whether it is absent from the base type
      Parameters:
      base - the base type
      Returns:
      true if the facet is present on this type and not on the base type
    • testAtomicValue

      public abstract boolean testAtomicValue(AtomicValue value)
      Test whether an atomic value conforms to this facet
      Parameters:
      value - the value to be tested
      Returns:
      true if the value conforms; false if it doesn't conform, or if the test fails
    • testListValue

      public boolean testListValue(AtomicSequence value)
      Test whether a list value conforms to this facet. This is used only for the enumeration and assertion facets.
      Parameters:
      value - the value to be tested
      Returns:
      true if the value conforms; false if it doesn't conform, or if the test fails
    • testLength

      public boolean testLength(int count)
      Test whether the length of a list conforms to this facet. Always true except for length facets
      Parameters:
      count - the actual length of the list
      Returns:
      true if the facet allows a list of this length, otherwise false
    • getWhitespaceAction

      public int getWhitespaceAction()
      Get the whitespace action required by this facet: one of PRESERVE, REPLACE, or COLLAPSE. Returns a dummy value of PRESERVE for facets other than whitespace facets.
      Returns:
      the whitespace action, by default PRESERVE
    • serializeFacet

      public void serializeFacet(SchemaModelSerializer serializer) throws XPathException
      Serialize this facet when externalizing the schema component model
      Parameters:
      serializer - receives the content for serialization
      Throws:
      XPathException - if an error occurs writing the value to the output
    • isFacetName

      public static boolean isFacetName(String name, int xsdVersion)
      Test whether a given string is one of the recognized facet names
      Parameters:
      name - a candidate facet name, for example "totalDigits"
      xsdVersion - either XSD10 or XSD11
      Returns:
      true if the name is recognized as a facet name in the selected version of the XSD specification
    • getFacetAsFunctionItem

      public abstract FunctionItem getFacetAsFunctionItem()
      Get a function item that represents this Facet schema component.
    • makeFacet

      public static Facet makeFacet(String name, String value, EnterpriseConfiguration config, NamespaceResolver resolver) throws SchemaException
      Factory method: creates a new Facet with the given name
      Parameters:
      name - the name of the Facet
      value - the value of the Facet
      config - the Saxon configuration
      resolver - a namespace resolver used for resolving prefixes in namespace-sensitive enumeration values
      Returns:
      the constructed facet
      Throws:
      SchemaException - if an error is found