use of org.knime.base.node.jsnippet.type.flowvar.TypeConverter in project knime-core by knime.
the class InFieldsTableModel method validateJavaTypeColumn.
/**
* Validate java type in the given row.
* @param row the row to check
* @return error message if error occurs
*/
private String validateJavaTypeColumn(final int row) {
Object value = this.getValueAt(row, Column.JAVA_TYPE);
if (null == value) {
return "Please select a value";
}
Object input = this.getValueAt(row, Column.COLUMN);
if (value instanceof DataCellToJavaConverterFactory) {
if (input instanceof FlowVariable) {
return "DataCell converters do not work for flow variables.";
} else if (input instanceof DataColumnSpec) {
final DataType dataType = ((DataColumnSpec) input).getType();
if (!dataType.getValueClasses().contains(((DataCellToJavaConverterFactory<?, ?>) value).getSourceType())) {
return "Input DataCell is incompatible with this java type.";
}
}
// otherwise user has to fix column/flowvar first.
} else if (value instanceof String) {
// converter factory id
final String id = (String) value;
if (input instanceof DataColumnSpec) {
final DataColumnSpec colSpec = (DataColumnSpec) input;
final Optional<DataCellToJavaConverterFactory<?, ?>> factory = ConverterUtil.getDataCellToJavaConverterFactory(id);
if (!factory.isPresent()) {
return "Converter with id " + id + " could not be found.";
}
if (!colSpec.getType().getValueClasses().contains(factory.get().getSourceType())) {
// But just in case it does, this will make sure we know.
return "Selected factory does not support the input type.";
}
return null;
} else if (input instanceof FlowVariable) {
return "DataCell converters do not work for flow variables.";
}
} else if (value instanceof Class) {
Class<?> javaType = (Class<?>) value;
if (input instanceof DataColumnSpec) {
DataColumnSpec colSpec = (DataColumnSpec) input;
final Collection<?> factories = ConverterUtil.getFactoriesForSourceType(colSpec.getType());
return factories.isEmpty() ? "The java type \"" + javaType.getSimpleName() + "\" is not supported." : null;
} else if (input instanceof FlowVariable) {
FlowVariable flowVar = (FlowVariable) input;
TypeConverter typeConversion = TypeProvider.getDefault().getTypeConverter(flowVar.getType());
return typeConversion.canProvideJavaType(javaType) ? null : "The java type \"" + javaType.getSimpleName() + "\" is not supported.";
}
} else {
return "Cannot find type or converter " + value.toString();
}
return null;
}
Aggregations