}
void checkIndex(Node refNode, int offset) throws DOMException
{
if (offset < 0) {
throw new DOMExceptionImpl(
DOMException.INDEX_SIZE_ERR,
"DOM004 Index out of bounds");
}
int type = refNode.getNodeType();
if((type == Node.TEXT_NODE
|| type == Node.CDATA_SECTION_NODE
|| type == Node.COMMENT_NODE
|| type == Node.PROCESSING_INSTRUCTION_NODE)
&& offset > refNode.getNodeValue().length()){
throw new DOMExceptionImpl(
DOMException.INDEX_SIZE_ERR,
"DOM004 Index out of bounds");
}
Node child = refNode.getFirstChild();
int i = 1;
for (; child != null; i++) {
child = child.getNextSibling();
}
if (i > offset) {
throw new DOMExceptionImpl(
DOMException.INDEX_SIZE_ERR,
"DOM004 Index out of bounds");
}
}