Changes

Jump to navigation Jump to search
2,034 bytes added ,  10:51, 6 December 2010
Created page with "==Java Binding== The Java Binding feature is an extensibility mechanism which allows direct calling of Java methods bound as XQuery functions and manipulation of wrapped Java ob..."
==Java Binding==

The Java Binding feature is an extensibility mechanism which allows direct calling
of Java methods bound as XQuery functions and manipulation of wrapped Java objects.
The following examples introduce the behavior. Please note that the namespace URI
must be of the form <code>java:fullyQualifiedClassName</code>.
<blockquote>
<p>This example uses the java <code>Math</code> class and returns the cosine of an angle:</p>
<pre>
declare namespace math = "java:java.lang.Math";
math:cos(xs:double(0))
</pre>

<p>The next example writes 256 bytes to the file <code>output.txt</code>:</p>
<pre> declare namespace fw = &quot;java:java.io.FileWriter&quot;;

let $file := fw:new('output.txt')
return (
for $i in 0 to 255
return fw:write($file, xs:int($i)),
fw:close($file)
)
</pre>
</blockquote>

==Try/Catch==
<p>The well-known try/catch construct can be used in BaseX to intercept
run-time errors. This feature will also be part of the new
<a href="http://www.w3.org/TR/xquery-11/#id-try-catch">XQuery 1.1 Recommendation</a>.<br/>
</p>
<blockquote>
<p><b>Example:</b></p>
<pre>
try {
1 + '2'
} catch *($code, $desc) {
concat('Error [', $code, ']: ', $desc)
}</pre>
<p><b>Result:</b> <code>Error [XPTY0004]: '+' operator: number expected, string found.</code></p>
</blockquote>

</div>
<div id="footer">
&copy; 2006-10 <a href="http://www.informatik.uni-konstanz.de/en/groups/dbis" target="top">
BaseX; DBIS, U Konstanz &nbsp;</a>
<!-- echo "Updated on ".(gmdate('Y/m/d', filectime($_SERVER[SCRIPT_NAME]))); -->
<a href='http://twitter.com/home?status=http%3A%2F%2Fwww.basex.org' target='_blank'><img border='0' alt='twitter' src='gfx/twitter.png'/></a>
<a href='http://facebook.com/sharer.php?u=http%3A%2F%2Fwww.basex.org' target='_blank'><img border='0' alt='facebook' src='gfx/facebook.png'/></a>
<a href='http://del.icio.us/post?url=http%3A%2F%2Fwww.basex.org' target='_blank'><img border='0' alt='delicio.us' src='gfx/delicious.png'/></a>
<br/>&nbsp;
</div>
Anonymous user

Navigation menu