<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="extensibility" page="function-result" subpage=""/>
      <!--
           Generated at 2010-10-29T18:20:48.427+01:00--><title>Saxonica: XSLT and XQuery Processing: Converting the Result of a Java Extension Function</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title"
            content="Saxonica: XSLT and XQuery Processing: Converting the Result of a Java Extension Function"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>Converting the Result of a Java Extension Function</h1>
      <p>This section explains how the value returned by a Java extension function is converted
to an XPath value. The same rules are used in converting a Java object supplied as a parameter
to a stylesheet or query.</p>
      <p>The result type of the method is converted to an XPath value as follows.</p>
      <ul>
         <li content="para">
            <p>If the method returns void, the XPath value is an empty sequence.</p>
         </li>
         <li content="para">
            <p>If the method returns null, the XPath value is an empty sequence.</p>
         </li>
         <li>
            <p>If the method is a constructor, the XPath value is of type "wrapped Java object". The only way of
using this is by passing it to another external function, or by converting it to one of the standard
XPath data types as described above.</p>
            <p><i>Note that calling <code>ArrayList.new()</code> will result in a wrapped <code>ArrayList</code> object. By constrast,
calling a method that returns an <code>ArrayList</code> will result in a an XPath sequence whose items are constructed by
converting the members of the returned <code>ArrayList</code>.</i></p>
         </li>
         <li content="para">
            <p>If the returned value is a Java boolean or Boolean, the XPath result is a boolean.</p>
         </li>
         <li content="para">
            <p>If the returned value is a Java double or Double, the XPath result is a double.</p>
         </li>
         <li content="para">
            <p>If the returned value is a Java float or Float, the XPath result is a float.</p>
         </li>
         <li content="para">
            <p>If the returned value is a Java int, short, long, character, or byte, or one of their object wrapper
equivalents, the XPath result is an integer.</p>
         </li>
         <li content="para">
            <p>If the returned value is a Java String, the XPath result is a string.</p>
         </li>
         <li content="para">
            <p>If the returned value is an instance of the Saxon class <a class="bodylink" href="../javadoc/net/sf/saxon/om/NodeInfo.html"><code>net.sf.saxon.om.NodeInfo</code></a>
 (a node in a Saxon tree), the XPath value will be a sequence containing a single node.</p>
         </li>
         <li content="para">
            <p>If the returned value is an instance of <code>javax.xml.transform.Source</code> 
(other than a <code>NodeInfo</code>), 
a tree is built from the specified <code>Source</code> object, and the root node of this tree is returned as
 the result of the function.</p>
         </li>
         <li content="para">
            <p>If the returned value is an instance of the Saxon class <a class="bodylink" href="../javadoc/net/sf/saxon/value/ValueRepresentation.html"><code>net.sf.saxon.value.ValueRepresentation</code></a>,
the returned value is used unchanged.</p>
         </li>
         <li content="para">
            <p>If the returned value is is an instance of the Saxon class <a class="bodylink" href="../javadoc/net/sf/saxon/om/SequenceIterator.html"><code>net.sf.saxon.om.SequenceIterator</code></a>
(an iterator over a sequence), the XPath
value will be the sequence represented by this iterator. It is essential that this iterator
properly implements the method <code>getAnother()</code> which returns a new iterator over the
same sequence of nodes or values, positioned at the start of the sequence.</p>
         </li>
         <li content="para">
            <p>If the returned value is an instance of the Java class <code>java.util.Collection</code>, or if it is an array,
 the XPath value will be the
sequence represented by the contents of this <code>Collection</code> or array. The members of the collection or array
will each be converted
to an XPath value, as if each member was supplied from a separate function call. An error is reported if
the result contains a list or array nested within another list or array. 
The contents of the list or array are copied immediately on return from the
function, so the original <code>List</code> or array object itself may be safely re-used.</p>
         </li>
         <li content="para">
            <p>If the returned value is a DOM Node, and it is recognized as a wrapper around a Saxon node, then the node
is unwrapped and the underlying Saxon node is returned. If the returned value is some other kind of DOM Node, then
a Saxon wrapper is added. (This is an imperfect solution, since it can lead to problems with node identity and document
order.) </p>
         </li>
         <li content="para">
            <p>If the returned value is a DOM <code>NodeList</code>, the list of nodes is returned as a Saxon node-set. 
Each node is handled in the same way as a Node that is returned directly as the result.</p>
         </li>
         <li content="para">
            <p>If the result is any other Java object (including null), it is returned as a "wrapped Java object".</p>
         </li>
      </ul>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="dotnetextensions.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>