Changes

Jump to navigation Jump to search
867 bytes added ,  12:38, 9 July 2021
{{Mark|Updated with Version 9.6:}}
* Java objects are now wrapped into function items.
* New option {{Option|WRAPJAVA}}.
* Mapping rules were refined. The most important changes:** {{Code|array(*)}} type added.** {{Code|xs:integer}} values are converted to {{Code|long}} values.** {{Code|xs:unsignedShort}} values are converted to {{Code|char}} values.
===Conversion to Java===
===Conversion to XQuery===
The conversion back By default, Java values with the most common types (as shown in the second and third column of the table) are converted to XQuery can be controlled values. All other values are returned as ''Java items'', which are function items with the {{Option|WRAPJAVA}} optionembedded Java value. The following values exist:
* {{Code|some}} (the default): Java values with the most common types are converted The conversion of an embedded value to XQuery, as shown in the second and third column of the table.* {{Code|none}}: The conversion is enforcedby invoking the function item: Additional to the default conversions, the contained values Values in {{Code|Iterator}} and {{Code|Iterable}} instances (Lists, Sets and Collections) are converted to items, and maps are converted to XQuery maps. If no conversion is possible, the string representation is returned.* {{Code|all}}: All values (excluding those inheriting the internal type {{Code|org.basex.query.value.Value}}) are returned as wrapped Java objects. The wrapped objects can be passed on to other Java functions without intermediate conversions.
<syntaxhighlight lang="xquery">declare namespace Scanner = 'java:java.util.Scanner';let $scanner := Scanner:new("A B C") => Scanner:useDelimiter(" ")return $scanner()</syntaxhighlight> If no conversion is defined, the string representation of the Java value is returned. In contrast to other function items, it is legal to retrieve the string value of a Java item: <syntaxhighlight lang="xquery">(: returns the string representation of the Java object :)string(Q{java:java.util.ArrayList}new())</syntaxhighlight> The conversion can also be controlled with the {{Option|WRAPJAVA}} option can . The following values exist: {| class="wikitable"|- valign="top"! Value! Description|- valign="top"| {{Code|some}}| The default: The most common types are converted.|- valign="top"| {{Code|none}}| The conversion is enforced, and no Java values will be specified via a pragmawrapped.|- valign="top"| {{Code|all}}| All values (excluding those inheriting the internal type {{Code|org.basex.query.value.Value}}) are returned as Java items. This is helpful if Java function calls are chained, and if no intermediate conversion is required or desired. |} In the following example, the result of the first function – a char array – is wrapped and passed on to a {{Code|CharBuffer}} function:
<syntaxhighlight lang="xquery">
</syntaxhighlight>
Without the pragmaoption, the single-value array would be converted to an {{Code|xs:unsignedShort}} item and the second function call would fail.
{| class="wikitable"
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu