NodeInfo node = ((SingletonNode)v).getNode();
if (node != null) {
array[a++] = node;
}
} else {
throw new DynamicError(
"Returned List contains an object that cannot be converted to an Item (" + obj.getClass() + ')');
}
}
}
}
return new SequenceExtent(array);
} else if (result instanceof Object[]) {
Item[] array = new Item[((Object[])result).length];
int a = 0;
for (int i = 0; i < ((Object[])result).length; i++){
Object obj = ((Object[])result)[i];
if (obj instanceof NodeInfo) {
array[a++] = (NodeInfo)obj;
} else {
Value v = convertJavaObjectToXPath(obj, controller);
if (v!=null) {
if (v instanceof Item) {
array[a++] = (Item)v;
} else {
throw new DynamicError(
"Returned array contains an object that cannot be converted to an Item (" + obj.getClass() + ')');
}
}
}
}
return new SequenceExtent(array);
} else if (result instanceof long[]) {
Item[] array = new Item[((long[])result).length];
for (int i = 0; i < ((long[])result).length; i++){
array[i] = new IntegerValue(((long[])result)[i]);
}
return new SequenceExtent(array);
} else if (result instanceof int[]) {
Item[] array = new Item[((int[])result).length];
for (int i = 0; i < ((int[])result).length; i++){
array[i] = new IntegerValue(((int[])result)[i]);
}
return new SequenceExtent(array);
} else if (result instanceof short[]) {
Item[] array = new Item[((short[])result).length];
for (int i = 0; i < ((short[])result).length; i++){
array[i] = new IntegerValue(((short[])result)[i]);
}
return new SequenceExtent(array);
} else if (result instanceof byte[]) { // interpret this as unsigned bytes
Item[] array = new Item[((byte[])result).length];
for (int i = 0; i < ((byte[])result).length; i++){
array[i] = new IntegerValue(255 & (int)((byte[])result)[i]);
}
return new SequenceExtent(array);
} else if (result instanceof char[]) {
return new StringValue(new String((char[])result));
} else if (result instanceof boolean[]) {
Item[] array = new Item[((boolean[])result).length];
for (int i = 0; i < ((boolean[])result).length; i++){
array[i] = BooleanValue.get(((boolean[])result)[i]);
}
return new SequenceExtent(array);
} else if (result instanceof Source && controller != null) {
if (result instanceof DOMSource) {
return new SingletonNode(controller.prepareInputTree((Source)result));
}
try {
Builder b = controller.makeBuilder();
new Sender(controller.getConfiguration()).send((Source) result, b);
return new SingletonNode(b.getCurrentDocument());
} catch (XPathException err) {
throw new DynamicError(err);
}
} else if (result instanceof org.w3c.dom.NodeList) {
NodeList list = ((NodeList)result);
NodeInfo[] nodes = new NodeInfo[list.getLength()];
for (int i=0; i<list.getLength(); i++) {
if (list.item(i) instanceof NodeInfo) {
nodes[i] = (NodeInfo)list.item(i);
} else {
throw new DynamicError("Supplied NodeList contains non-Saxon DOM Nodes");
}
}
return new SequenceExtent(nodes);
// Note, we accept the nodes in the order returned by the function; there
// is no requirement that this should be document order.
} else if (result instanceof org.w3c.dom.Node) {
throw new DynamicError("Supplied Java object is a non-Saxon DOM Node");
} else {
return new ObjectValue(result);
}
}