Class ItemTypeFactory
The ItemTypeFactory
class is thread-safe.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionObtain a s9apiItemType
corresponding to an underlying instance ofItemType
getArrayType
(SequenceType memberType) Obtain an array type, that is a type for XDM arrays with a given member typegetAtomicType
(QName name) Get an item type representing an atomic type.getAttributeTest
(QName name, QName schemaType) Get an ItemType that tests an attribute name and/or schema type.getDocumentTest
(ItemType elementTest) Make an ItemType representing a document-node() test with an embedded element test.getElementTest
(QName name, QName schemaType, boolean nillable) Make an ItemType that tests an element name and/or schema type.getExternalObject
(Object object) Factory method to construct an "external object".getExternalObjectType
(Class externalClass) Get an ItemType representing the type of a Java object when used as an external object for use in conjunction with calls on extension/external functions.getFunctionType
(SequenceType returnType, SequenceType... argumentTypes) Obtain a function type, that is a type for XDM functions with given argument types and a given result type.getItemType
(XdmItem item) Get an ItemType representing the type of a supplied XdmItem.getItemType
(XdmNodeKind kind, QName name) Get an item type that matches nodes of a specified kind with a specified name.getMapType
(ItemType keyType, SequenceType valueType) Obtain a map type, that is a type for XDM maps with a given key type and value typegetNodeKindTest
(XdmNodeKind kind) Get an item type that matches any node of a specified kind.getSchemaAttributeTest
(QName name) Get an ItemType representing an attribute declaration in the schema.getSchemaElementTest
(QName name) Make an ItemType representing an element declaration in the schema.Deprecated.parseItemType
(String typeDesignation) Parse an item type in XPath syntax.
-
Constructor Details
-
ItemTypeFactory
Create an ItemTypeFactory- Parameters:
processor
- the processor used by this ItemTypeFactory. This must be supplied in the case of user-defined types or types that reference element or attribute names; for built-in types it can be omitted.
-
-
Method Details
-
parseItemType
Parse an item type in XPath syntax.XPath 4.0 experimental extensions such as union types and record types are enabled if the processor option
Feature.XQUERY_VERSION
is set to "4.0".- Parameters:
typeDesignation
- the lexical representation of the item type in XPath syntax, for examplemap(xs:string, node()*)
. The namespace prefixxs
is recognized; any other namespaced names should be written usingQ{uri}local
notation.- Returns:
- the ItemType
- Throws:
SaxonApiException
- if the syntax is invalid- Since:
- 12.0
-
getAtomicType
Get an item type representing an atomic type. This may be a built-in type in the XML Schema namespace, or a user-defined atomic type. The resulting type will use the conversion rules configured for the suppliedProcessor
.It is undefined whether two calls supplying the same QName will return the same ItemType object.
- Parameters:
name
- the name of the built-in or user-defined atomic type required- Returns:
- an ItemType object representing this built-in or user-defined atomic type
- Throws:
SaxonApiException
- if the type name is not known, or if the type identified by the name is not an atomic type.
-
getNodeKindTest
Get an item type that matches any node of a specified kind.This corresponds to the XPath syntactic forms element(), attribute(), document-node(), text(), comment(), processing-instruction(). It also provides an option, not available in the XPath syntax, that matches namespace nodes.
It is undefined whether two calls supplying the same argument value will return the same ItemType object.
- Parameters:
kind
- the kind of node for which a NodeTest is required- Returns:
- an item type corresponding to the specified kind of node
-
getItemType
Get an item type that matches nodes of a specified kind with a specified name.This corresponds to the XPath syntactic forms element(name), attribute(name), and processing-instruction(name). In the case of processing-instruction, the supplied QName must have no namespace.
It is undefined whether two calls supplying the same argument values will return the same ItemType object.
- Parameters:
kind
- the kind of nodes that matchname
- the name of the nodes that match- Returns:
- an ItemType that matches nodes of a given node kind with a given name
- Throws:
IllegalArgumentException
- if the node kind is other than element, attribute, or processing instruction, or if the node kind is processing instruction and the name is in a namespace.
-
getSchemaElementTest
Make an ItemType representing an element declaration in the schema. This is the equivalent of the XPath syntaxschema-element(element-name)
It is undefined whether two calls supplying the same argument values will return the same ItemType object.
- Parameters:
name
- the element name- Returns:
- the ItemType
- Throws:
SaxonApiException
- if the schema does not contain a global element declaration for the given name, or if the element declaration contains dangling references to other schema components
-
getElementTest
public ItemType getElementTest(QName name, QName schemaType, boolean nillable) throws SaxonApiException Make an ItemType that tests an element name and/or schema type. This is the equivalent of the XPath syntaxelement(element-name, type)
It is undefined whether two calls supplying the same argument values will return the same ItemType object.
- Parameters:
name
- the element name, or null if there is no constraint on the name (equivalent to specifyingelement(*, type)
)schemaType
- the name of the required schema type, or null if there is no constraint on the type (equivalent to specifyingelement(name)
)nillable
- if a nilled element is allowed to match the type (equivalent to specifying "?" after the type name). The value is ignored if schemaType is null.- Returns:
- the constructed ItemType
- Throws:
SaxonApiException
- if the schema does not contain a global element declaration for the given name
-
getSchemaAttributeTest
Get an ItemType representing an attribute declaration in the schema. This is the equivalent of the XPath syntaxschema-attribute(attribute-name)
It is undefined whether two calls supplying the same argument values will return the same ItemType object.
- Parameters:
name
- the attribute name- Returns:
- the ItemType
- Throws:
SaxonApiException
- if the schema does not contain a global attribute declaration for the given name, or if the attribute declaration contains dangling references to other schema components
-
getAttributeTest
Get an ItemType that tests an attribute name and/or schema type. This is the equivalent of the XPath syntaxelement(element-name, type)
It is undefined whether two calls supplying the same argument values will return the same ItemType object.
- Parameters:
name
- the element name, or null if there is no constraint on the name (equivalent to specifyingelement(*, type)
)schemaType
- the name of the required schema type, or null of there is no constraint on the type (equivalent to specifyingelement(name)
)- Returns:
- the constructed ItemType
- Throws:
SaxonApiException
- if the schema does not contain a global element declaration for the given name
-
getDocumentTest
Make an ItemType representing a document-node() test with an embedded element test. This reflects the XPath syntaxdocument-node(element(N, T))
ordocument-node(schema-element(N))
.It is undefined whether two calls supplying the same argument values will return the same ItemType object.
- Parameters:
elementTest
- the elementTest. An IllegalArgumentException is thrown if the supplied ItemTest is not an elementTest or schemaElementTest.- Returns:
- a new ItemType representing the document test
-
getExternalObjectType
Get an ItemType representing the type of a Java object when used as an external object for use in conjunction with calls on extension/external functions.- Parameters:
externalClass
- a Java class- Returns:
- the ItemType representing the type of external objects of this class
-
getExternalObject
Factory method to construct an "external object". This is an XDM value that wraps a Java object. Such values can be passed as parameters to stylesheets or queries, for use in conjunction with external (extension) functions.Changed in Saxon 9.5 to return XdmItem rather than XdmAtomicValue, since wrapped external objects are now modelled as a separate type of item, rather than as an atomic value.
- Parameters:
object
- the value to be wrapped as an external object. Must not be null.- Returns:
- the object, wrapped as an XdmItem
-
getMapType
Obtain a map type, that is a type for XDM maps with a given key type and value type- Parameters:
keyType
- the type of the keys in the mapvalueType
- the type of the values in the map- Returns:
- the required map type
-
getFunctionType
Obtain a function type, that is a type for XDM functions with given argument types and a given result type.- Parameters:
returnType
- the type of the function's resultargumentTypes
- the types of the argument values- Returns:
- the required function type
-
getArrayType
Obtain an array type, that is a type for XDM arrays with a given member type- Parameters:
memberType
- the type of the members in the array- Returns:
- the required array type
-
newMap
Deprecated.since 12.0 - useXdmMap.makeMap(java.util.Map<K, V>)
insteadFactory method to construct a map item from a Java mapNote: this is merely a wrapper around
XdmMap.makeMap(java.util.Map<K, V>)
, which is probably more convenient to use.- Parameters:
map
- the input map. The contents of this map are shallow-copied, so subsequent changes to the Java map do not affect the XDM map. The keys in the map must be convertible to atomic values, and the values in the map must be convertible to XDM values.- Returns:
- an XDM item representing the contents of the map. This is of type function item because XDM maps are functions (from the key to the value).
- Throws:
SaxonApiException
- if there are values that cannot be converted.- Since:
- 9.6
-
getItemType
Get an ItemType representing the type of a supplied XdmItem.Note that the results are to some extent arbitrary, since an item may conform to many different item types, and none of them is necessarily more specific than all the others.
If the supplied item is an atomic value, the returned ItemType will reflect the most specific atomic type of the item.
If the supplied item is a node, the returned item type will reflect the node kind, and if the node has a name, then its name. It will not reflect the type annotation.
For a map, the result is simply
ItemType.ANY_MAP
. For an array, the result is simplyItemType.ANY_ARRAY
. For any other function, it is an instance ofXdmFunctionItem
that reflects the signature of the function.If the item is an external object, a suitable item type object is constructed.
Future versions of Saxon may return a more precise type.
- Parameters:
item
- the supplied item whose type is required- Returns:
- the type of the supplied item
-
exposeItemType
Obtain a s9apiItemType
corresponding to an underlying instance ofItemType
-
XdmMap.makeMap(java.util.Map<K, V>)
instead