// If $arg is not specified, returns the value of the base-uri property
// of the context item (.)
final Item contextItem = dynEnv.contextItem();
if(argv == null) {
if(contextItem == null) {
throw new DynamicError("err:XPDY0002", "Context Item is not set");
} else {
if(!(contextItem instanceof XQNode)) {
throw new DynamicError("err:XPTY0004", "Context item is not a node: "
+ contextItem.getClass().getName());
}
}
} else if(argv.isEmpty()) {// If $arg is the empty sequence, the empty sequence is returned.
return ValueSequence.EMPTY_SEQUENCE;
}
}
Item it = argv.getItem(0);
if(it instanceof SingleCollection) {
final Sequence<? extends Item> src = ((SingleCollection) it).getSource();
final IFocus<? extends Item> itor = src.iterator();
if(!itor.hasNext()) {
itor.closeQuietly();
return ValueSequence.EMPTY_SEQUENCE;
}
it = itor.next();
if(itor.hasNext()) {
itor.closeQuietly();
throw new DynamicError("err:XPTY0004", "Context item is not a node: " + src);
}
itor.closeQuietly();
}
if(!(it instanceof XQNode)) {
if(it.isEmpty()) {
return ValueSequence.EMPTY_SEQUENCE;
} else {
throw new DynamicError("err:XPTY0004", "Item was not a node: "
+ it.getClass().getName());
}
}
final XQNode node = (XQNode) it;
final byte nodekind = node.nodeKind();