com.saxonica.schema
Class UserSimpleType

java.lang.Object
  extended by com.saxonica.schema.SchemaStructure
      extended by com.saxonica.schema.UserDefinedType
          extended by com.saxonica.schema.UserSimpleType
All Implemented Interfaces:
SerializableSchemaComponent, UserSchemaComponent, Serializable, SourceLocator, SchemaComponent, SchemaType, SimpleType
Direct Known Subclasses:
SimpleTypeDefinition, UserAtomicType, UserListType, UserUnionType

public abstract class UserSimpleType
extends UserDefinedType
implements SimpleType, UserSchemaComponent, SerializableSchemaComponent

This class represents a used-defined simple type, as defined in the XML Schema specification. This may be an atomic type, a list type, or a union type. In the non-schema-aware version of Saxon, a simple type will always be a built-in type. With the schema-aware product, it may also be a user-defined simple type.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.saxonica.schema.UserDefinedType
extendedTypes, finalProhibitions
 
Fields inherited from interface net.sf.saxon.type.SimpleType
VARIETY_ATOMIC, VARIETY_LIST, VARIETY_UNION, VARIETY_UNSPECIFIED_SIMPLE
 
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
FIXED_UP, INCOMPLETE, INVALID, UNVALIDATED, VALIDATED, VALIDATING
 
Constructor Summary
UserSimpleType()
          Construct a UserSimpleType
 
Method Summary
 void addFacet(Facet facet)
          Add the given Facet to this Simpletype.
protected  List<Facet> addInheritedFacets(List<Facet> localFacets)
           
 void analyzeContentExpression(Expression expression, int kind, StaticContext env)
          Analyze an expression to see whether the expression is capable of delivering a value of this type.
 CharSequence applyWhitespaceNormalization(CharSequence value)
          Apply the whitespace normalization rules for this simple type
 Value atomize(NodeInfo node)
          Get the typed value of a node that is annotated with this schema type.
 ValidationFailure checkAgainstFacets(Value primitiveValue, CharSequence lexicalValue, Iterator iter)
          Validate that the value conforms to all the constraining facets for the given type.
 void checkTypeDerivationIsOK(SchemaType type, int block)
          Check that this type is validly derived from a given type
 void convertFacetValues()
          Convert the values of facets to the target data type
 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.
 SchemaType getBuiltInBaseType()
          Returns the built-in base type this type is derived from.
 List<Facet> getExtendedFacetList()
          Get the extended facet list, creating it if necessary.
 Facet getFacet(Class name)
          Returns the first facet associated with the given name, defined either on this type or on a type from which it is derived
 Iterator<Facet> getFacets()
          Returns an Iterator over all the Facets (including inherited facets) for this type.
 List getLocalFacetList()
          Return all the facets for this type
 SequenceIterator getTypedValue(NodeInfo node)
          Get the typed value of a node that is annotated with this schema type
 int getWhitespaceAction(TypeHierarchy th)
          Determine the whitespace normalization required for values of this type
 boolean isAtomicType()
          Test whether this Simple Type is an atomic 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()
          Returns true if this type is derived by list, or if it is derived by restriction from a list type, or if it is a union that contains a list as one of its members
 boolean isSimpleType()
          Returns true if this SchemaType is a SimpleType
static String isTypeDerivationOK(SimpleType d, SchemaType b, int derivation)
          Check whether type derivation is allowed.
 boolean isUnionType()
          Return true if this type is a union type (that is, if its variety is union), which will be true if is derived by union, or if it is derived by restriction from a type whose variety is union.
 void mergeEnumerationFacets(SchemaCompiler compiler)
          Merge enumeration facets into a single enumerationSet pseudo-facet.
 CharSequence postprocess(CharSequence input)
          Reverse any pre-lexical facets, other than whitespace.
 CharSequence preprocess(CharSequence input)
          Apply any pre-lexical facets, other than whitespace.
 void serialize(SchemaModelSerializer serializer)
          Serialize the schema component
protected abstract  void serializeVariety(SchemaModelSerializer serializer)
           
 void setFacetList(List facetList)
          Set the local facet list for this simple type
 boolean validate(SchemaCompiler compiler)
          Checks the validity of this SimpleType definition.
 
Methods inherited from class com.saxonica.schema.UserDefinedType
allowsDerivation, containingDeclarationIsElement, getBaseType, getBaseTypeFingerprint, getBaseTypeReference, getBlock, getContainingDeclarationName, getDerivationMethod, getDescription, getDisplayName, getFingerprint, getLocalName, getName, getNameCode, getNamePool, getTargetNamespace, hasRegisteredExtension, isAnonymousType, isComplexType, isExternalType, isSameType, iterateExtensionTypes, registerExtensionType, setBaseTypeReference, setContainingDeclaration, setDerivationMethod, setDerivationMethodName, setExtendedTypes, setFinalProhibitions, setNameCode
 
Methods inherited from class com.saxonica.schema.SchemaStructure
fixup, getColumnNumber, getConfiguration, getFixupStatus, getLineNumber, getPublicId, getRedefinitionLevel, getSystemId, getValidationStatus, lookForCycles, setConfiguration, setFixupStatus, setLineNumber, setLocator, setRedefinitionLevel, setSystemId, setValidationStatus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.saxon.type.SimpleType
getCommonAtomicType, getTypedValue, isBuiltInType, isExternalType, isNamespaceSensitive, validateContent
 
Methods inherited from interface net.sf.saxon.type.SchemaType
allowsDerivation, getBaseType, getBlock, getDerivationMethod, getDescription, getDisplayName, getFingerprint, getName, getNameCode, getSystemId, getTargetNamespace, isAnonymousType, isComplexType, isSameType
 
Methods inherited from interface net.sf.saxon.type.SchemaComponent
getRedefinitionLevel, getValidationStatus
 
Methods inherited from interface com.saxonica.schema.UserSchemaComponent
fixup, lookForCycles
 

Constructor Detail

UserSimpleType

public UserSimpleType()
Construct a UserSimpleType

Method Detail

isSimpleType

public final boolean isSimpleType()
Returns true if this SchemaType is a SimpleType

Specified by:
isSimpleType in interface SchemaType
Returns:
true (always)

isAtomicType

public boolean isAtomicType()
Test whether this Simple Type is an atomic type

Specified by:
isAtomicType in interface SchemaType
Specified by:
isAtomicType in interface SimpleType
Returns:
the default implementation returns false

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 SchemaType

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

isListType

public boolean isListType()
Returns true if this type is derived by list, or if it is derived by restriction from a list type, or if it is a union that contains a list as one of its members

Specified by:
isListType in interface SimpleType
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), which will be true if is derived by union, or if it is derived by restriction from a type whose variety is union.

Specified by:
isUnionType in interface SimpleType
Returns:
true for a union type

getExtendedFacetList

public List<Facet> getExtendedFacetList()
Get the extended facet list, creating it if necessary. The extended facet list includes facets inherited from supertypes, unless they are redundant

Returns:
the extended facet list

addInheritedFacets

protected List<Facet> addInheritedFacets(List<Facet> localFacets)

addFacet

public void addFacet(Facet facet)
Add the given Facet to this Simpletype.

Parameters:
facet - the Facet to add to this Simpletype

mergeEnumerationFacets

public void mergeEnumerationFacets(SchemaCompiler compiler)
                            throws SchemaException,
                                   UnresolvedReferenceException
Merge enumeration facets into a single enumerationSet pseudo-facet. This method also merges multiple pattern facets into a single pattern facet with multiple branches.

Parameters:
compiler - used for error reporting
Throws:
SchemaException
UnresolvedReferenceException

getFacet

public Facet getFacet(Class name)
Returns the first facet associated with the given name, defined either on this type or on a type from which it is derived

Parameters:
name - the required class of facet
Returns:
the first facet associated with the given name

setFacetList

public void setFacetList(List facetList)
Set the local facet list for this simple type

Parameters:
facetList - the list of facets

convertFacetValues

public void convertFacetValues()
                        throws SchemaException
Convert the values of facets to the target data type

Throws:
SchemaException

getFacets

public Iterator<Facet> getFacets()
Returns an Iterator over all the Facets (including inherited facets) for this type.

Returns:
an Iterator over all the Facets for this type. The objects returned by the iterator will be instanceof of Facet

getWhitespaceAction

public int getWhitespaceAction(TypeHierarchy th)
Determine the whitespace normalization required for values of this type

Specified by:
getWhitespaceAction in interface SimpleType
Parameters:
th - type hierarchy cache
Returns:
one of PRESERVE, REPLACE, COLLAPSE
Throws:
IllegalStateException - if the simple type is not fully validated and the whitespace facet is not yet known.

applyWhitespaceNormalization

public CharSequence applyWhitespaceNormalization(CharSequence value)
Apply the whitespace normalization rules for this simple type

Parameters:
value - the string before whitespace normalization
Returns:
the string after whitespace normalization

getBuiltInBaseType

public SchemaType getBuiltInBaseType()
Returns the built-in base type this type is derived from.

Specified by:
getBuiltInBaseType in interface SimpleType
Returns:
the first built-in type found when searching up the type hierarchy

checkTypeDerivationIsOK

public void checkTypeDerivationIsOK(SchemaType type,
                                    int block)
                             throws SchemaException
Check that this type is validly derived from a given type

Specified by:
checkTypeDerivationIsOK in interface SchemaType
Overrides:
checkTypeDerivationIsOK in class UserDefinedType
Parameters:
type - the type from which this type is derived
block - the derivations that are blocked by the relevant element declaration
Throws:
SchemaException - if the derivation is not allowed

validate

public boolean validate(SchemaCompiler compiler)
                 throws SchemaException,
                        UnresolvedReferenceException
Checks the validity of this SimpleType definition.

Specified by:
validate in interface UserSchemaComponent
Parameters:
compiler - used for error reporting
Returns:
true when this Schema definition is valid, otherwise false.
Throws:
SchemaException - if this SimpleType definition is invalid.
UnresolvedReferenceException

analyzeContentExpression

public void analyzeContentExpression(Expression expression,
                                     int kind,
                                     StaticContext env)
                              throws XPathException
Analyze an expression to see whether the expression is capable of delivering a value of this type.

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
env - the static context
Throws:
XPathException - if the expression will never deliver a value of the correct type

getTypedValue

public final SequenceIterator getTypedValue(NodeInfo node)
                                     throws XPathException
Get the typed value of a node that is annotated with this schema type

Specified by:
getTypedValue in interface SchemaType
Parameters:
node - the node whose typed value is required
Returns:
an iterator over the items making up the typed value of this node. The objects returned by this SequenceIterator will all be of type AtomicValue
Throws:
XPathException

atomize

public Value atomize(NodeInfo node)
              throws XPathException
Get the typed value of a node that is annotated with this schema type. The result of this method will always be consistent with the method getTypedValue(net.sf.saxon.om.NodeInfo). However, this method is often more convenient and may be more efficient, especially in the common case where the value is expected to be a singleton.

Specified by:
atomize in interface SchemaType
Parameters:
node - the node whose typed value is required
Returns:
the typed value.
Throws:
XPathException
Since:
8.5

isTypeDerivationOK

public static String isTypeDerivationOK(SimpleType d,
                                        SchemaType b,
                                        int derivation)
Check whether type derivation is allowed. This implements the Schema Component Constraint: Type Derivation OK (Simple). This type is D (the derived type); the type supplied as an argument is B (the base type), and the argument (a subset (extension, restriction, list, union)) is provided in the second argument. If type derivation is allowed, the method return null; otherwise it returns a string that can be used as an error message

Parameters:
d - the derived type
b - the base type
derivation - the disallowed derivations, as a bit-significant integer
Returns:
null if type derivation is OK; otherwise a string that can be used as an error message

getLocalFacetList

public List getLocalFacetList()
Return all the facets for this type

Returns:
the list of facets defined on this simple type (this doesn't include inherited facets)

preprocess

public CharSequence preprocess(CharSequence 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

postprocess

public CharSequence postprocess(CharSequence 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

checkAgainstFacets

public ValidationFailure checkAgainstFacets(Value primitiveValue,
                                            CharSequence lexicalValue,
                                            Iterator iter)
Validate that the value conforms to all the constraining facets for the given type.

Parameters:
primitiveValue - the typed value to be checked, as an instance of its primitive type
lexicalValue - The supplied value; this must be normalized using the whitespace facet, and then checked against the pattern facet. May be null; if so the actual value is converted to a string for checking against the pattern.
iter - Iterator over the facets to be checked: can be obtained using one of the various getFacets() methods.
Returns:
null if the value is OK, otherwise a ValidationFailure. Note that the exception is returned rather than being thrown. This is designed to make the "castable" operator more efficient.

elaborate

public void elaborate(SchemaCompiler compiler)
               throws SchemaException
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 SchemaStructure
Parameters:
compiler -
Throws:
SchemaException

serialize

public void serialize(SchemaModelSerializer serializer)
               throws XPathException
Serialize the schema component

Specified by:
serialize in interface SerializableSchemaComponent
Throws:
XPathException

serializeVariety

protected abstract void serializeVariety(SchemaModelSerializer serializer)
                                  throws XPathException
Throws:
XPathException


Copyright (c) Saxonica Limited. All rights reserved.