Class EnumerationType

java.lang.Object
net.sf.saxon.type.EnumerationType
All Implemented Interfaces:
AtomicType, CastingTarget, HyperType, ItemType, PlainType, SchemaComponent, SchemaType, SimpleType

public class EnumerationType extends Object implements AtomicType
Proposed extension for XPath 4.0: an enumeration type is a way of defining a subtype of xs:string, with a defined set of permitted values, without recourse to a schema or schema-awareness.

The XPath syntax proposed is enum("A", "B", "C")

  • Constructor Details

    • EnumerationType

      public EnumerationType(Set<String> values)
      Create an enumeration type permitting a defined set of values
      Parameters:
      values - the values to be permitted
  • Method Details

    • validate

      public ValidationFailure validate(AtomicValue primValue, UnicodeString lexicalValue, ConversionRules rules)
      Validate that a primitive atomic value is a valid instance of a type derived from the same primitive type.
      Specified by:
      validate in interface AtomicType
      Parameters:
      primValue - the value in the value space of the primitive type.
      lexicalValue - the value in the lexical space. If null, the string value of primValue is used. This value is checked against the pattern facet (if any)
      rules - the conversion rules for this configuration
      Returns:
      null if the value is valid; otherwise, a ValidationFailure object indicating the nature of the error.
      Throws:
      UnsupportedOperationException - in the case of an external object type
    • isOrdered

      public boolean isOrdered(boolean optimistic)
      Determine whether the atomic type is ordered, that is, whether less-than and greater-than comparisons are permitted
      Specified by:
      isOrdered in interface AtomicType
      Parameters:
      optimistic - if true, the function takes an optimistic view, returning true if ordering comparisons are available for some subtype. This mainly affects xs:duration, where the function returns true if optimistic is true, false if it is false.
      Returns:
      true if ordering operations are permitted
    • isAbstract

      public boolean isAbstract()
      Determine whether the type is abstract, that is, whether it cannot have instances that are not also instances of some concrete subtype
      Specified by:
      isAbstract in interface AtomicType
      Returns:
      true if the type is abstract
    • isPrimitiveType

      public boolean isPrimitiveType()
      Determine whether the atomic type is a primitive type. The primitive types are the 19 primitive types of XML Schema, plus xs:integer, xs:dayTimeDuration and xs:yearMonthDuration; xs:untypedAtomic; and all supertypes of these (xs:anyAtomicType, xs:numeric, ...)
      Specified by:
      isPrimitiveType in interface AtomicType
      Returns:
      true if the type is considered primitive under the above rules
    • isIdType

      public boolean isIdType()
      Ask whether this type is an ID type. This is defined to be any simple type who typed value may contain atomic values of type xs:ID: that is, it includes types derived from ID by restriction, list, or union. Note that for a node to be treated as an ID, its typed value must be a *single* atomic value of type ID; the type of the node, however, can still allow a list.
      Specified by:
      isIdType in interface AtomicType
      Specified by:
      isIdType in interface SchemaType
      Returns:
      true if this type is an ID type
    • isIdRefType

      public boolean isIdRefType()
      Ask whether this type is an IDREF or IDREFS type. This is defined to be any simple type who typed value may contain atomic values of type xs:IDREF: that is, it includes types derived from IDREF or IDREFS by restriction, list, or union
      Specified by:
      isIdRefType in interface AtomicType
      Specified by:
      isIdRefType in interface SchemaType
      Returns:
      true if this type is an IDREF type
    • isBuiltInType

      public boolean isBuiltInType()
      Determine whether the atomic type is a built-in type. The built-in atomic types are the 41 atomic types defined in XML Schema, plus xs:dayTimeDuration and xs:yearMonthDuration, xs:untypedAtomic, and all supertypes of these (xs:anyAtomicType, xs:numeric, ...)
      Specified by:
      isBuiltInType in interface AtomicType
      Specified by:
      isBuiltInType in interface SimpleType
      Returns:
      true if this is a built-in type
    • getTypeName

      public StructuredQName getTypeName()
      Get the name of this type as a StructuredQName, unless the type is anonymous, in which case return null
      Specified by:
      getTypeName in interface AtomicType
      Specified by:
      getTypeName in interface PlainType
      Returns:
      the name of the atomic type, or null if the type is anonymous.
    • getDefaultPriority

      public double getDefaultPriority()
      Description copied from interface: AtomicType
      Get the default priority when this ItemType is used as an XSLT pattern.
      Specified by:
      getDefaultPriority in interface AtomicType
      Specified by:
      getDefaultPriority in interface ItemType
      Returns:
      the default priority. For an atomic type this is 1 minus 0.5^N, where N is the depth of the type in the type hierarchy. The result is 0 for xs:anyAtomicType, 0.5 for a primitive type such as xs:date, and between 0.5 and 1.0 for derived atomic types.
    • getStringConverter

      public StringConverter getStringConverter(ConversionRules rules)
      Get a StringConverter, an object which converts strings in the lexical space of this data type to instances (in the value space) of the data type.
      Specified by:
      getStringConverter in interface AtomicType
      Parameters:
      rules - the conversion rules to be used
      Returns:
      a StringConverter to do the conversion, or null if no built-in converter is available.
    • getPlainMemberTypes

      public List<? extends PlainType> getPlainMemberTypes()
      Get the list of plain types that are subsumed by this type
      Specified by:
      getPlainMemberTypes in interface PlainType
      Returns:
      for an atomic type, the type itself; for a plain union type, the list of plain types in its transitive membership
    • matches

      public boolean matches(Item item, TypeHierarchy th)
      Test whether a given item conforms to this type
      Specified by:
      matches in interface ItemType
      Specified by:
      matches in interface PlainType
      Parameters:
      item - The item to be tested
      th - The type hierarchy cache. Currently used only when matching function items.
      Returns:
      true if the item is an instance of this type; false otherwise
    • getPrimitiveItemType

      public AtomicType getPrimitiveItemType()
      Redeclare getPrimitiveItemType() to return a more specific result type Get the primitive item type corresponding to this item type. For anyAtomicValue and union types it is Type.ATOMIC_VALUE. For numeric it is Type.NUMBER. For other atomic types it is the primitive type as defined in XML Schema, except that integer, xs:dayTimeDuration, and xs:yearMonthDuration are considered to be primitive types.
      Specified by:
      getPrimitiveItemType in interface ItemType
      Specified by:
      getPrimitiveItemType in interface PlainType
      Returns:
      the corresponding primitive type (this is an instance of BuiltInAtomicType in all cases except where this type is xs:error. The class ErrorType does not inherit from BuiltInAtomicType because of multiple inheritance problems).
    • isPlainType

      public boolean isPlainType()
      Determine whether this item type is a plain type (that is, whether it can ONLY match atomic values)
      Specified by:
      isPlainType in interface ItemType
      Returns:
      true if this is ANY_ATOMIC_TYPE or a subtype thereof, or a "plain" union type (that is, unions of atomic types that impose no further restrictions). Return false if this is a union type whose member types are not all known.
    • getPrimitiveType

      public int getPrimitiveType()
      Get the primitive type corresponding to this item type. For item(), this is Type.ITEM. For node(), it is Type.NODE. For specific node kinds, it is the value representing the node kind, for example Type.ELEMENT. For anyAtomicValue it is BuiltInAtomicType.ANY_ATOMIC. For numeric it is Type.NUMBER. For other atomic types it is the primitive type as defined in XML Schema, except that INTEGER is considered to be a primitive type.
      Specified by:
      getPrimitiveType in interface ItemType
      Returns:
      the integer fingerprint of the corresponding primitive type
    • getUType

      public UType getUType()
      Get the corresponding UType. A UType is a union of primitive item types.
      Specified by:
      getUType in interface ItemType
      Returns:
      the smallest UType that subsumes this item type
    • getAtomizedItemType

      public PlainType getAtomizedItemType()
      Get the item type of the atomic values that will be produced when an item of this type is atomized
      Specified by:
      getAtomizedItemType in interface ItemType
      Returns:
      the best available item type of the atomic values that will be produced when an item of this type is atomized, or null if it is known that atomization will throw an error.
    • isAtomizable

      public boolean isAtomizable(TypeHierarchy th)
      Ask whether values of this type are atomizable
      Specified by:
      isAtomizable in interface ItemType
      Parameters:
      th - the type hierarchy cache
      Returns:
      true if some or all instances of this type can be successfully atomized; false if no instances of this type can be atomized
    • getBasicAlphaCode

      public String getBasicAlphaCode()
      Get an alphabetic code representing the type, or at any rate, the nearest built-in type from which this type is derived. The codes are designed so that for any two built-in types A and B, alphaCode(A) is a prefix of alphaCode(B) if and only if A is a supertype of B.
      Specified by:
      getBasicAlphaCode in interface ItemType
      Returns:
      the alphacode for the nearest containing built-in type. For example: for xs:string return "AS", for xs:boolean "AB", for node() "N", for element() "NE", for map(*) "FM", for array(*) "FA".
    • isAtomicType

      public boolean isAtomicType()
      Test whether this Simple Type is an atomic type
      Specified by:
      isAtomicType in interface ItemType
      Specified by:
      isAtomicType in interface SchemaType
      Specified by:
      isAtomicType in interface SimpleType
      Returns:
      true if this is an atomic type
    • isListType

      public boolean isListType()
      Test whether this Simple Type is a list type
      Specified by:
      isListType in interface SimpleType
      Returns:
      true if this is a list type
    • isUnionType

      public boolean isUnionType()
      Test whether this Simple Type is a union type
      Specified by:
      isUnionType in interface SimpleType
      Returns:
      true if this is a union type
    • getBuiltInBaseType

      public SchemaType getBuiltInBaseType()
      Get the built-in type from which this type is derived by restriction
      Specified by:
      getBuiltInBaseType in interface SimpleType
      Returns:
      the built-in type from which this type is derived by restriction. This will not necessarily be a primitive type.
    • getTypedValue

      public AtomicSequence getTypedValue(UnicodeString value, NamespaceResolver resolver, ConversionRules rules) throws ValidationException
      Get the typed value corresponding to a given string value, assuming it is valid against this type
      Specified by:
      getTypedValue in interface SimpleType
      Parameters:
      value - the string value
      resolver - a namespace resolver used to resolve any namespace prefixes appearing in the content of values. Can supply null, in which case any namespace-sensitive content will be rejected.
      rules - the conversion rules from the configuration
      Returns:
      the atomic sequence comprising the typed value. The objects returned by this SequenceIterator will all be of type AtomicValue,
      Throws:
      ValidationException - if the supplied value is not in the lexical space of the data type
    • validateContent

      public ValidationFailure validateContent(UnicodeString value, NamespaceResolver nsResolver, ConversionRules rules)
      Check whether a given input string is valid according to this SimpleType
      Specified by:
      validateContent in interface SimpleType
      Parameters:
      value - the input string to be checked
      nsResolver - a namespace resolver used to resolve namespace prefixes if the type is namespace sensitive. The value supplied may be null; in this case any namespace-sensitive content will throw an UnsupportedOperationException.
      rules - the conversion rules from the configuration
      Returns:
      null if validation succeeds; or return a ValidationFailure describing the validation failure if validation fails. Note that the exception is returned rather than being thrown.
      Throws:
      UnsupportedOperationException - if the type is namespace-sensitive and no namespace resolver is supplied
    • isNamespaceSensitive

      public boolean isNamespaceSensitive()
      Test whether this type is namespace sensitive, that is, if a namespace context is needed to translate between the lexical space and the value space. This is true for types derived from, or containing, QNames and NOTATIONs
      Specified by:
      isNamespaceSensitive in interface HyperType
      Returns:
      true if the type is namespace-sensitive, or if the namespace-sensitivity cannot be determined because there are missing schema components. (However, for xs:anyAtomicType, the result returned is false, even though the type allows xs:QName instances.)
    • getWhitespaceAction

      public int getWhitespaceAction()
      Determine how values of this simple type are whitespace-normalized.
      Specified by:
      getWhitespaceAction in interface SimpleType
      Returns:
      one of Whitespace.PRESERVE, Whitespace.COLLAPSE, Whitespace.REPLACE.
    • preprocess

      public UnicodeString preprocess(UnicodeString input) throws ValidationException
      Apply any pre-lexical facets, other than whitespace. At the moment the only such facet is saxon:preprocess
      Specified by:
      preprocess in interface SimpleType
      Parameters:
      input - the value to be preprocessed
      Returns:
      the value after preprocessing
      Throws:
      ValidationException - if preprocessing detects that the value is invalid
    • postprocess

      public UnicodeString postprocess(UnicodeString input) throws ValidationException
      Reverse any pre-lexical facets, other than whitespace. At the moment the only such facet is saxon:preprocess. This is called when converting a value of this type to a string
      Specified by:
      postprocess in interface SimpleType
      Parameters:
      input - the value to be postprocessed: this is the "ordinary" result of converting the value to a string
      Returns:
      the value after postprocessing
      Throws:
      ValidationException - if postprocessing detects that the value is invalid
    • getName

      public String getName()
      Get the local name of this type
      Specified by:
      getName in interface SchemaType
      Returns:
      the local name of this type definition, if it has one. Return null in the case of an anonymous type.
    • getTargetNamespace

      public NamespaceUri getTargetNamespace()
      Get the target namespace of this type
      Specified by:
      getTargetNamespace in interface SchemaType
      Returns:
      the target namespace of this type definition, if it has one. Return null in the case of an anonymous type, and in the case of a global type defined in a no-namespace schema.
    • getFingerprint

      public int getFingerprint()
      Get the fingerprint of the name of this type
      Specified by:
      getFingerprint in interface SchemaType
      Returns:
      the fingerprint. Returns an invented fingerprint for an anonymous type.
    • getDisplayName

      public String getDisplayName()
      Get the display name of the type: that is, a lexical QName with an arbitrary prefix
      Specified by:
      getDisplayName in interface SchemaType
      Returns:
      a lexical QName identifying the type. In the case of an anonymous type, an internally-generated name is returned
    • getStructuredQName

      public StructuredQName getStructuredQName()
      Get the name of the type as a StructuredQName
      Specified by:
      getStructuredQName in interface SchemaType
      Returns:
      a StructuredQName identifying the type. In the case of an anonymous type, an internally-generated name is returned
    • getEQName

      public String getEQName()
      Get the name of this type as an EQName, that is, a string in the format Q{uri}local.
      Specified by:
      getEQName in interface SchemaType
      Returns:
      an EQName identifying the type. In the case of an anonymous type, an internally-generated name is returned
    • isComplexType

      public boolean isComplexType()
      Test whether this SchemaType is a complex type
      Specified by:
      isComplexType in interface SchemaType
      Returns:
      true if this SchemaType is a complex type
    • isSimpleType

      public boolean isSimpleType()
      Test whether this SchemaType is a simple type
      Specified by:
      isSimpleType in interface SchemaType
      Returns:
      true if this SchemaType is a simple type
    • isAnonymousType

      public boolean isAnonymousType()
      Test whether this is an anonymous type
      Specified by:
      isAnonymousType in interface SchemaType
      Returns:
      true if this SchemaType is an anonymous type
    • getBlock

      public int getBlock()
      Returns the value of the 'block' attribute for this type, as a bit-significant integer with fields such as Derivation.DERIVATION_LIST and Derivation.DERIVATION_EXTENSION. This corresponds to the property "prohibited substitutions" in the schema component model.
      Specified by:
      getBlock in interface SchemaType
      Returns:
      the value of the 'block' attribute for this type
    • getBaseType

      public SchemaType getBaseType()
      Returns the base type that this type inherits from. This method can be used to get the base type of a type that is known to be valid. If this type is a Simpletype that is a built in primitive type then null is returned.
      Specified by:
      getBaseType in interface SchemaType
      Returns:
      the base type, or null if this is xs:anyType (the root of the type hierarchy)
    • getDerivationMethod

      public int getDerivationMethod()
      Gets the integer code of the derivation method used to derive this type from its parent. Returns zero for primitive types.
      Specified by:
      getDerivationMethod in interface SchemaType
      Returns:
      a numeric code representing the derivation method, for example Derivation.DERIVATION_RESTRICTION
    • getFinalProhibitions

      public int getFinalProhibitions()
      Get the types of derivation that are not permitted, by virtue of the "final" property.
      Specified by:
      getFinalProhibitions in interface SchemaType
      Returns:
      the types of derivation that are not permitted, as a bit-significant integer containing bits such as Derivation.DERIVATION_EXTENSION
    • allowsDerivation

      public boolean allowsDerivation(int derivation)
      Determines whether derivation (of a particular kind) from this type is allowed, based on the "final" property
      Specified by:
      allowsDerivation in interface SchemaType
      Parameters:
      derivation - the kind of derivation, for example Derivation.DERIVATION_LIST
      Returns:
      true if this kind of derivation is allowed
    • analyzeContentExpression

      public void analyzeContentExpression(Expression expression, int kind) throws XPathException
      Analyze an XPath expression to see whether the expression is capable of delivering a value of this type. This method is called during static analysis of a query or stylesheet to give compile-time warnings when "impossible" paths are used.
      Specified by:
      analyzeContentExpression in interface SchemaType
      Parameters:
      expression - the expression that delivers the content
      kind - the node kind whose content is being delivered: Type.ELEMENT, Type.ATTRIBUTE, or Type.DOCUMENT
      Throws:
      XPathException - if the expression will never deliver a value of the correct type
    • atomize

      public AtomicSequence atomize(NodeInfo node) throws XPathException
      Get the typed value of a node that is annotated with this schema type.
      Specified by:
      atomize in interface SchemaType
      Parameters:
      node - the node whose typed value is required
      Returns:
      the typed value.
      Throws:
      XPathException - if the node cannot be atomized, for example if this is a complex type with element-only content
      Since:
      8.5. Changed in 9.5 to return the new type AtomicSequence
    • isSameType

      public boolean isSameType(SchemaType other)
      Test whether this is the same type as another type. They are considered to be the same type if they are derived from the same type definition in the original XML representation (which can happen when there are multiple includes of the same file)
      Specified by:
      isSameType in interface SchemaType
      Parameters:
      other - the other type
      Returns:
      true if this is the same type as other
    • getDescription

      public String getDescription()
      Get a description of this type for use in error messages. This is the same as the display name in the case of named types; for anonymous types it identifies the type by its position in a source schema document.
      Specified by:
      getDescription in interface SchemaType
      Returns:
      text identifing the type, for use in a phrase such as "the type XXXX".
    • toString

      public String toString()
      Produce a string representation of the type name. If the type is anonymous, an internally-allocated type name will be returned.
      Overrides:
      toString in class Object
      Returns:
      the name of the atomic type in the form Q{uri}local
    • checkTypeDerivationIsOK

      public void checkTypeDerivationIsOK(SchemaType base, int block) throws SchemaException
      Check that this type is validly derived from a given type, following the rules for the Schema Component Constraint "Is Type Derivation OK (Simple)" (3.14.6) or "Is Type Derivation OK (Complex)" (3.4.6) as appropriate.
      Specified by:
      checkTypeDerivationIsOK in interface SchemaType
      Parameters:
      base - the base type; the algorithm tests whether derivation from this type is permitted
      block - the derivations that are blocked by the relevant element declaration
      Throws:
      SchemaException - if the derivation is not allowed
    • getSystemId

      public String getSystemId()
      Get the URI of the schema document where the type was originally defined.
      Specified by:
      getSystemId in interface SchemaType
      Returns:
      the URI of the schema document. Returns null if the information is unknown or if this is a built-in type
    • getValidationStatus

      public SchemaValidationStatus getValidationStatus()
      Get the validation status of this component.
      Specified by:
      getValidationStatus in interface SchemaComponent
      Returns:
      one of the values SchemaValidationStatus.UNVALIDATED, SchemaValidationStatus.VALIDATING, SchemaValidationStatus.VALIDATED, SchemaValidationStatus.INVALID, SchemaValidationStatus.INCOMPLETE
    • getRedefinitionLevel

      public int getRedefinitionLevel()
      Get the redefinition level. This is zero for a component that has not been redefined; for a redefinition of a level-0 component, it is 1; for a redefinition of a level-N component, it is N+1. This concept is used to support the notion of "pervasive" redefinition: if a component is redefined at several levels, the top level wins, but it is an error to have two versions of the component at the same redefinition level.
      Specified by:
      getRedefinitionLevel in interface SchemaComponent
      Returns:
      the redefinition level
    • getComponentAsFunction

      public FunctionItem getComponentAsFunction()
      Get the schema component in the form of a function item. This allows schema information to be made visible to XSLT or XQuery code. The function makes available the contents of the schema component as defined in the XSD specification. The function takes a string as argument representing a property name, and returns the corresponding property of the schema component. There is also a property "class" which returns the kind of schema component, for example "Attribute Declaration".
      Specified by:
      getComponentAsFunction in interface SchemaComponent
      Returns:
      the schema component represented as a function from property names to property values.