Changes

Jump to navigation Jump to search
1,600 bytes removed ,  12:14, 8 July 2021
no edit summary
{{Mark|Introduced with Version 9.6}
 
==convert:from-java==
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|convert:from-java|$items as item()*|item()*}}
|-
| '''Summary'''
|Tries to convert Java objects, which result from the invocation of [[Java Bindings#Data Types|Java Code]], to XQuery values. The supplied {{Code|$items}} are processed one by one:
* If an item is already an XQuery value (e.g., as result from the default mapping), it is returned unchanged.
* If an item wraps an {{Code|Iterable}} ({{Code|Collection}}, {{Code|List}}, {{Code|Set}}, others) or {{Code|Iterator}}, the contained objects are recursively converted to XQuery.
* If an item wraps a {{Code|Map}}, the entries are recursively converted to an XQuery map.
* If no conversion is possible, an error is raised.
|-
| '''Examples'''
|Adds 1000 values to {{Code|HashSet}} and returns the number of distinct entries:
<syntaxhighlight lang="xquery">
declare namespace HashSet = 'java:java.util.HashSet';
let $set := HashSet:new()
return (
prof:void((1 to 1000) ! HashSet:add($set, . mod 10)),
count(convert:from-java($set))
)
</syntaxhighlight>
Creates a {{Code|Scanner}} instance and converts the iterated results as sequence:
<syntaxhighlight lang="xquery">
declare namespace Scanner = 'java:java.util.Scanner';
Scanner:new("A B C")
=> Scanner:useDelimiter(" ")
=> convert:from-java()
</syntaxhighlight>
|-
| '''Errors'''
|{{Error|java|#Errors}} A wrapped Java object cannot be converted to an XQuery value.
|}
=Errors=
|{{Code|integer}}
|The specified digit is not valid for the given range.
|-
|{{Code|java}}
|A wrapped Java object cannot be converted to an XQuery value.
|-
|{{Code|key}}
=Changelog=
 
;Version 9.6
* Added: {{Function||convert:from-java}}
;Version 9.4
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu