final EmbeddedXMLStreamReader reader = broker.getXMLStreamReader(parent, true);
final int level = nodeId.getTreeLevel();
StoredNode last = null;
while (reader.hasNext()) {
final int status = reader.next();
final NodeId currentId = (NodeId) reader.getProperty(ExtendedXMLStreamReader.PROPERTY_NODE_ID);
if (status != XMLStreamConstants.END_ELEMENT && currentId.getTreeLevel() == level) {
if (currentId.equals(nodeId))
{return last;}
last = reader.getNode();
}
}
} catch (final IOException e) {
LOG.error("Internal error while reading child nodes: " + e.getMessage(), e);
//TODO : throw exception -pb
} catch (final XMLStreamException e) {
LOG.error("Internal error while reading child nodes: " + e.getMessage(), e);
//TODO : throw exception -pb
} catch (final EXistException e) {
LOG.error("Internal error while reading child nodes: " + e.getMessage(), e);
//TODO : throw exception -pb
} finally {
ownerDocument.getBrokerPool().release(broker);
}
return null;
}
final NodeId firstChild = parent.getNodeId().newChild();
if (nodeId.equals(firstChild))
{return null;}
final NodeId siblingId = nodeId.precedingSibling();
return ownerDocument.getNode(siblingId);
}