de.bund.bfr.knime.pmm.nodes/src/de/bund/bfr/knime/pmm/numl/NuMLReaderNodeModel.java
/*******************************************************************************
* Copyright (c) 2015 Federal Institute for Risk Assessment (BfR), Germany
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* Department Biological Safety - BfR
*******************************************************************************/
package de.bund.bfr.knime.pmm.numl;
import java.io.File;
import java.io.IOException;
import org.knime.core.data.DataTableSpec;
import org.knime.core.node.BufferedDataContainer;
import org.knime.core.node.BufferedDataTable;
import org.knime.core.node.CanceledExecutionException;
import org.knime.core.node.ExecutionContext;
import org.knime.core.node.ExecutionMonitor;
import org.knime.core.node.InvalidSettingsException;
import org.knime.core.node.NodeModel;
import org.knime.core.node.NodeSettingsRO;
import org.knime.core.node.NodeSettingsWO;
import org.knime.core.node.defaultnodesettings.SettingsModelString;
import de.bund.bfr.knime.pmm.common.generictablemodel.KnimeTuple;
import de.bund.bfr.knime.pmm.common.reader.DataTuple;
import de.bund.bfr.knime.pmm.extendedtable.pmmtablemodel.SchemaFactory;
import de.bund.bfr.pmfml.numl.NuMLDocument;
import de.bund.bfr.pmfml.numl.NuMLReader;
public class NuMLReaderNodeModel extends NodeModel {
// configuration keys
public static final String CFGKEY_FILE = "filename";
// defaults for persistent state
private static final String DEFAULT_FILE = "c:/temp/foo.numl";
// persistent state
private SettingsModelString filename = new SettingsModelString(CFGKEY_FILE, DEFAULT_FILE);
private static final DataTableSpec TABLE_SPEC = SchemaFactory.createDataSchema().createSpec();
/**
* Constructor for the node model
*/
protected NuMLReaderNodeModel() {
// 0 input ports and 1 input port
super(0, 1);
}
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec)
throws Exception {
File file = new File(filename.getStringValue());
NuMLDocument doc = NuMLReader.read(file);
KnimeTuple tuple = new DataTuple(doc).knimeTuple;
BufferedDataContainer dataContainer = exec.createDataContainer(TABLE_SPEC);
dataContainer.addRowToTable(tuple);
dataContainer.close();
BufferedDataTable[] table = { dataContainer.getTable() };
return table;
}
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
return new DataTableSpec[] { TABLE_SPEC };
}
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) {
filename.saveSettingsTo(settings);
}
@Override
protected void loadValidatedSettingsFrom(final NodeSettingsRO settings) throws InvalidSettingsException {
filename.loadSettingsFrom(settings);
}
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
filename.validateSettings(settings);
}
@Override
public void loadInternals(final File internDir, final ExecutionMonitor exec)
throws IOException, CanceledExecutionException {
}
@Override
protected void reset() {
}
@Override
protected void saveInternals(final File internDir, final ExecutionMonitor exec)
throws IOException, CanceledExecutionException {
}
}