### Question:
BagriXQItemAccessor extends BagriXQCloseable implements XQItemAccessor { @Override public XQItemType getItemType() throws XQException { if (closed) { throw new XQException(ex_item_closed); } if (!positioned) { throw new XQException("not positioned on the Item"); } return type; } BagriXQItemAccessor(XQProcessor xqProcessor); @Override boolean getBoolean(); @Override byte getByte(); @Override double getDouble(); @Override float getFloat(); @Override int getInt(); @Override XQItemType getItemType(); @Override String getAtomicValue(); @Override long getLong(); @Override Node getNode(); @Override URI getNodeUri(); @Override Object getObject(); @Override XMLStreamReader getItemAsStream(); @Override String getItemAsString(Properties props); @Override short getShort(); @Override boolean instanceOf(XQItemType type); @Override void writeItem(OutputStream os, Properties props); @Override void writeItem(Writer ow, Properties props); @Override void writeItemToSAX(ContentHandler saxhdlr); @Override void writeItemToResult(Result result);  }### Answer:
@Test public void testBindNode() throws XQException, IOException, SAXException, ParserConfigurationException { XQPreparedExpression xqpe; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser = factory.newDocumentBuilder(); Document document = parser.parse(new InputSource(new StringReader( "<e>Hello world!</e>"))); xqpe = xqc.prepareExpression("declare variable $v external; $v"); xqpe.close(); try { xqpe.bindNode(new QName("v"), document, null); fail("A-XQDC-1.1: bindNode() throws an XQException when the dynamic context is in closed state."); } catch (XQException e) { } xqpe = xqc.prepareExpression("declare variable $v external; $v"); try { xqpe.bindNode(null, document, null); fail("A-XQDC-1.2: null argument is invalid and throws an XQException."); } catch (XQException e) { } xqpe.close(); boolean bindFailed = false; xqpe = xqc.prepareExpression("declare variable $v external; $v"); try { xqpe.bindNode(new QName("v"), document, xqc.createCommentType()); } catch (XQException e) { bindFailed = true; } if (!bindFailed) { XQSequence xqs = xqpe.executeQuery(); xqs.next(); if (xqs.getItemType().getItemKind() != XQItemType.XQITEMKIND_COMMENT) { fail("A-XQDC-1.3: The conversion is subject to the following constraints. Either it fails with an XQException, either it is successful in which case it must result in an instance of XDT."); } } xqpe.close(); xqpe = xqc.prepareExpression("declare variable $v external; $v"); try { xqpe.bindNode(new QName("foo"), document, null); fail("A-XQDC-1.5: The bound variable must be declared external in the prepared expression."); } catch (XQException e) { } xqpe.close(); xqpe = xqc.prepareExpression("declare variable $v as xs:decimal external; $v"); try { xqpe.bindNode(new QName("v"), document, null); xqpe.executeQuery().getSequenceAsString(null); fail("A-XQDC-1.6: The dynamic type of the bound value is not compatible with the static type of the variable and must fail."); } catch (XQException e) { } xqpe.close(); xqpe = xqc.prepareExpression("declare variable $v external; $v"); try { xqpe.bindNode(new QName("v"), document, null); } catch (XQException e) { fail("A-XQDC-1.7: bindNode() failed with message: " + e.getMessage()); } String result = xqpe.executeQuery().getSequenceAsString(null); assertTrue("A-XQDC-1.7: Expects serialized result contains '<e>Hello world!</e>', but it is '" + result + "'", result.indexOf("<e>Hello world!</e>") != -1); xqpe.close(); }