List of usage examples for org.springframework.batch.item.xml.stax UnclosedElementCollectingEventWriter getUnclosedElements
public List<QName> getUnclosedElements()
From source file:org.springframework.batch.item.xml.StaxEventItemWriter.java
/** * Open the output source//w w w . j a v a 2 s .c o m * * @see org.springframework.batch.item.ItemStream#open(ExecutionContext) */ @SuppressWarnings("unchecked") @Override public void open(ExecutionContext executionContext) { super.open(executionContext); Assert.notNull(resource, "The resource must be set"); long startAtPosition = 0; // if restart data is provided, restart from provided offset // otherwise start from beginning if (executionContext.containsKey(getExecutionContextKey(RESTART_DATA_NAME))) { startAtPosition = executionContext.getLong(getExecutionContextKey(RESTART_DATA_NAME)); currentRecordCount = executionContext.getLong(getExecutionContextKey(WRITE_STATISTICS_NAME)); if (executionContext.containsKey(getExecutionContextKey(UNCLOSED_HEADER_CALLBACK_ELEMENTS_NAME))) { unclosedHeaderCallbackElements = (List<QName>) executionContext .get(getExecutionContextKey(UNCLOSED_HEADER_CALLBACK_ELEMENTS_NAME)); } restarted = true; if (shouldDeleteIfEmpty && currentRecordCount == 0) { // previous execution deleted the output file because no items were written restarted = false; startAtPosition = 0; } else { restarted = true; } } else { currentRecordCount = 0; restarted = false; } open(startAtPosition); if (startAtPosition == 0) { try { if (headerCallback != null) { UnclosedElementCollectingEventWriter headerCallbackWriter = new UnclosedElementCollectingEventWriter( delegateEventWriter); headerCallback.write(headerCallbackWriter); unclosedHeaderCallbackElements = headerCallbackWriter.getUnclosedElements(); } } catch (IOException e) { throw new ItemStreamException("Failed to write headerItems", e); } } this.initialized = true; }