Package net.sf.saxon.ma.map
Class RecordType
java.lang.Object
net.sf.saxon.ma.map.RecordType
- All Implemented Interfaces:
FunctionItemType,ItemType
An instance of this class represents a specific record item type, for example
record(x as xs:double, y as element(employee)).
Record types are a proposed extension for XPath 4.0. They were previously introduced
as a Saxon extension in Saxon 9.8, under the name "tuple types". The syntax for constructing
a record type requires Saxon-PE or higher, but the supporting code is included in
Saxon-HE for convenience.
Extended in 10.0 to distinguish extensible vs non-extensible record types. Extensible record
types permit fields other than those listed to appear; non-extensible record types do not.
An extensible record type is denoted by record(... ,*).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClass representing one field definition within a record type definition, used only while constructing a record definition -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a dummy RecordTest, details to be supplied laterRecordType(List<String> names, List<SequenceType> types, Collection<String> optionalFieldNames, boolean extensible) Construct a RecordTestRecordType(List<String> names, List<SequenceType> types, Collection<String> optionalFieldNames, boolean extensible, StructuredQName name) Construct a named RecordTestRecordType(StructuredQName name) Construct a named RecordTest, details to be supplied later -
Method Summary
Modifier and TypeMethodDescriptionbooleanTest whether this function type equals another function typeexplainMismatch(Item item, TypeHierarchy th) Get extra diagnostic information about why a supplied item does not conform to this item type, if available.static RecordTypeextensible(RecordType.Field... fields) Make an extensible record typeGet the list of Annotation Assertions associated with this function item typeGet the argument types of this map, viewed as a functionintgetArity()Get the arity (number of arguments) of this function typeGet the item type of the aXPtomic values that will be produced when an item of this type is atomizedGet an alphabetic code representing the type, or at any rate, the nearest built-in type from which this type is derived.getCoercionPlan(int version) Get the coercion plan for use when this type is the required type for (say) coercion of arguments in a function calldoubleGet the default priority when this ItemType is used as an XSLT patternGet the names of all the fieldsgetFieldType(String field) Get the type of a given fieldgetGenre()Determine the Genre (top-level classification) of this typegetName()Get the name of the record type, if it has oneGet the primitive item type corresponding to this item type.intGet the primitive type corresponding to this item type.Get the result type of this record type, viewed as a functionintgetSize()Get the number of declared fieldsgetUType()Get the correspondingUType.inthashCode()Returns a hash code value for the object.booleanAsk whether this function item type is an array type.booleanDetermine whether this item type is an atomic typebooleanAsk whether values of this type are atomizablebooleanAsk whether the record type is extensible, that is, whether fields other than those named are permittedbooleanAsk whether this function item type is a map type.booleanisOptionalField(String field) Ask whether a given field is optionalbooleanDetermine whether this item type is a plain type (that is, whether it can ONLY match atomic values)makeFunctionSequenceCoercer(Expression exp, Supplier<RoleDiagnostic> role, boolean allow40) Create an expression whose effect is to apply function coercion to coerce a function to this function typebooleanTest whether a given item conforms to this typestatic RecordTypenonExtensible(RecordType.Field... fields) Make a non-extensible record typeNormalize this item type, returning a potentially different item type that matches the same items.relationship(FunctionItemType other) Determine the relationship of one function item type to anothervoidsetDetails(boolean extensible, RecordType.Field... fields) Supply the details of the RecordTest.voidsetDetails(List<String> names, List<SequenceType> types, Collection<String> optionalFieldNames, boolean extensible) Supply the details of the RecordTest.Return a string representation of this ItemType suitable for use in stylesheet export files.toString()Produce a representation of this type name for use in error messages.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface net.sf.saxon.type.ItemType
asChoiceItemType, getNormalizedDefaultPriority
-
Field Details
-
VALUE_RECORD
-
KEY_VALUE_RECORD
-
SCHEMA_TYPE_RECORD
-
-
Constructor Details
-
RecordType
public RecordType()Construct a dummy RecordTest, details to be supplied later -
RecordType
Construct a named RecordTest, details to be supplied later -
RecordType
public RecordType(List<String> names, List<SequenceType> types, Collection<String> optionalFieldNames, boolean extensible) Construct a RecordTest- Parameters:
names- the names of the fieldstypes- the types of the fieldsoptionalFieldNames- a list of the names of the fields that are declared optionalextensible- indicates whether the RecordTest is extensible (allows fields other than those declared)
-
RecordType
public RecordType(List<String> names, List<SequenceType> types, Collection<String> optionalFieldNames, boolean extensible, StructuredQName name) Construct a named RecordTest- Parameters:
names- the names of the fieldstypes- the types of the fieldsoptionalFieldNames- a list of the names of the fields that are declared optionalextensible- indicates whether the RecordTest is extensible (allows fields other than those declared)name- the name of the record type
-
-
Method Details
-
extensible
Make an extensible record type- Parameters:
fields- the fields of the record type- Returns:
- the record type
-
nonExtensible
Make a non-extensible record type- Parameters:
fields- the fields of the record type- Returns:
- the record type
-
setDetails
Supply the details of the RecordTest. This method is only to be used during initialisation, it is needed so that a RecordTest can refer to itself. Apart from this, the RecordTest is immutable. -
setDetails
public void setDetails(List<String> names, List<SequenceType> types, Collection<String> optionalFieldNames, boolean extensible) Supply the details of the RecordTest. This method is only to be used during initialisation, it is needed so that a RecordTest can refer to itself. Apart from this, the RecordTest is immutable.- Parameters:
names- the names of the fieldstypes- the types of the fieldsoptionalFieldNames- a list of the names of the fields that are declared optionalextensible- indicates whether the RecordTest is extensible (allows fields other than those declared)
-
getGenre
Determine the Genre (top-level classification) of this type- Specified by:
getGenrein interfaceFunctionItemType- Specified by:
getGenrein interfaceItemType- Returns:
- the Genre to which this type belongs, specifically
Genre.MAP
-
isMapType
public boolean isMapType()Ask whether this function item type is a map type. In this case function coercion (to the map type) will never succeed.- Specified by:
isMapTypein interfaceFunctionItemType- Returns:
- true if this FunctionItemType is a map type
-
isArrayType
public boolean isArrayType()Ask whether this function item type is an array type. In this case function coercion (to the array type) will never succeed.- Specified by:
isArrayTypein interfaceFunctionItemType- Returns:
- true if this FunctionItemType is an array type
-
getName
Get the name of the record type, if it has one- Returns:
- the name of the record type, or null if it has no name
-
getFieldNames
Get the names of all the fields- Returns:
- the names of the fields (in retained order)
-
getSize
public int getSize()Get the number of declared fields- Returns:
- the number of declared fields
-
getFieldType
Get the type of a given field- Parameters:
field- the name of the field- Returns:
- the type of the field if it is defined, or null otherwise
-
isOptionalField
Ask whether a given field is optional- Parameters:
field- the name of the field- Returns:
- true if the field is defined as an optional field
-
isExtensible
public boolean isExtensible()Ask whether the record type is extensible, that is, whether fields other than those named are permitted- Returns:
- true if fields other than the named fields are permitted to appear
-
matches
Test whether a given item conforms to this type -
getArity
public int getArity()Get the arity (number of arguments) of this function type- Returns:
- the number of argument types in the function signature
-
getArgumentTypes
Get the argument types of this map, viewed as a function- Specified by:
getArgumentTypesin interfaceFunctionItemType- Returns:
- the list of argument types of this map, viewed as a function
-
getResultType
Get the result type of this record type, viewed as a function- Specified by:
getResultTypein interfaceFunctionItemType- Returns:
- the result type of this record type, viewed as a function
-
getDefaultPriority
public double getDefaultPriority()Get the default priority when this ItemType is used as an XSLT pattern- Specified by:
getDefaultPriorityin interfaceItemType- Returns:
- the default priority
-
toString
Produce a representation of this type name for use in error messages. -
toExportString
Return a string representation of this ItemType suitable for use in stylesheet export files. This differs from the result of toString() in that it will not contain any references to anonymous types. Note that it may also use the Saxon extended syntax for union types and record types.- Specified by:
toExportStringin interfaceItemType- Returns:
- the string representation as an instance of the XPath ItemType construct
-
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:
getBasicAlphaCodein interfaceItemType- Returns:
- the alphacode for the nearest containing built-in type
-
equals
Test whether this function type equals another function type -
normalizeItemType
Description copied from interface:ItemTypeNormalize this item type, returning a potentially different item type that matches the same items. For example,record(*)andmap(*)match the same items. The default implementation returns the item type unchanged. This method does NOT expand item types to an equivalent choice item type.Item types should be normalized before comparison using equals().
- Specified by:
normalizeItemTypein interfaceItemType- Returns:
- the normalized item type.
-
hashCode
public int hashCode()Returns a hash code value for the object. -
relationship
Determine the relationship of one function item type to another- Specified by:
relationshipin interfaceFunctionItemType- Parameters:
other- the other function item type- Returns:
- for example
Affinity.SUBSUMES,Affinity.SAME_TYPE
-
explainMismatch
Get extra diagnostic information about why a supplied item does not conform to this item type, if available. If extra information is returned, it should be in the form of a complete sentence, minus the closing full stop. No information should be returned for obvious cases.- Specified by:
explainMismatchin interfaceItemType- Parameters:
item- the item being matchedth- the type hierarchy cache- Returns:
- optionally, a message explaining why the item does not match the type
-
makeFunctionSequenceCoercer
public Expression makeFunctionSequenceCoercer(Expression exp, Supplier<RoleDiagnostic> role, boolean allow40) throws XPathException Description copied from interface:FunctionItemTypeCreate an expression whose effect is to apply function coercion to coerce a function to this function type- Specified by:
makeFunctionSequenceCoercerin interfaceFunctionItemType- Parameters:
exp- the expression that delivers the supplied sequence of function items (the ones in need of coercion)role- information for use in diagnosticsallow40- true if 4.0 coercions are allowed, such as reducing the arity of the function- Returns:
- the coerced function, a function that calls the original function after checking the parameters
- Throws:
XPathException- if an error is detected
-
getCoercionPlan
Get the coercion plan for use when this type is the required type for (say) coercion of arguments in a function call- Specified by:
getCoercionPlanin interfaceItemType- Parameters:
version- the XPath language version (40 or 31)
-
getAnnotationAssertions
Get the list of Annotation Assertions associated with this function item type- Specified by:
getAnnotationAssertionsin interfaceFunctionItemType- Returns:
- the list of annotation assertions
-
isAtomicType
public boolean isAtomicType()Determine whether this item type is an atomic type- Specified by:
isAtomicTypein interfaceItemType- Returns:
- true if this is ANY_ATOMIC_TYPE or a subtype thereof
-
isPlainType
public boolean isPlainType()Determine whether this item type is a plain type (that is, whether it can ONLY match atomic values)- Specified by:
isPlainTypein interfaceItemType- 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.
-
getPrimitiveItemType
Get the primitive item 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 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:
getPrimitiveItemTypein interfaceItemType- Returns:
- the corresponding primitive type
-
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:
getPrimitiveTypein interfaceItemType- Returns:
- the integer fingerprint of the corresponding primitive type
-
getUType
Get the correspondingUType. A UType is a union of primitive item types. -
getAtomizedItemType
Get the item type of the aXPtomic values that will be produced when an item of this type is atomized- Specified by:
getAtomizedItemTypein interfaceItemType- 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
Ask whether values of this type are atomizable- Specified by:
isAtomizablein interfaceItemType- 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
-