Package net.sf.saxon.ma.map
Class TupleItemType
java.lang.Object
net.sf.saxon.type.AnyFunctionType
net.sf.saxon.ma.map.TupleItemType
- All Implemented Interfaces:
TupleType,FunctionItemType,ItemType
An instance of this class represents a specific tuple item type, for example
tuple(x: xs:double, y: element(employee)).
Tuple types are a Saxon extension introduced in Saxon 9.8. The syntax for constructing
a tuple type requires Saxon-PE or higher, but the supporting code is included in
Saxon-HE for convenience.
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.sf.saxon.type.ItemType
ItemType.WithSequenceTypeCache -
Field Summary
Fields inherited from class net.sf.saxon.type.AnyFunctionType
ANY_FUNCTION -
Constructor Summary
ConstructorsConstructorDescriptionTupleItemType(List<String> names, List<SequenceType> types) TupleItemType(List<String> names, List<SequenceType> types, Set<String> optionalFields, boolean extensible) -
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.generateJavaScriptItemTypeTest(ItemType knownToBe, int targetVersion) Generate Javascript code to test whether an item conforms to this item typeGet the argument types of this map, viewed as a functionintgetArity()Get the arity (number of arguments) of this function typeGet the names of all the fieldsgetFieldType(String field) Get the type of a given fieldgetGenre()Determine the Genre (top-level classification) of this typeGet the result type of this tuple type, viewed as a functioninthashCode()Returns a hash code value for the object.booleanAsk whether this function item type is an array type.booleanAsk whether the tuple type is extensible, that is, whether fields other than those named are permittedbooleanAsk whether this function item type is a map type.booleanisOptional(String field) Ask whether a particular field is optional (that is, allowed to be absent from the map)makeFunctionSequenceCoercer(Expression exp, RoleDiagnostic role) Create an expression whose effect is to apply function coercion to coerce a function from this type to another typebooleanmatches(Item item, TypeHierarchy th) Test whether a given item conforms to this typeintrelationship(FunctionItemType other, TypeHierarchy th) Determine the relationship of one function item type to anotherReturn 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 net.sf.saxon.type.AnyFunctionType
generateJavaScriptItemTypeAcceptor, getAlphaCode, getAnnotationAssertions, getAtomizedItemType, getInstance, getPrimitiveItemType, getPrimitiveType, getUType, isAtomicType, isAtomizable, isPlainTypeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface net.sf.saxon.type.FunctionItemType
getAnnotationAssertionsMethods inherited from interface net.sf.saxon.type.ItemType
generateJavaScriptItemTypeAcceptor, getAlphaCode, getAtomizedItemType, getPrimitiveItemType, getPrimitiveType, getUType, isAtomicType, isAtomizable, isPlainType, isTrueItemType
-
Constructor Details
-
TupleItemType
-
TupleItemType
-
-
Method Details
-
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- Overrides:
isMapTypein 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:
isArrayTypein interfaceFunctionItemType- Overrides:
isArrayTypein classAnyFunctionType- Returns:
- true if this FunctionItemType is an array type
-
getFieldNames
Get the names of all the fields- Specified by:
getFieldNamesin interfaceTupleType- Returns:
- the names of the fields (in arbitrary order)
-
getFieldType
Get the type of a given field- Specified by:
getFieldTypein interfaceTupleType- Parameters:
field- the name of the field- Returns:
- the type of the field if it is defined, or null otherwise
-
isOptional
Description copied from interface:TupleTypeAsk whether a particular field is optional (that is, allowed to be absent from the map)- Specified by:
isOptionalin interfaceTupleType- Parameters:
field- the name of the field- Returns:
- true if the field is optional
-
isExtensible
public boolean isExtensible()Ask whether the tuple type is extensible, that is, whether fields other than those named are permitted- Specified by:
isExtensiblein interfaceTupleType- Returns:
- true if fields other than the named fields are permitted to appear
-
matches
Test whether a given item conforms to this type- Specified by:
matchesin interfaceItemType- Overrides:
matchesin classAnyFunctionType- Parameters:
item- The item to be testedth- type hierarchy data- Returns:
- true if the item is an instance of this type; false otherwise
- Throws:
XPathException
-
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- Overrides:
getArgumentTypesin classAnyFunctionType- Returns:
- the list of argument types of this map, viewed as a function
-
getResultType
Get the result type of this tuple type, viewed as a function- Specified by:
getResultTypein interfaceFunctionItemType- Overrides:
getResultTypein classAnyFunctionType- Returns:
- the result type of this tuple type, viewed as a function
-
toString
Produce a representation of this type name for use in error messages.- Specified by:
toStringin interfaceItemType- Overrides:
toStringin classAnyFunctionType- Returns:
- a string representation of the type, in notation resembling but not necessarily identical to XPath syntax
-
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 tuple types.- Specified by:
toExportStringin interfaceItemType- Returns:
- the string representation as an instance of the XPath ItemType construct
-
equals
Test whether this function type equals another function 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- Overrides:
relationshipin classAnyFunctionType- Returns:
- for example
TypeHierarchy.SUBSUMES,TypeHierarchy.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, RoleDiagnostic role) throws XPathException Description copied from class:AnyFunctionTypeCreate an expression whose effect is to apply function coercion to coerce a function from this type to another type- Specified by:
makeFunctionSequenceCoercerin interfaceFunctionItemType- Overrides:
makeFunctionSequenceCoercerin 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
-
generateJavaScriptItemTypeTest
public String generateJavaScriptItemTypeTest(ItemType knownToBe, int targetVersion) throws XPathException Generate Javascript code to test whether an item conforms to this item type- Specified by:
generateJavaScriptItemTypeTestin interfaceItemType- Overrides:
generateJavaScriptItemTypeTestin classAnyFunctionType- Parameters:
knownToBe- a type that this item is known to conform totargetVersion- the target version of Saxon-JS- Returns:
- a Javascript instruction or sequence of instructions, which can be used as the body of a Javascript function, and which returns a boolean indication whether the value of the variable "item" is an instance of this item type.
- Throws:
XPathException- if JS code cannot be generated for this item type, for example because the test is schema-aware.
-