<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="extensibility" page="converting-args"
               subpage="converting-wrapped-java"/>
      <!--
           Generated at 2010-10-29T18:20:48.427+01:00--><title>Saxonica: XSLT and XQuery Processing: Converting Wrapped Java Objects</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title"
            content="Saxonica: XSLT and XQuery Processing: Converting Wrapped Java Objects"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>Converting Wrapped Java Objects</h1>
      <p>Saxon allows an extension function to return an arbitrary Java object. This will then be wrapped as an XPath item, so that
it can be held in a variable and passed subsequently as an argument to another extension function. This second extension function
will see the original Java object minus its wrapper, provided it is declared to expect the appropriate Java class.</p>
      <p>A wrapped Java object may be converted to another data type as follows.</p>
      <ul>
         <li content="para">
            <p>It is converted to a string by using its toString() method; if the object is null, the result is
the empty string "".</p>
         </li>
         <li content="para">
            <p>It is converted to a number by converting it first to a string, and then applying the
XPath number() conversion. If it is null, the result is NaN.</p>
         </li>
         <li content="para">
            <p>It is converted to a boolean as follows: if it is null, the result is false, otherwise
it is converted to a string and the result is true if and only if the string is non-empty.</p>
         </li>
      </ul>
      <p>The type of a wrapped Java object may be declared in a variable declaration or function signature using a type name whose
namespace URI is "http://saxon.sf.net/java-type", and whose local name is the fully qualified name of the Java class, with any "$" signs 
replaced by hyphens. For example, the <code>sql:connection</code> extension function returns a value of type
<code>{http://saxon.sf.net/java-type}java.sql.Connection</code>.</p>
      <p>Note that a call on a constructor function (using prefix:new()) always returns a wrapped Java object, regardless
of the class. But a call on a static method, instance-level method, or field will return a wrapped Java object only
if the result is a class that Saxon does not specifically recognize as one that it can convert to a regular
XPath value. Such classes include <code>String</code>, <code>Long</code>, <code>Double</code>, <code>Date</code>, 
<code>BigInteger</code>, <code>URI</code>, <code>List</code> and so on.</p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="../function-result.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>