<?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-arguments"/> <!-- Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: Converting Method Arguments - General Rules</title> <meta name="coverage" content="Worldwide"/> <meta name="copyright" content="Copyright Saxonica Ltd"/> <meta name="title" content="Saxonica: XSLT and XQuery Processing: Converting Method Arguments - General Rules"/> <meta name="robots" content="noindex,nofollow"/> <link rel="stylesheet" href="../../saxondocs.css" type="text/css"/> </head> <body class="main"> <h1>Converting Method Arguments - General Rules</h1> <p>Having decided which method to call, Saxon has to convert the supplied XPath argument values to the Java objects required by this method.</p> <p>If the expected type is <code>Object</code>, the supplied value must either be a singleton, or an empty sequence. If it is an empty sequence, null will be passed. If it is a singleton node, an instance of <a class="bodylink" href="../../javadoc/net/sf/saxon/om/NodeInfo.html"><code>net.sf.saxon.om.NodeInfo</code></a> will be passed. If it is a wrapped Java object, that Java object will be passed. If it is a singleton atomic value, the value will be converted to the nearest equivalent Java object: for example an <code>xs:boolean</code> becomes <code>java.lang.Boolean</code>, an <code>xs:string</code> becomes <code>java.lang.String</code>, and so on. An untyped atomic value is treated as a string. An <code>xs:integer</code> (even if it belongs to a subtype such as <code>xs:short</code>) is converted to a Java <code>BigInteger</code>. The more specialized XML Schema primitive types such as <code>xs:hexBinary</code> and <code>xs:duration</code> are passed in their native Saxon representation (a subclass of <a class="bodylink" href="../../javadoc/net/sf/saxon/value/AtomicValue.html"><code>net.sf.saxon.value.AtomicValue</code></a>).</p> <p>If the expected type is one of the Saxon-specific classes (<a class="bodylink" href="../../javadoc/net/sf/saxon/om/SequenceIterator.html"><code>SequenceIterator</code></a>, <a class="bodylink" href="../../javadoc/net/sf/saxon/om/ValueRepresentation.html"><code>ValueRepresentation</code></a>, <a class="bodylink" href="../../javadoc/net/sf/saxon/om/Item.html"><code>Item</code></a>, <a class="bodylink" href="../../javadoc/net/sf/saxon/value/Value.html"><code>Value</code></a>, <a class="bodylink" href="../../javadoc/net/sf/saxon/value/AtomicValue.html"><code>AtomicValue</code></a>, <a class="bodylink" href="../../javadoc/net/sf/saxon/value/SequenceExtent.html"><code>SequenceExtent</code></a>), then the value is passed unchanged. An error occurs if the supplied value contains more than one item and the expected type does not allow this.</p> <p>If the expected type implements <code>java.util.Collection</code>, Saxon attempts to convert each value in the supplied sequence to the most appropriate Java class, following the same rules as when converting a singleton to <code>java.lang.Object</code>. This process takes no account of parameterized collection types (such as <code>List<String></code>). If the required collection type accepts an <code>java.util.ArrayList</code>, Saxon will create an <code>ArrayList</code> to hold the values; otherwise it will attempt to instantiate the required type of collection, which will only work if it is a concrete class with a zero-argument public constructor (so it will fail, for example, if the required type is <code>java.util.Set</code>). If an empty sequence is supplied as the argument value, this is converted to an empty Collection.</p> <p>If the required type is an array, Saxon will attempt to create an array of the required type. This will not always succeed, for example if the array has type <code>X[]</code> where X is an interface rather than a concrete class. If it is an array of items or nodes, the nodes in the supplied sequence will be inserted into the array directly; if it is an array of a type such as integer or double, the sequence will first be atomized.</p> <table width="100%"> <tr> <td> <p align="right"><a class="nav" href="converting-atomic.xml">Next</a></p> </td> </tr> </table> </body> </html>