com.saxonica.schema

## Class UserUnionType

- java.lang.Object
- - com.saxonica.schema.SchemaStructure
  - - com.saxonica.schema.UserDefinedType
    - - com.saxonica.schema.UserSimpleType
      - - com.saxonica.schema.UserUnionType

- All Implemented Interfaces:
    SerializableSchemaComponent, UserSchemaComponent, Serializable, SourceLocator, ItemType, PlainType, SchemaComponent, SchemaType, SimpleType, UnionType

      public class UserUnionType
      extends UserSimpleType
      implements PlainType, UnionType

  A class that represents the XML Schema simple-type with variety union.

  A "plain" union is a union that is not derived by restriction and whose member types are all either atomic types or plain union types. Only plain union types can be named in the XPath SequenceType production. (All union types, however, can act as the target of a cast expression). This class implements the interface `PlainType` despite the fact that not all its instances represent plain unions; to test whether a union is a plain union, use the `isPlainType()` method.

  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from class com.saxonica.schema.UserDefinedType

      `extendedTypes, finalProhibitions`

    - ### Fields inherited from interface net.sf.saxon.type.SchemaType

      `DERIVATION_EXTENSION, DERIVATION_LIST, DERIVATION_RESTRICTION, DERIVATION_UNION, DERIVE_BY_SUBSTITUTION`

    - ### Fields inherited from interface net.sf.saxon.type.SchemaComponent

      `COMPONENT_FUNCTION_TYPE, FIXED_UP, INCOMPLETE, INVALID, UNVALIDATED, VALIDATED, VALIDATING`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `UserUnionType(EnterpriseConfiguration config)` Creates a new Union type.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addMemberTypeReference(TypeReference member)` Add a member type to the list of member types
    `boolean` | `containsListType()` Ask whether this union type includes any list types among its members
    `void` | `elaborate(SchemaCompiler compiler)` Elaborate the schema component: after reloading a serialized schema component model, this expands the component with derived information needed during validation episodes.
    `PlainType` | `getAtomizedItemType()` Get the item type of the atomic values that will be produced when an item of this type is atomized
    `double` | `getDefaultPriority()` Determine the default priority of this item type when used on its own as a Pattern
    `List<TypeReference>` | `getMemberTypeReferences()` Get the list of member types
    `Set<PlainType>` | `getPlainMemberTypes()` Get the list of plain types that are subsumed by this type
    `ItemType` | `getPrimitiveItemType()` Method defined in ItemType: get a primitive supertype in the ItemType type hierarchy
    `int` | `getPrimitiveType()` Method defined in ItemType: get a primitive supertype in the ItemType type hierarchy
    `SequenceType` | `getResultTypeOfCast()` Get the SequenceType that most accurately describes the result of casting a value to this union type
    `ItemType` | `getSuperType(TypeHierarchy th)` Method defined in ItemType: get a supertype in the ItemType type hierarchy
    `AtomicSequence` | `getTypedValue(CharSequence value, NamespaceResolver resolver, ConversionRules rules)` Get the typed value corresponding to a given string value, assuming it is valid against this type
    `boolean` | `isAtomicType()` Ask whether this Simple Type is an atomic type
    `boolean` | `isAtomizable()` Ask whether values of this type are atomizable
    `boolean` | `isBuiltInType()` Determine whether this is a built-in type or a user-defined type
    `boolean` | `isIdRefType()` Ask whether this type is an IDREF or IDREFS type.
    `boolean` | `isIdType()` Ask whether this type is an ID type.
    `boolean` | `isListType()` Determine whether this is a list type
    `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.
    `boolean` | `isPlainType()` Ask whether this Union type is a "plain type", defined as a union type whose member types are all atomic types or plain unions.
    `boolean` | `isUnionType()` Return true if this type is a union type (that is, if its variety is union)
    `void` | `lookForCycles(Stack references, SchemaCompiler compiler)` This method is called to look for cycles.
    `boolean` | `matches(Item item, XPathContext context)` Test whether a given item conforms to this type
    `boolean` | `matchesItem(Item item, boolean allowURIPromotion, Configuration config)` Test whether a given item conforms to this type
    `void` | `serializeVariety(SchemaModelSerializer serializer)` Serialize the schema component
    `void` | `setMemberTypeReferences(List<TypeReference> members)` Set the member types of this union type.
    `String` | `toString()` Produce a string representation of the type name.
    `boolean` | `validate(SchemaCompiler compiler)` Validate this Union, replacing all unresolved forwards references at the same time
    `ValidationFailure` | `validateContent(CharSequence value, NamespaceResolver nsResolver, ConversionRules rules)` Check whether a given input string is valid according to this SimpleType
    `void` | `visitNamedSchemaComponents(SchemaComponentVisitor visitor)` Visit all the schema components used in this ItemType definition

    - ### Methods inherited from class com.saxonica.schema.UserSimpleType

      `addFacet, addInheritedFacets, analyzeContentExpression, applyWhitespaceNormalization, atomize, checkAgainstFacets, checkTypeDerivationIsOK, convertFacetValues, getBuiltInBaseType, getComponentAsFunction, getComponentAsFunction, getContextComponent, getEQName, getExtendedFacetList, getFacet, getLocalFacetList, getWhitespaceAction, isSimpleType, isTypeDerivationOK, mergeEnumerationFacets, postprocess, preprocess, serialize, setContextComponent, setFacetList`

    - ### Methods inherited from class com.saxonica.schema.UserDefinedType

      `allowsDerivation, containingDeclarationIsElement, getBaseType, getBaseTypeFingerprint, getBaseTypeReference, getBlock, getContainingDeclarationName, getDerivationMethod, getDescription, getDisplayName, getExtensionTypes, getFinalProhibitions, getFingerprint, getLocalName, getName, getNameCode, getNamePool, getTargetNamespace, isAnonymousType, isComplexType, isExternalType, isSameType, registerExtensionType, setBaseTypeReference, setContainingDeclaration, setDerivationMethod, setDerivationMethodName, setExtendedTypes, setFinalProhibitions, setNameCode`

    - ### Methods inherited from class com.saxonica.schema.SchemaStructure

      `fixup, getColumnNumber, getConfiguration, getFixupStatus, getLineNumber, getPublicId, getRedefinitionLevel, getSchemaDocumentURI, getSystemId, getValidationStatus, makeXPathExpressionPropertyRecord, setConfiguration, setFixupStatus, setLineNumber, setLocator, setRedefinitionLevel, setSchemaDocumentURI, setSystemId, setValidationStatus`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface net.sf.saxon.type.PlainType

      `isExternalType`

    - ### Methods inherited from interface net.sf.saxon.type.SimpleType

      `getBuiltInBaseType, getWhitespaceAction, isExternalType, postprocess, preprocess`

    - ### Methods inherited from interface net.sf.saxon.type.SchemaType

      `allowsDerivation, analyzeContentExpression, atomize, checkTypeDerivationIsOK, getBaseType, getBlock, getDerivationMethod, getDescription, getDisplayName, getEQName, getFinalProhibitions, getFingerprint, getName, getNameCode, getSystemId, getTargetNamespace, isAnonymousType, isComplexType, isSameType, isSimpleType`

    - ### Methods inherited from interface net.sf.saxon.type.SchemaComponent

      `getComponentAsFunction, getRedefinitionLevel, getValidationStatus`

    - ### Methods inherited from interface com.saxonica.schema.UserSchemaComponent

      `fixup`

- - ### Constructor Detail

    - #### UserUnionType

          public UserUnionType(EnterpriseConfiguration config)

      Creates a new Union type.
      Parameters:
        `config` - the Configuration for this Union (Cannot be null)

  - ### Method Detail

    - #### setMemberTypeReferences

          public void setMemberTypeReferences(List<TypeReference> members)

      Set the member types of this union type.
      Parameters:
        `members` - a list of `TypeReference` objects

    - #### addMemberTypeReference

          public void addMemberTypeReference(TypeReference member)

      Add a member type to the list of member types
      Parameters:
        `member` - a reference to a new member type

    - #### getMemberTypeReferences

          public List<TypeReference> getMemberTypeReferences()

      Get the list of member types
      Returns:
        a List containing `TypeReference` objects

    - #### isAtomicType

          public boolean isAtomicType()

      Ask 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`
      Overrides:
        `isAtomicType` in class `UserSimpleType`
      Returns:
        false, this is not an atomic type

    - #### containsListType

          public boolean containsListType()

      Ask whether this union type includes any list types among its members
      Specified by:
        `containsListType` in interface `UnionType`

    - #### isPlainType

          public boolean isPlainType()

      Ask whether this Union type is a "plain type", defined as a union type whose member types are all atomic types or plain unions. That is, it disallows unions that are derived by restriction from another union. The significance of this is that an atomic value will never match a non-plain union type
      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)

    - #### getResultTypeOfCast

          public SequenceType getResultTypeOfCast()

      Get the SequenceType that most accurately describes the result of casting a value to this union type
      Specified by:
        `getResultTypeOfCast` in interface `UnionType`
      Returns:
        the most precise SequenceType for the result of casting

    - #### 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 in XSD 1.0, its typed value must be a *single* atomic value of type ID; the type of the node, however, can still allow a list or union. This changes in XSD 1.1, where a list of IDs is allowed.
      Specified by:
        `isIdType` in interface `SchemaType`
      Overrides:
        `isIdType` in class `UserSimpleType`
      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 `SchemaType`
      Overrides:
        `isIdRefType` in class `UserSimpleType`
      Returns:
        true if this type is an IDREF type

    - #### isBuiltInType

          public boolean isBuiltInType()

      Determine whether this is a built-in type or a user-defined type
      Specified by:
        `isBuiltInType` in interface `SimpleType`
      Returns:
        true if this is a built-in type

    - #### isListType

          public boolean isListType()

      Determine whether this is a list type
      Specified by:
        `isListType` in interface `SimpleType`
      Overrides:
        `isListType` in class `UserSimpleType`
      Returns:
        true if this is a list type

    - #### isUnionType

          public boolean isUnionType()

      Return true if this type is a union type (that is, if its variety is union)
      Specified by:
        `isUnionType` in interface `SimpleType`
      Overrides:
        `isUnionType` in class `UserSimpleType`
      Returns:
        true for a union type

    - #### 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 `SimpleType`
      Returns:
        true if any of the member types is namespace-sensitive

    - #### validate

          public boolean validate(SchemaCompiler compiler)
                           throws SchemaException

      Validate this Union, replacing all unresolved forwards references at the same time
      Specified by:
        `validate` in interface `UserSchemaComponent`
      Overrides:
        `validate` in class `UserSimpleType`
      Parameters:
        `compiler` - used for error reporting
      Returns:
        true when this Schema definition is valid, otherwise false.
      Throws:
        `SchemaException`

    - #### elaborate

          public void elaborate(SchemaCompiler compiler)
                         throws SchemaException

      Description copied from class: `UserSimpleType`
      Elaborate the schema component: after reloading a serialized schema component model, this expands the component with derived information needed during validation episodes. The model is assumed to be valid.
      Specified by:
        `elaborate` in interface `UserSchemaComponent`
      Overrides:
        `elaborate` in class `UserSimpleType`
      Parameters:
        `compiler` - the schema compiler
      Throws:
        `SchemaException` - if a fatal error occurs

    - #### lookForCycles

          public void lookForCycles(Stack references,
                           SchemaCompiler compiler)
                             throws SchemaException,
                                    UnresolvedReferenceException

      This method is called to look for cycles. The object implementing this method is required (a) to raise an exception if the object itself appears in the list of references, (b) to add itself to the list of references, and (c) to call the lookForCycles method on all the objects that it references.
      Specified by:
        `lookForCycles` in interface `UserSchemaComponent`
      Overrides:
        `lookForCycles` in class `SchemaStructure`
      Parameters:
        `references` - A list of objects that contain direct or indirect references to this object, and that must therefore not be referred to from this object.
        `compiler` - used for error reporting
      Throws:
        `SchemaException`
        `UnresolvedReferenceException`

    - #### validateContent

          public ValidationFailure validateContent(CharSequence 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 configuration-wide conversion rules
      Returns:
        null if validation succeeds; return a ValidationFailure describing the validation failure if validation fails
      Throws:
        `UnsupportedOperationException` - if the type is namespace-sensitive and no namespace resolver is supplied

    - #### getTypedValue

          public AtomicSequence getTypedValue(CharSequence value,
                                     NamespaceResolver resolver,
                                     ConversionRules rules)
                                       throws ValidationException

      Description copied from interface: `SimpleType`
      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:
        an iterator over the atomic sequence comprising the typed value. The objects returned by this SequenceIterator will all be of type `AtomicValue`, The next() method on the iterator throws no checked exceptions, although it is not actually declared as an UnfailingIterator.
      Throws:
        `ValidationException` - if the supplied value is not in the lexical space of the data type

    - #### serializeVariety

          public void serializeVariety(SchemaModelSerializer serializer)
                                throws XPathException

      Serialize the schema component
      Specified by:
        `serializeVariety` in class `UserSimpleType`
      Throws:
        `XPathException`

    - #### matches

          public boolean matches(Item item,
                        XPathContext context)

      Test whether a given item conforms to this type
      Specified by:
        `matches` in interface `ItemType`
      Parameters:
        `item` - The item to be tested
        `context` - the XPath dynamic evaluation context
      Returns:
        true if the item is an instance of this type; false otherwise

    - #### matchesItem

          public boolean matchesItem(Item item,
                            boolean allowURIPromotion,
                            Configuration config)

      Description copied from interface: `ItemType`
      Test whether a given item conforms to this type
      Specified by:
        `matchesItem` in interface `ItemType`
      Parameters:
        `item` - The item to be tested
        `allowURIPromotion` - if a URI value is to be treated as a string
        `config` - the Saxon configuration
      Returns:
        true if the item is an instance of this type; false otherwise

    - #### getSuperType

          public ItemType getSuperType(TypeHierarchy th)

      Method defined in ItemType: get a supertype in the ItemType type hierarchy
      Specified by:
        `getSuperType` in interface `ItemType`
      Parameters:
        `th` - the type hierarchy cache
      Returns:
        BuiltInAtomicType.ANY_ATOMIC

    - #### getPrimitiveItemType

          public ItemType getPrimitiveItemType()

      Method defined in ItemType: get a primitive supertype in the ItemType type hierarchy
      Specified by:
        `getPrimitiveItemType` in interface `ItemType`
      Returns:
        BuiltInAtomicType.ANY_ATOMIC

    - #### getPrimitiveType

          public int getPrimitiveType()

      Method defined in ItemType: get a primitive supertype in the ItemType type hierarchy
      Specified by:
        `getPrimitiveType` in interface `ItemType`
      Returns:
        StandardNames.XS_ANY_ATOMIC_TYPE

    - #### getAtomizedItemType

          public PlainType getAtomizedItemType()

      Description copied from interface: `ItemType`
      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()

      Description copied from interface: `ItemType`
      Ask whether values of this type are atomizable
      Specified by:
        `isAtomizable` in interface `ItemType`
      Returns:
        true unless it is known that these items will be elements with element-only content, or function items, in which case return false

    - #### visitNamedSchemaComponents

          public void visitNamedSchemaComponents(SchemaComponentVisitor visitor)
                                          throws XPathException

      Description copied from interface: `ItemType`
      Visit all the schema components used in this ItemType definition
      Specified by:
        `visitNamedSchemaComponents` in interface `ItemType`
      Parameters:
        `visitor` - the visitor class to be called when each component is visited
      Throws:
        `XPathException` - if an error occurs

    - #### getPlainMemberTypes

          public Set<PlainType> getPlainMemberTypes()

      Get the list of plain types that are subsumed by this type
      Specified by:
        `getPlainMemberTypes` in interface `PlainType`
      Specified by:
        `getPlainMemberTypes` in interface `UnionType`
      Returns:
        for an atomic type, the type itself; for a plain union type, the list of plain types in its transitive membership, in declaration order

    - #### getDefaultPriority

          public double getDefaultPriority()

      Description copied from interface: `ItemType`
      Determine the default priority of this item type when used on its own as a Pattern
      Specified by:
        `getDefaultPriority` in interface `ItemType`
      Returns:
        the default priority

    - #### 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

Copyright (c) 2004-2013 Saxonica Limited. All rights reserved.