Search in sources :

Example 1 with FixedLengthRecord

use of org.apache.camel.dataformat.bindy.annotation.FixedLengthRecord in project camel by apache.

the class BindyFixedLengthFactory method initFixedLengthRecordParameters.

/**
     * Get parameters defined in @FixedLengthRecord annotation
     */
private void initFixedLengthRecordParameters() {
    for (Class<?> cl : models) {
        // Get annotation @FixedLengthRecord from the class
        FixedLengthRecord record = cl.getAnnotation(FixedLengthRecord.class);
        if (record != null) {
            LOG.debug("Fixed length record: {}", record);
            // Get carriage return parameter
            crlf = record.crlf();
            LOG.debug("Carriage return defined for the CSV: {}", crlf);
            // Get header parameter
            header = record.header();
            LOG.debug("Header: {}", header);
            hasHeader = header != void.class;
            LOG.debug("Has Header: {}", hasHeader);
            // Get skipHeader parameter
            skipHeader = record.skipHeader();
            LOG.debug("Skip Header: {}", skipHeader);
            // Get footer parameter
            footer = record.footer();
            LOG.debug("Footer: {}", footer);
            hasFooter = record.footer() != void.class;
            LOG.debug("Has Footer: {}", hasFooter);
            // Get skipFooter parameter
            skipFooter = record.skipFooter();
            LOG.debug("Skip Footer: {}", skipFooter);
            // Get isHeader parameter
            isHeader = hasHeader ? cl.equals(header) : false;
            LOG.debug("Is Header: {}", isHeader);
            // Get isFooter parameter
            isFooter = hasFooter ? cl.equals(footer) : false;
            LOG.debug("Is Footer: {}", isFooter);
            // Get padding character
            paddingChar = record.paddingChar();
            LOG.debug("Padding char: {}", paddingChar);
            // Get length of the record
            recordLength = record.length();
            LOG.debug("Length of the record: {}", recordLength);
            // Get flag for ignore trailing characters
            ignoreTrailingChars = record.ignoreTrailingChars();
            LOG.debug("Ignore trailing chars: {}", ignoreTrailingChars);
            ignoreMissingChars = record.ignoreMissingChars();
            LOG.debug("Enable ignore missing chars: {}", ignoreMissingChars);
        }
    }
    if (hasHeader && isHeader) {
        throw new java.lang.IllegalArgumentException("Record can not be configured with both 'isHeader=true' and 'hasHeader=true'");
    }
    if (hasFooter && isFooter) {
        throw new java.lang.IllegalArgumentException("Record can not be configured with both 'isFooter=true' and 'hasFooter=true'");
    }
    if ((isHeader || isFooter) && (skipHeader || skipFooter)) {
        throw new java.lang.IllegalArgumentException("skipHeader and/or skipFooter can not be configured on a record where 'isHeader=true' or 'isFooter=true'");
    }
}
Also used : FixedLengthRecord(org.apache.camel.dataformat.bindy.annotation.FixedLengthRecord)

Aggregations

FixedLengthRecord (org.apache.camel.dataformat.bindy.annotation.FixedLengthRecord)1