use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class MissingCellHandler method fromPMMLExtension.
/**
* Creates a missing cell handler from an extension that is inside of a PMML derived field.
* @param column the column this handler is used for
* @param manager missing value factory manager
* @param ext the extension containing the necessary information
* @return a missing cell handler that was initialized from the extension
* @throws InvalidSettingsException if the the factory from the extension is not applicable for the column
*/
protected static MissingCellHandler fromPMMLExtension(final DataColumnSpec column, final MissingCellHandlerFactoryManager manager, final Extension ext) throws InvalidSettingsException {
String factoryID = ext.getValue();
MissingCellHandlerFactory fac = manager.getFactoryByID(factoryID);
if (fac == null) {
LOGGER.error("Unknown missing cell handler " + factoryID + ".");
final String[] parts = factoryID.split("\\.");
throw new InvalidSettingsException("Unknown missing cell handler " + parts[parts.length - 1] + ".");
}
if (!fac.isApplicable(column.getType())) {
throw new InvalidSettingsException("Missing cell handler " + fac.getDisplayName() + " is not applicable for columns of type " + column.getType().toString() + ".");
}
// Create document from empty node settings
NodeSettings nodeSettings = new NodeSettings("");
MissingCellHandler handler = fac.createHandler(column);
// Without a panel, the handler has no settings and we can return it
if (!fac.hasSettingsPanel()) {
return handler;
}
// Load settings from the panel
try {
// Create an XML document from empty settings
ByteArrayOutputStream baos = new ByteArrayOutputStream();
nodeSettings.saveToXML(baos);
Document doc = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(baos.toByteArray()));
// Remove original settings
doc.removeChild(doc.getFirstChild());
// And plug in those from the PMML
doc.appendChild(doc.importNode(ext.getDomNode().getFirstChild(), true));
// Now write it to a stream and create new node settings
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
StreamResult result = new StreamResult(bos);
transformer.transform(source, result);
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
NodeSettingsRO settings = NodeSettings.loadFromXML(bis);
handler.loadSettingsFrom(settings);
} catch (Exception ex) {
LOGGER.error("An error occurred while loading settings for a MissingCellHandler from PMML.\n" + ex.getMessage());
}
return handler;
}
use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class RenameNodeDialogPane method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec[] specs) throws NotConfigurableException {
DataTableSpec spec = specs[0];
if (spec.getNumColumns() == 0) {
throw new NotConfigurableException("No columns at input.");
}
m_orgTableSpec = specs[0];
m_columnToSettings.clear();
m_errornousColNames.clear();
m_individualsPanel.removeAll();
m_searchableListModifier = m_searchableListPanel.update(spec);
NodeSettingsRO subSettings;
try {
// this node settings object must contain only entry of type
// NodeSetting
subSettings = settings.getNodeSettings(RenameNodeModel.CFG_SUB_CONFIG);
} catch (InvalidSettingsException ise) {
subSettings = null;
}
if (subSettings != null) {
// process settings for individual column
for (String id : subSettings) {
NodeSettingsRO idSettings;
String nameForSettings;
try {
// idSettigs address the settings for one particular column
idSettings = subSettings.getNodeSettings(id);
// the name of the column - must match
nameForSettings = idSettings.getString(RenameColumnSetting.CFG_OLD_COLNAME);
} catch (InvalidSettingsException is) {
continue;
}
final DataColumnSpec orgSpec = m_orgTableSpec.getColumnSpec(nameForSettings);
final RenameColumnSetting renameColumnSetting = orgSpec == null ? new RenameColumnSetting(nameForSettings) : new RenameColumnSetting(orgSpec);
renameColumnSetting.loadSettingsFrom(idSettings);
if (orgSpec == null) {
DataColumnSpec invalidSpec = createInvalidSpec(nameForSettings);
m_searchableListModifier.addAdditionalColumn(invalidSpec);
m_columnToSettings.put(invalidSpec, renameColumnSetting);
} else {
m_columnToSettings.put(orgSpec, renameColumnSetting);
}
}
}
// add for each setting a panel in the individual panel
for (Map.Entry<DataColumnSpec, RenameColumnSetting> entries : m_columnToSettings.entrySet()) {
addToIndividualPanel(new RenameColumnPanel(entries.getValue(), entries.getKey(), m_hideColumnType));
}
}
use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class RowFilterNodeModel method loadOrValidateSettingsFrom.
private void loadOrValidateSettingsFrom(final NodeSettingsRO settings, final boolean verifyOnly) throws InvalidSettingsException {
IRowFilter tmpFilter = null;
if (settings.containsKey(CFGFILTER)) {
NodeSettingsRO filterCfg = settings.getNodeSettings(CFGFILTER);
// because we don't know what type of filter is in the config we
// must ask the factory to figure it out for us (actually the type
// is also saved in a valid config). When we save row filters they
// will (hopefully!!) add their type to the config.
tmpFilter = RowFilterFactory.createRowFilter(filterCfg);
} else {
throw new InvalidSettingsException("Row Filter config contains no" + " row filter.");
}
// if we got so far settings are valid.
if (verifyOnly) {
return;
}
// take over settings
m_rowFilter = tmpFilter;
return;
}
use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class InteractiveHiLiteCollectorNodeModel method loadInternals.
/**
* {@inheritDoc}
*/
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
this.reset();
File f = new File(nodeInternDir, KEY_ANNOTATIONS);
NodeSettingsRO sett = NodeSettings.loadFromXML(new FileInputStream(f));
RowKey[] rowKeys = sett.getRowKeyArray("row_keys", (RowKey[]) null);
if (rowKeys != null) {
for (RowKey key : rowKeys) {
try {
NodeSettingsRO subSett = sett.getNodeSettings(key.toString());
Map<Integer, String> map = new LinkedHashMap<Integer, String>();
for (String i : subSett.keySet()) {
try {
int idx = Integer.parseInt(i);
m_lastIndex = (m_lastIndex == null ? idx : Math.max(m_lastIndex, idx));
map.put(idx, subSett.getString(i));
} catch (InvalidSettingsException ise) {
// ignored
}
}
m_annotationMap.put(key, map);
} catch (InvalidSettingsException ise) {
// ignored
}
}
}
}
use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class AndRowFilter method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
public void loadSettingsFrom(final NodeSettingsRO cfg) throws InvalidSettingsException {
NodeSettingsRO cfg1 = cfg.getNodeSettings(CFG_FILTER1);
NodeSettingsRO cfg2 = cfg.getNodeSettings(CFG_FILTER2);
m_in1 = RowFilterFactory.createRowFilter(cfg1);
m_in2 = RowFilterFactory.createRowFilter(cfg2);
}
Aggregations