* @throws OMException
*/
public int next() throws OMException {
try {
if (done) {
throw new OMException();
}
int token = parser.next();
if (!cache) {
return token;
}
switch (token) {
case XMLStreamConstants.START_ELEMENT:
if (doDebug) {
System.out.println("START_ELEMENT: " + parser.getName() + ":" + parser.getLocalName());
}
lastNode = createOMElement();
break;
case XMLStreamConstants.START_DOCUMENT:
// Document has already being created.
document.setXMLVersion(parser.getVersion());
document.setCharsetEncoding(parser.getEncoding());
document.setStandalone(parser.isStandalone() ? "yes" : "no");
if (doDebug) {
System.out.println("START_DOCUMENT: ");
}
break;
case XMLStreamConstants.CHARACTERS:
if (doDebug) {
System.out.println("CHARACTERS: [" + parser.getText() + "]");
}
lastNode = createOMText(XMLStreamConstants.CHARACTERS);
break;
case XMLStreamConstants.CDATA:
if (doDebug) {
System.out.println("CDATA: [" + parser.getText() + "]");
}
lastNode = createOMText(XMLStreamConstants.CDATA);
break;
case XMLStreamConstants.END_ELEMENT:
if (doDebug) {
System.out.println("END_ELEMENT: " + parser.getName() + ":" + parser.getLocalName());
}
endElement();
break;
case XMLStreamConstants.END_DOCUMENT:
if (doDebug) {
System.out.println("END_DOCUMENT: ");
}
done = true;
((OMContainerEx) this.document).setComplete(true);
break;
case XMLStreamConstants.SPACE:
if (doDebug) {
System.out.println("SPACE: [" + parser.getText() + "]");
}
lastNode = createOMText(XMLStreamConstants.SPACE);
break;
case XMLStreamConstants.COMMENT:
if (doDebug) {
System.out.println("COMMENT: [" + parser.getText() + "]");
}
createComment();
break;
case XMLStreamConstants.DTD:
if (doDebug) {
System.out.println("DTD: [" + parser.getText() + "]");
}
createDTD();
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
if (doDebug) {
System.out.println("PROCESSING_INSTRUCTION: [" + parser.getPITarget() + "][" + parser.getPIData() + "]");
}
createPI();
break;
case XMLStreamConstants.ENTITY_REFERENCE:
if (doDebug) {
System.out.println("ENTITY_REFERENCE: " + parser.getLocalName() + "[" + parser.getText() + "]");
}
lastNode = createOMText(XMLStreamConstants.ENTITY_REFERENCE);
break;
default :
throw new OMException();
}
return token;
} catch (OMException e) {
throw e;
} catch (Exception e) {
throw new OMException(e);
}
}