Search in sources :

Example 6 with DataCellToJavaConverter

use of org.knime.core.data.convert.java.DataCellToJavaConverter in project knime-core by knime.

the class DefaultKnimeToExternalMapper method map.

@Override
public void map(final DataRow row, final D destination, @SuppressWarnings("unchecked") final P... parameters) throws MappingException {
    requireNonNull(row, "row");
    requireNonNull(destination, "destination");
    if (requireNonNull(parameters, "parameters").length != m_cellCount) {
        throw new IllegalArgumentException("The number of consumer parameters is not equal to the number of cells (" + m_cellCount + "): " + parameters.length);
    }
    try {
        final ListIterator<Pair<DataCellToJavaConverter<?, ?>, CellValueConsumer<D, Object, P>>> // Forced line break.
        converterConsumerPairIterator = m_converterConsumerPairs.listIterator();
        for (final DataCell cell : row) {
            final Pair<DataCellToJavaConverter<?, ?>, CellValueConsumer<D, Object, P>> converterConsumerPair = converterConsumerPairIterator.next();
            converterConsumerPair.getSecond().consumeCellValue(destination, cell.isMissing() ? null : converterConsumerPair.getFirst().convertUnsafe(cell), parameters[converterConsumerPairIterator.previousIndex()]);
        }
    } catch (final Exception exception) {
        // always unwrap the exception and return a new MappingException with the cause message
        final Throwable cause = exception.getCause();
        final String message;
        if (cause != null) {
            message = cause.getMessage();
        } else {
            message = "Data type mapping exception";
        }
        throw new MappingException(message, cause);
    }
}
Also used : DataCellToJavaConverter(org.knime.core.data.convert.java.DataCellToJavaConverter) DataCell(org.knime.core.data.DataCell) Pair(org.knime.core.util.Pair)

Aggregations

DataCellToJavaConverter (org.knime.core.data.convert.java.DataCellToJavaConverter)6 Test (org.junit.Test)5 DataCell (org.knime.core.data.DataCell)5 BinaryObjectDataCell (org.knime.core.data.blob.BinaryObjectDataCell)4 ArrayList (java.util.ArrayList)2 MissingCell (org.knime.core.data.MissingCell)2 ListCell (org.knime.core.data.collection.ListCell)2 IntCell (org.knime.core.data.def.IntCell)2 InputStream (java.io.InputStream)1 StringValue (org.knime.core.data.StringValue)1 BinaryObjectCellFactory (org.knime.core.data.blob.BinaryObjectCellFactory)1 StringCell (org.knime.core.data.def.StringCell)1 Pair (org.knime.core.util.Pair)1 Document (org.w3c.dom.Document)1 NodeList (org.w3c.dom.NodeList)1