use of org.knime.core.data.DataType in project knime-core by knime.
the class JavaToDataCellConverterRegistry method register.
/**
* Register a DataCellToJavaConverterFactory.
*
* @param factory The factory to register
*/
public synchronized void register(final JavaToDataCellConverterFactory<?> factory) {
if (factory == null) {
throw new IllegalArgumentException("factory must not be null");
}
final ConversionKey key = new ConversionKey(factory);
ArrayList<JavaToDataCellConverterFactory<?>> list = m_converterFactories.get(key);
if (list == null) {
list = new ArrayList<>();
m_converterFactories.put(key, list);
}
list.add(factory);
final DataType destType = factory.getDestinationType();
Set<JavaToDataCellConverterFactory<?>> byDestinationType = m_byDestinationType.get(destType);
if (byDestinationType == null) {
byDestinationType = new LinkedHashSet<>();
m_byDestinationType.put(destType, byDestinationType);
}
byDestinationType.add(factory);
final Class<?> sourceType = factory.getSourceType();
Set<JavaToDataCellConverterFactory<?>> bySourceType = m_bySourceType.get(sourceType);
if (bySourceType == null) {
bySourceType = new LinkedHashSet<>();
m_bySourceType.put(sourceType, bySourceType);
bySourceType.add(factory);
} else {
bySourceType.add(factory);
}
final JavaToDataCellConverterFactory<?> previous = m_byIdentifier.put(factory.getIdentifier(), factory);
if (previous != null) {
LOGGER.coding("JavaToDataCellConverterFactory identifier is not unique (" + factory.getIdentifier() + ")");
}
}
use of org.knime.core.data.DataType in project knime-core by knime.
the class JavaToDataCellConverterRegistry method parseAnnotations.
private void parseAnnotations() {
final Collection<DataType> availableDataTypes = DataTypeRegistry.getInstance().availableDataTypes();
for (final DataType dataType : availableDataTypes) {
final Optional<DataCellFactory> cellFactory = dataType.getCellFactory(null);
if (cellFactory.isPresent()) {
final Class<? extends DataCellFactory> cellFactoryClass = cellFactory.get().getClass();
for (final Pair<Method, DataCellFactoryMethod> pair : ClassUtil.getMethodsWithAnnotation(cellFactoryClass, DataCellFactoryMethod.class)) {
final Method method = pair.getFirst();
try {
final JavaToDataCellConverterFactory<?> factory = new FactoryMethodToDataCellConverterFactory<>(cellFactoryClass, method, ClassUtil.ensureObjectType(method.getParameterTypes()[0]), dataType, pair.getSecond().name());
// Check name of factory
if (!validateFactoryName(factory)) {
LOGGER.warn("JavaToDataCellFactory name \"" + factory.getName() + "\" of factory with id \"" + factory.getIdentifier() + "\" does not follow naming convention (see DataCellFactoryMethod#name()).");
LOGGER.warn("Factory will not be registered.");
continue;
}
register(factory);
LOGGER.debug("Registered JavaToDataCellConverterFactory from DataCellFactoryMethod annotation for: " + method.getParameterTypes()[0].getName() + " to " + dataType.getName());
} catch (IncompleteAnnotationException e) {
LOGGER.coding("Incomplete DataCellFactoryMethod annotation for " + cellFactoryClass.getName() + "." + method.getName() + ". Will not register.", e);
} catch (NoSuchMethodException | SecurityException ex) {
LOGGER.error("Could not access default constructor or constructor with parameter 'ExecutionContext' of " + "class '" + cellFactoryClass.getName() + "'. Converter will not be registered.", ex);
}
}
}
}
}
use of org.knime.core.data.DataType in project knime-core by knime.
the class DataCellToJavaConverterRegistry method parseAnnotations.
/*
* Parse @DataCellFactoryMethod and @DataValueAccessMethod annotations
*/
private void parseAnnotations() {
final Collection<DataType> availableDataTypes = DataTypeRegistry.getInstance().availableDataTypes();
final Set<Class<? extends DataValue>> processedValueClasses = new HashSet<>();
for (final DataType dataType : availableDataTypes) {
for (final Class<? extends DataValue> valueClass : dataType.getValueClasses()) {
if (processedValueClasses.contains(valueClass)) {
// already parsed this value class
continue;
}
// get methods annotated with DataValueAccessMethod
final Collection<Pair<Method, DataValueAccessMethod>> methodsWithAnnotation = ClassUtil.getMethodsWithAnnotation(valueClass, DataValueAccessMethod.class);
// register a converter for every DataValueAccessMethod annotation
for (final Pair<Method, DataValueAccessMethod> pair : methodsWithAnnotation) {
parseAnnotation(valueClass, pair.getFirst(), pair.getSecond());
}
processedValueClasses.add(valueClass);
}
}
}
use of org.knime.core.data.DataType in project knime-core by knime.
the class BlobSupportDataCellList method init.
private void init(final Collection<? extends DataCell> coll) {
ArrayList<DataCell> cellList = new ArrayList<DataCell>(coll.size());
DataType commonType = null;
for (DataCell c : coll) {
if (c == null) {
throw new NullPointerException("List element must not be null");
}
DataType cellType;
if (c instanceof BlobWrapperDataCell) {
m_containsBlobWrapperCells = true;
cellList.add(c);
cellType = DataType.getType(((BlobWrapperDataCell) c).getBlobClass());
} else if (c instanceof BlobDataCell) {
m_containsBlobWrapperCells = true;
cellList.add(new BlobWrapperDataCell((BlobDataCell) c));
cellType = c.getType();
} else {
cellList.add(c);
cellType = c.getType();
}
if (!c.isMissing()) {
if (commonType == null) {
commonType = cellType;
} else {
commonType = DataType.getCommonSuperType(commonType, cellType);
}
}
}
if (commonType == null) {
m_elementType = DataType.getMissingCell().getType();
} else {
m_elementType = commonType;
}
m_cellList = cellList;
}
use of org.knime.core.data.DataType in project knime-core by knime.
the class ColumnRearranger method ensureColumnIsConverted.
/**
* @param converter
* @param index
* @since 2.7
*/
public final void ensureColumnIsConverted(final DataCellTypeConverter converter, final int index) {
SpecAndFactoryObject current = m_includes.get(index);
DataType converterOutputType = converter.getOutputType();
DataColumnSpec colSpec = current.getColSpec();
if (converterOutputType.equals(colSpec.getType())) {
LOGGER.debug("Converting column \"" + colSpec.getName() + "\" not required.");
} else {
LOGGER.debug("Converting column \"" + colSpec.getName() + "\" required.");
DataColumnSpecCreator c = new DataColumnSpecCreator(colSpec);
c.setType(converterOutputType);
DataCellTypeConverterCellFactory cellConverter = new DataCellTypeConverterCellFactory(c.createSpec(), converter, index);
replace(cellConverter, index);
}
}
Aggregations