use of org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec in project knime-core by knime.
the class FileNodePersistor method savePort.
private static void savePort(final Node node, final File portDir, final NodeSettingsWO settings, final Set<Integer> savedTableIDs, final ExecutionMonitor exec, final int portIdx, final boolean saveData) throws IOException, CanceledExecutionException {
PortObjectSpec spec = node.getOutputSpec(portIdx);
PortObject object = node.getOutputObject(portIdx);
String summary = node.getOutputObjectSummary(portIdx);
settings.addString("port_spec_class", spec != null ? spec.getClass().getName() : null);
boolean isSaveObject = saveData && object != null;
settings.addString("port_object_class", isSaveObject ? object.getClass().getName() : null);
if (saveData && object != null) {
settings.addString("port_object_summary", summary);
}
boolean isBDT = object instanceof BufferedDataTable || node.getOutputType(portIdx).equals(BufferedDataTable.TYPE);
boolean isInactive = spec instanceof InactiveBranchPortObjectSpec;
if (isBDT && !isInactive) {
assert object == null || object instanceof BufferedDataTable : "Expected BufferedDataTable, got " + object.getClass().getSimpleName();
// executed and instructed to save data
if (saveData && object != null) {
saveBufferedDataTable((BufferedDataTable) object, savedTableIDs, portDir, exec);
}
} else {
if (isSaveObject) {
exec.setMessage("Saving object");
assert spec != null : "Spec is null but port object is non-null (port " + portIdx + " of node " + node.getName() + ")";
savePortObject(spec, object, portDir, settings, exec);
}
}
}
use of org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec in project knime-core by knime.
the class FileNodePersistor method loadPort.
void loadPort(final Node node, final ReferencedFile portDir, final NodeSettingsRO settings, final ExecutionMonitor exec, final int portIdx, final Map<Integer, BufferedDataTable> loadTblRep, final HashMap<Integer, ContainerTable> tblRep, final FileStoreHandlerRepository fileStoreHandlerRepository) throws IOException, InvalidSettingsException, CanceledExecutionException {
final String specClass = settings.getString("port_spec_class");
final String objectClass = loadPortObjectClassName(settings);
PortType designatedType = node.getOutputType(portIdx);
PortObjectSpec spec = null;
PortObject object = null;
// this cannot be simplified as BDT must be loaded as BDT even if
// the port type is not BDT (but general PortObject)
boolean isBDT = (BufferedDataTable.TYPE.getPortObjectClass().getName().equals(objectClass) && BufferedDataTable.TYPE.getPortObjectSpecClass().getName().equals(specClass)) || designatedType.equals(BufferedDataTable.TYPE);
// an InactiveBranchPortObjectSpec can be put into any port!
boolean isInactive = InactiveBranchPortObjectSpec.class.getName().equals(specClass);
if (isBDT && !isInactive) {
if (specClass != null && !specClass.equals(BufferedDataTable.TYPE.getPortObjectSpecClass().getName())) {
throw new IOException("Actual spec class \"" + specClass + "\", expected \"" + BufferedDataTable.TYPE.getPortObjectSpecClass().getName() + "\"");
}
if (objectClass != null && !objectClass.equals(BufferedDataTable.TYPE.getPortObjectClass().getName())) {
throw new IOException("Actual object class \"" + objectClass + "\", expected \"" + BufferedDataTable.TYPE.getPortObjectClass().getName() + "\"");
}
if (objectClass != null) {
object = loadBufferedDataTable(portDir, exec, loadTblRep, tblRep, fileStoreHandlerRepository);
((BufferedDataTable) object).setOwnerRecursively(node);
spec = ((BufferedDataTable) object).getDataTableSpec();
} else if (specClass != null) {
spec = BufferedDataTable.loadSpec(portDir);
}
} else {
object = loadPortObject(portDir, settings, exec, fileStoreHandlerRepository).orElse(null);
spec = object != null ? object.getSpec() : null;
}
if (spec != null) {
if (!designatedType.getPortObjectSpecClass().isInstance(spec) && !isInactive) {
throw new IOException("Actual port spec type (\"" + spec.getClass().getSimpleName() + "\") does not match designated one (\"" + designatedType.getPortObjectSpecClass().getSimpleName() + "\")");
}
}
String summary = null;
if (object != null) {
if (!designatedType.getPortObjectClass().isInstance(object) && !isInactive) {
throw new IOException("Actual port object type (\"" + object.getClass().getSimpleName() + "\") does not match designated one (\"" + designatedType.getPortObjectClass().getSimpleName() + "\")");
}
summary = settings.getString("port_object_summary", null);
if (summary == null) {
summary = object.getSummary();
}
}
setPortObjectSpec(portIdx, spec);
setPortObject(portIdx, object);
setPortObjectSummary(portIdx, summary);
}
Aggregations