// }
try {
if (container instanceof OMDocument) {
if (container != document) {
throw new OMException("Called discard for a document that is not being built by this builder");
}
while (parserNext() != XMLStreamConstants.END_DOCUMENT) {
// Just loop
}
} else {
// Calculate the depth of the element to be discarded. This determines how many
// END_ELEMENT events we need to consume.
int targetDepth = elementLevel-1;
OMContainerEx current = target;
while (current != container) {
if (current instanceof OMElement) {
targetDepth--;
current = (OMContainerEx)((OMElement)current).getParent();
} else {
throw new OMException("Called discard for an element that is not being built by this builder");
}
}
while (elementLevel > targetDepth) {
parserNext();
}
}
// Mark nodes as discarded
OMContainerEx current = target;
while (true) {
discarded(current);
if (current == container) {
break;
}
current = (OMContainerEx)((OMElement)current).getParent();
}
if (container instanceof OMDocument) {
target = null;
done = true;
} else {
target = (OMContainerEx)((OMElement)container).getParent();
}
} catch (XMLStreamException e) {
throw new OMException(e);
}
}