Changes

Jump to navigation Jump to search
204 bytes removed ,  18:33, 1 December 2023
m
Text replacement - "</syntaxhighlight>" to "</pre>"
declare namespace math = "java:java.lang.Math";
math:cos(xs:double(0)), math:PI()
</syntaxhighlightpre>
With the [[XQuery 3.0#Expanded QNames|Expanded QName]] notation of XQuery 3.0, the namespace can directly be embedded in the function call:
<syntaxhighlight lang="xquery">
Q{java:java.lang.Math}cos(xs:double(0))
</syntaxhighlightpre>
The constructor of a class can be invoked by calling the virtual function {{Code|new()}}. Instance methods can then called by passing on the resulting Java object as first argument. In the following example, 256 bytes are written to the file {{Code|output.txt}}. First, a new {{Code|FileWriter}} instance is created, and its {{Code|write()}} function is called in the next step:
fw:close($file)
)
</syntaxhighlightpre>
If the result of a Java call contains invalid XML characters, it will be rejected. The validity check can be disabled by setting {{Option|CHECKSTRINGS}} to false. In the example below, a file with a single {{Code|00}} byte is written, and this file will then be accessed by via Java functions:
br:close($br)
)
</syntaxhighlightpre>
The option can also be specified via a pragma:
br:new(fr:new('00.bin')) ! (br:readLine(.), br:close(.))
}
</syntaxhighlightpre>
=Module Imports=
),
set:size()
</syntaxhighlightpre>
The execution of imported classes is more efficient than the execution of instances that have been created via {{Code|new()}}. In turn, no arguments can be supplied in the import statement, and the construction will only be successful if the class can be instantiated without arguments.
element error { $err:description }
}
</syntaxhighlightpre>
The imported Java class is shown below:
}
}
</syntaxhighlightpre>
The result will look as follows:
<user>admin</admin>
<error>Integer conversion failed: abc</error>
</syntaxhighlightpre>
Please visit the XQuery 3.0 specification if you want to get more insight into
// ...
}
</syntaxhighlightpre>
An XQuery expression will be handled as an [[XQuery Update#Updating Expressions|updating expression]] if it calls an updating Java function. In contrast to XQuery update operations, the Java code will immediately be executed, but the result will be cached as if {{Function|Update|update:output}} was called.
// ...
}
</syntaxhighlightpre>
If an XQuery expression invokes {{Code|write()}}, any other query that calls {{Code|write()}} or {{Code|read()}} needs to wait for the query to be finished. The {{Code|read()}} function can be run in parallel; whereas queries will be queued if {{Code|write()}} is called.
Q{String}codePointAt('ABC', xs:byte(1)),
Q{String}codePointAt('ABC', 1)
</syntaxhighlightpre>
===Conversion to XQuery===
let $scanner := Scanner:new("A B C") => Scanner:useDelimiter(" ")
return $scanner()
</syntaxhighlightpre>
If no conversion is defined, a string is returned, resulting from the {{Code|toString()}} method of the object. This method is also called if the string representation of a Java item is requested:
'Map: ' || Q{java.util.HashMap}new(),
string(Q{java:java.util.ArrayList}new())
</syntaxhighlightpre>
The conversion can be further controlled with the {{Option|WRAPJAVA}} option. The following values exist:
=> Q{java.nio.CharBuffer}wrap()
}
</syntaxhighlightpre>
The next example demonstrates a use case for the {{Code|instance}} option:
}
return $set()
</syntaxhighlightpre>
The {{Code|void}} option is helpful if side-effecting methods return values that do not contribute to the final result:
$set()
)
</syntaxhighlightpre>
The irrelevant results could also be swallowed with {{Function|Profiling|prof:void}}.
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu