Package com.saxonica.ee.schema
Class UserSimpleType
- java.lang.Object
-
- com.saxonica.ee.schema.SchemaStructure
-
- com.saxonica.ee.schema.UserDefinedType
-
- com.saxonica.ee.schema.UserSimpleType
-
- All Implemented Interfaces:
SerializableSchemaComponent
,UserSchemaComponent
,javax.xml.transform.SourceLocator
,Location
,HyperType
,SchemaComponent
,SchemaType
,SimpleType
,org.xml.sax.Locator
- 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.
-
-
Field Summary
-
Fields inherited from class com.saxonica.ee.schema.UserDefinedType
extendedTypes, finalProhibitions
-
-
Constructor Summary
Constructors Constructor Description UserSimpleType()
Construct a UserSimpleType
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addFacet(Facet facet)
Add the given Facet to this Simpletype.protected java.util.List<Facet>
addInheritedFacets(java.util.List<Facet> localFacets)
void
analyzeContentExpression(Expression expression, int kind)
Analyze an expression to see whether the expression is capable of delivering a value of this type.UnicodeString
applyWhitespaceNormalization(UnicodeString value)
Apply the whitespace normalization rules for this simple typeAtomicSequence
atomize(NodeInfo node)
Get the typed value of a node that is annotated with this schema type.ValidationFailure
checkAgainstFacets(AtomicSequence primitiveValue, UnicodeString lexicalValue, java.util.List<Facet> facets, ConversionRules rules)
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 typevoid
convertFacetValues()
Convert the values of facets to the target data typevoid
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.Function
getComponentAsFunction()
Get the schema component in the form of a function item.static Function
getComponentAsFunction(SimpleType type)
Get schema information for a simple type in the form of a function itemSchemaComponent
getContextComponent()
Get the component that contains the definition of this anonymous simple type definitionjava.lang.String
getEQName()
Get the name of this type as an EQName, that is, a string in the format Q{uri}local.java.util.List<Facet>
getExtendedFacetList()
Get the extended facet list, creating it if necessary.Facet
getFacet(java.lang.Class name)
Returns the first facet associated with the given name, defined either on this type or on a type from which it is derivedjava.util.List<Facet>
getLocalFacetList()
Return all the facets for this typeint
getWhitespaceAction()
Determine the whitespace normalization required for values of this typeboolean
isAtomicType()
Test whether this Simple Type is an atomic typeboolean
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 membersboolean
isSimpleType()
Returns true if this SchemaType is a SimpleTypestatic java.lang.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.static ValidationFailure
makeValidationFailure(AtomicSequence primitiveValue, SimpleType type, Facet f)
void
mergeEnumerationFacets(SchemaCompiler compiler)
Merge enumeration facets into a single enumerationSet pseudo-facet.UnicodeString
postprocess(UnicodeString input)
Reverse any pre-lexical facets, other than whitespace.UnicodeString
preprocess(UnicodeString input)
Apply any pre-lexical facets, other than whitespace.void
serialize(SchemaModelSerializer serializer)
Serialize the schema componentprotected abstract void
serializeVariety(SchemaModelSerializer serializer)
void
setContextComponent(SchemaComponent contextComponent)
Set the component that contains the definition of this anonymous simple type definitionvoid
setFacetList(java.util.List<Facet> facetList)
Set the local facet list for this simple typeboolean
validate(SchemaCompiler compiler)
Checks the validity of this SimpleType definition.-
Methods inherited from class com.saxonica.ee.schema.UserDefinedType
allowsDerivation, containingDeclarationIsElement, getBaseType, getBaseTypeFingerprint, getBaseTypeReference, getBlock, getContainingDeclarationName, getDerivationMethod, getDescription, getDisplayName, getExtensionTypes, getFinalProhibitions, getFingerprint, getName, getNamePool, getStructuredQName, getTargetNamespace, getTypeName, isAnonymousType, isComplexType, isSameType, isSameURI, registerExtensionType, setBaseTypeReference, setContainingDeclaration, setDerivationMethod, setDerivationMethodName, setExtendedTypes, setFinalProhibitions, setTypeName, toString
-
Methods inherited from class com.saxonica.ee.schema.SchemaStructure
fixup, getColumnNumber, getConfiguration, getFixupStatus, getGeneratedId, getLineNumber, getPublicId, getRedefinitionLevel, getSchemaDocumentURI, getSystemId, getValidationStatus, hasSameLocation, isValidationNeeded, lookForCycles, makeXPathExpressionPropertyRecord, saveLocation, setConfiguration, setFixupStatus, setGeneratedId, 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.HyperType
isNamespaceSensitive
-
Methods inherited from interface net.sf.saxon.type.SchemaComponent
getRedefinitionLevel, getValidationStatus
-
Methods inherited from interface net.sf.saxon.type.SchemaType
allowsDerivation, getBaseType, getBlock, getDerivationMethod, getDescription, getDisplayName, getFinalProhibitions, getFingerprint, getName, getStructuredQName, getSystemId, getTargetNamespace, isAnonymousType, isComplexType, isSameType
-
Methods inherited from interface net.sf.saxon.type.SimpleType
getTypedValue, isBuiltInType, validateContent
-
Methods inherited from interface com.saxonica.ee.schema.UserSchemaComponent
fixup, lookForCycles
-
-
-
-
Method Detail
-
isSimpleType
public final boolean isSimpleType()
Returns true if this SchemaType is a SimpleType- Specified by:
isSimpleType
in interfaceSchemaType
- Returns:
- true (always)
-
isAtomicType
public boolean isAtomicType()
Test whether this Simple Type is an atomic type- Specified by:
isAtomicType
in interfaceSchemaType
- Specified by:
isAtomicType
in interfaceSimpleType
- Returns:
- the default implementation returns false
-
isIdType
public boolean isIdType() throws MissingComponentException
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 interfaceSchemaType
- Returns:
- true if this type is an ID type
- Throws:
MissingComponentException
-
isIdRefType
public boolean isIdRefType() throws MissingComponentException
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 interfaceSchemaType
- Returns:
- true if this type is an IDREF type
- Throws:
MissingComponentException
-
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 interfaceSimpleType
- 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 interfaceSimpleType
- Returns:
- true for a union type
-
getContextComponent
public SchemaComponent getContextComponent()
Get the component that contains the definition of this anonymous simple type definition- Returns:
- the containing component, or null of the type is not anonymous
-
setContextComponent
public void setContextComponent(SchemaComponent contextComponent)
Set the component that contains the definition of this anonymous simple type definition- Parameters:
contextComponent
- the containing component, or null of the type is not anonymous
-
getExtendedFacetList
public java.util.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. This includes all constraining facets (but not fundamental facets). It does not include facets from built-in base types.- Returns:
- the extended facet list
-
addInheritedFacets
protected java.util.List<Facet> addInheritedFacets(java.util.List<Facet> localFacets)
-
getEQName
public java.lang.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 interfaceSchemaType
- Overrides:
getEQName
in classUserDefinedType
- Returns:
- an EQName identifying the type. In the case of an anonymous type, an internally-generated name is returned
-
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, MissingComponentException
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
- if a schema validity error is foundMissingComponentException
- if an unresolved reference to a schema component is found
-
getFacet
public Facet getFacet(java.lang.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(java.util.List<Facet> 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
- if conversion fails
-
getWhitespaceAction
public int getWhitespaceAction()
Determine the whitespace normalization required for values of this type- Specified by:
getWhitespaceAction
in interfaceSimpleType
- Returns:
- one of PRESERVE, REPLACE, COLLAPSE
- Throws:
java.lang.IllegalStateException
- if the simple type is not fully validated and the whitespace facet is not yet known.
-
applyWhitespaceNormalization
public UnicodeString applyWhitespaceNormalization(UnicodeString 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 interfaceSimpleType
- 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 interfaceSchemaType
- Overrides:
checkTypeDerivationIsOK
in classUserDefinedType
- Parameters:
type
- the type from which this type is derivedblock
- 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
Checks the validity of this SimpleType definition.- Specified by:
validate
in interfaceUserSchemaComponent
- Overrides:
validate
in classSchemaStructure
- Parameters:
compiler
- used for error reporting- Returns:
- true when this Schema definition is valid, otherwise false.
- Throws:
SchemaException
- if this SimpleType definition is invalid.
-
analyzeContentExpression
public void analyzeContentExpression(Expression expression, int kind) throws XPathException
Analyze an expression to see whether the expression is capable of delivering a value of this type.- Specified by:
analyzeContentExpression
in interfaceSchemaType
- Parameters:
expression
- the expression that delivers the contentkind
- the node kind whose content is being delivered:Type.ELEMENT
,Type.ATTRIBUTE
, orType.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 interfaceSchemaType
- 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
-
isTypeDerivationOK
public static java.lang.String isTypeDerivationOK(SimpleType d, SchemaType b, int derivation) throws MissingComponentException
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 typeb
- the base typederivation
- 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
- Throws:
MissingComponentException
-
getLocalFacetList
public java.util.List<Facet> 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 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 interfaceSimpleType
- 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 interfaceSimpleType
- 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
-
checkAgainstFacets
public ValidationFailure checkAgainstFacets(AtomicSequence primitiveValue, UnicodeString lexicalValue, java.util.List<Facet> facets, ConversionRules rules)
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 typelexicalValue
- 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.facets
- List of the facets to be checked: can be obtained using one of the various getFacets() methods.rules
- Validation context (including values of parameters declared using saxon:param)- 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.
-
makeValidationFailure
public static ValidationFailure makeValidationFailure(AtomicSequence primitiveValue, SimpleType type, Facet f)
-
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 interfaceUserSchemaComponent
- Overrides:
elaborate
in classSchemaStructure
- Parameters:
compiler
- the schema compiler- Throws:
SchemaException
- if a fatal error occurs
-
serialize
public void serialize(SchemaModelSerializer serializer) throws XPathException
Serialize the schema component- Specified by:
serialize
in interfaceSerializableSchemaComponent
- Parameters:
serializer
- the object responsible for performing the serialization- Throws:
XPathException
- if serialization fails
-
serializeVariety
protected abstract void serializeVariety(SchemaModelSerializer serializer) throws XPathException
- Throws:
XPathException
-
getComponentAsFunction
public Function getComponentAsFunction()
Description copied from interface:SchemaComponent
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 interfaceSchemaComponent
- Overrides:
getComponentAsFunction
in classSchemaStructure
- Returns:
- the schema component represented as a function from property names to property values.
-
getComponentAsFunction
public static Function getComponentAsFunction(SimpleType type)
Get schema information for a simple type in the form of a function item- Parameters:
type
- The type whose component information is required- Returns:
- a function item representing a function whose argument is a property name and whose result is the value of that property
-
-