Package net.sf.saxon.ma.map
Class RecordTest
- java.lang.Object
-
- net.sf.saxon.type.AnyFunctionType
-
- net.sf.saxon.ma.map.RecordTest
-
- All Implemented Interfaces:
TupleType
,FunctionItemType
,ItemType
public class RecordTest extends AnyFunctionType implements TupleType
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(... ,*).
-
-
Field Summary
-
Fields inherited from class net.sf.saxon.type.AnyFunctionType
ANY_FUNCTION
-
-
Constructor Summary
Constructors Constructor Description RecordTest()
Construct a dummy RecordTest, details to be supplied laterRecordTest(java.util.List<java.lang.String> names, java.util.List<SequenceType> types, java.util.Collection<java.lang.String> optionalFieldNames, boolean extensible)
Construct a RecordTest
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object other)
Test whether this function type equals another function typejava.util.Optional<java.lang.String>
explainMismatch(Item item, TypeHierarchy th)
Get extra diagnostic information about why a supplied item does not conform to this item type, if available.SequenceType[]
getArgumentTypes()
Get the argument types of this map, viewed as a functionint
getArity()
Get the arity (number of arguments) of this function typejava.lang.String
getBasicAlphaCode()
Get an alphabetic code representing the type, or at any rate, the nearest built-in type from which this type is derived.double
getDefaultPriority()
Get the default priority when this ItemType is used as an XSLT patternjava.lang.Iterable<java.lang.String>
getFieldNames()
Get the names of all the fieldsSequenceType
getFieldType(java.lang.String field)
Get the type of a given fieldGenre
getGenre()
Determine the Genre (top-level classification) of this typeSequenceType
getResultType()
Get the result type of this record type, viewed as a functionint
hashCode()
Returns a hash code value for the object.boolean
isArrayType()
Ask whether this function item type is an array type.boolean
isExtensible()
Ask whether the record type is extensible, that is, whether fields other than those named are permittedboolean
isMapType()
Ask whether this function item type is a map type.boolean
isOptionalField(java.lang.String field)
Ask whether a given field is optionalExpression
makeFunctionSequenceCoercer(Expression exp, RoleDiagnostic role)
Create an expression whose effect is to apply function coercion to coerce a function from this type to another typeboolean
matches(Item item, TypeHierarchy th)
Test whether a given item conforms to this typeAffinity
relationship(FunctionItemType other, TypeHierarchy th)
Determine the relationship of one function item type to anothervoid
setDetails(java.util.List<java.lang.String> names, java.util.List<SequenceType> types, java.util.Collection<java.lang.String> optionalFieldNames, boolean extensible)
Supply the details of the RecordTest.java.lang.String
toExportString()
Return a string representation of this ItemType suitable for use in stylesheet export files.java.lang.String
toString()
Produce a representation of this type name for use in error messages.-
Methods inherited from class net.sf.saxon.type.AnyFunctionType
getAnnotationAssertions, getAtomizedItemType, getInstance, getPrimitiveItemType, getPrimitiveType, getUType, isAtomicType, isAtomizable, isPlainType
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.type.FunctionItemType
getAnnotationAssertions
-
Methods inherited from interface net.sf.saxon.type.ItemType
getAtomizedItemType, getFullAlphaCode, getNormalizedDefaultPriority, getPrimitiveItemType, getPrimitiveType, getUType, isAtomicType, isAtomizable, isPlainType
-
-
-
-
Constructor Detail
-
RecordTest
public RecordTest()
Construct a dummy RecordTest, details to be supplied later
-
RecordTest
public RecordTest(java.util.List<java.lang.String> names, java.util.List<SequenceType> types, java.util.Collection<java.lang.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)
-
-
Method Detail
-
setDetails
public void setDetails(java.util.List<java.lang.String> names, java.util.List<SequenceType> types, java.util.Collection<java.lang.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
public Genre getGenre()
Determine the Genre (top-level classification) of this type- Specified by:
getGenre
in interfaceFunctionItemType
- Specified by:
getGenre
in 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:
isMapType
in interfaceFunctionItemType
- Overrides:
isMapType
in classAnyFunctionType
- 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:
isArrayType
in interfaceFunctionItemType
- Overrides:
isArrayType
in classAnyFunctionType
- Returns:
- true if this FunctionItemType is an array type
-
getFieldNames
public java.lang.Iterable<java.lang.String> getFieldNames()
Get the names of all the fields- Specified by:
getFieldNames
in interfaceTupleType
- Returns:
- the names of the fields (in arbitrary order)
-
getFieldType
public SequenceType getFieldType(java.lang.String field)
Get the type of a given field- Specified by:
getFieldType
in interfaceTupleType
- Parameters:
field
- the name of the field- Returns:
- the type of the field if it is defined, or null otherwise
-
isOptionalField
public boolean isOptionalField(java.lang.String field)
Ask whether a given field is optional- Specified by:
isOptionalField
in interfaceTupleType
- 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- Specified by:
isExtensible
in interfaceTupleType
- Returns:
- true if fields other than the named fields are permitted to appear
-
matches
public boolean matches(Item item, TypeHierarchy th)
Test whether a given item conforms to this type- Specified by:
matches
in interfaceItemType
- Overrides:
matches
in classAnyFunctionType
- Parameters:
item
- The item to be testedth
- type hierarchy data- Returns:
- true if the item is an instance of this type; false otherwise
-
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
public SequenceType[] getArgumentTypes()
Get the argument types of this map, viewed as a function- Specified by:
getArgumentTypes
in interfaceFunctionItemType
- Overrides:
getArgumentTypes
in classAnyFunctionType
- Returns:
- the list of argument types of this map, viewed as a function
-
getResultType
public SequenceType getResultType()
Get the result type of this record type, viewed as a function- Specified by:
getResultType
in interfaceFunctionItemType
- Overrides:
getResultType
in classAnyFunctionType
- 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:
getDefaultPriority
in interfaceItemType
- Overrides:
getDefaultPriority
in classAnyFunctionType
- Returns:
- the default priority
-
toString
public java.lang.String toString()
Produce a representation of this type name for use in error messages.- Overrides:
toString
in classAnyFunctionType
- Returns:
- a string representation of the type, in notation resembling but not necessarily identical to XPath syntax
-
toExportString
public java.lang.String 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:
toExportString
in interfaceItemType
- Returns:
- the string representation as an instance of the XPath ItemType construct
-
getBasicAlphaCode
public java.lang.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 interfaceItemType
- Overrides:
getBasicAlphaCode
in classAnyFunctionType
- Returns:
- the alphacode for the nearest containing built-in type
-
equals
public boolean equals(java.lang.Object other)
Test whether this function type equals another function type- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
Returns a hash code value for the object.- Overrides:
hashCode
in classjava.lang.Object
-
relationship
public Affinity relationship(FunctionItemType other, TypeHierarchy th)
Determine the relationship of one function item type to another- Specified by:
relationship
in interfaceFunctionItemType
- Overrides:
relationship
in classAnyFunctionType
- Parameters:
other
- the other function item typeth
- the type hierarchy cache- Returns:
- for example
Affinity.SUBSUMES
,Affinity.SAME_TYPE
-
explainMismatch
public java.util.Optional<java.lang.String> explainMismatch(Item item, TypeHierarchy th)
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:
explainMismatch
in 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, RoleDiagnostic role) throws XPathException
Description copied from class:AnyFunctionType
Create an expression whose effect is to apply function coercion to coerce a function from this type to another type- Specified by:
makeFunctionSequenceCoercer
in interfaceFunctionItemType
- Overrides:
makeFunctionSequenceCoercer
in classAnyFunctionType
- Parameters:
exp
- the expression that delivers the supplied sequence of function items (the ones in need of coercion)role
- information for use in diagnostics- Returns:
- the sequence of coerced functions, each on a function that calls the corresponding original function after checking the parameters
- Throws:
XPathException
- if an error is detected
-
-