Example usage for org.springframework.batch.item.xml StaxUtils getSource

List of usage examples for org.springframework.batch.item.xml StaxUtils getSource

Introduction

In this page you can find the example usage for org.springframework.batch.item.xml StaxUtils getSource.

Prototype

public static Source getSource(XMLEventReader r) throws XMLStreamException 

Source Link

Usage

From source file:org.geoserver.backuprestore.reader.CatalogFileReader.java

/**
 * Move to next fragment and map it to item.
 *///from w  w w  .j  a v a 2 s .  c  o m
@Override
protected T doRead() throws Exception {
    T item = null;
    try {
        if (noInput) {
            return null;
        }

        boolean success = false;
        try {
            success = moveCursorToNextFragment(fragmentReader);
        } catch (NonTransientResourceException e) {
            // Prevent caller from retrying indefinitely since this is fatal
            noInput = true;
            throw e;
        }
        if (success) {
            fragmentReader.markStartFragment();

            try {
                @SuppressWarnings("unchecked")
                T mappedFragment = (T) unmarshal(StaxUtils.getSource(fragmentReader));
                item = mappedFragment;

                try {
                    firePostRead(item, resource);
                } catch (IOException e) {
                    logValidationExceptions((ValidationResult) null,
                            new UnexpectedInputException("Could not write data.  The file may be corrupt.", e));
                }
            } finally {
                fragmentReader.markFragmentProcessed();
            }
        }
    } catch (Exception e) {
        logValidationExceptions((T) null, e);
    }

    return item;
}

From source file:org.springframework.batch.item.xml.StaxEventItemReader.java

/**
 * Move to next fragment and map it to item.
 */// ww w  .  j a v a  2s  .c  o m
@Override
protected T doRead() throws Exception {

    if (noInput) {
        return null;
    }

    T item = null;

    boolean success = false;
    try {
        success = moveCursorToNextFragment(fragmentReader);
    } catch (NonTransientResourceException e) {
        // Prevent caller from retrying indefinitely since this is fatal
        noInput = true;
        throw e;
    }
    if (success) {
        fragmentReader.markStartFragment();

        try {
            @SuppressWarnings("unchecked")
            T mappedFragment = (T) unmarshaller.unmarshal(StaxUtils.getSource(fragmentReader));
            item = mappedFragment;
        } finally {
            fragmentReader.markFragmentProcessed();
        }
    }

    return item;
}