Search in sources :

Example 11 with ConfigRO

use of org.knime.core.node.config.ConfigRO in project knime-core by knime.

the class AbstractHistogramNodeModel method loadInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException {
    try {
        final File settingsFile = new File(nodeInternDir, CFG_TABLESPEC_FILE);
        final FileInputStream settingsIS = new FileInputStream(settingsFile);
        final ConfigRO settings = NodeSettings.loadFromXML(settingsIS);
        m_tableSpec = DataTableSpec.load(settings);
        final File histoDataDir = new File(nodeInternDir, CFG_DATA_DIR_NAME);
        loadXCol();
        loadAggrColumns();
        // load the data of the implementation
        loadHistogramInternals(histoDataDir, exec);
    } catch (final FileNotFoundException e) {
        LOGGER.debug("Previous implementations haven't stored the data");
        m_tableSpec = null;
    } catch (final Exception e) {
        LOGGER.debug("Error while loading table specification: " + e.getMessage());
        m_tableSpec = null;
        throw new IOException(e.getMessage());
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) ConfigRO(org.knime.core.node.config.ConfigRO) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 12 with ConfigRO

use of org.knime.core.node.config.ConfigRO in project knime-core by knime.

the class InteractivePieDataModel method loadFromFile.

/**
 * @param dataDir the data directory to read from
 * @param exec {@link ExecutionMonitor}
 * @return the {@link InteractivePieDataModel}
 * @throws IOException if the file could not be read
 * @throws InvalidSettingsException if a setting wasn't present
 * @throws CanceledExecutionException if the operation was canceled
 */
public static InteractivePieDataModel loadFromFile(final File dataDir, final ExecutionMonitor exec) throws IOException, InvalidSettingsException, CanceledExecutionException {
    final File settingFile = new File(dataDir, CFG_SETTING_FILE);
    final FileInputStream is = new FileInputStream(settingFile);
    final GZIPInputStream inData = new GZIPInputStream(is);
    final ConfigRO config = NodeSettings.loadFromXML(inData);
    final boolean supportHiliting = config.getBoolean(CFG_HILITING);
    final boolean detailsAvailable = config.getBoolean(CFG_DETAILS);
    exec.checkCanceled();
    final File dataFile = new File(dataDir, CFG_DATA_FILE);
    final ContainerTable table = DataContainer.readFromZip(dataFile);
    final int rowCount = table.getRowCount();
    final DefaultDataArray dataArray = new DefaultDataArray(table, 1, rowCount, exec);
    return new InteractivePieDataModel(dataArray, detailsAvailable, supportHiliting);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) ConfigRO(org.knime.core.node.config.ConfigRO) File(java.io.File) FileInputStream(java.io.FileInputStream) ContainerTable(org.knime.core.data.container.ContainerTable)

Example 13 with ConfigRO

use of org.knime.core.node.config.ConfigRO in project knime-core by knime.

the class VirtualSubNodeInputNodeFactory method loadPortTypeList.

/**
 * @param config
 * @return TODO
 * @throws InvalidSettingsException
 */
static PortType[] loadPortTypeList(final ConfigRO config) throws InvalidSettingsException {
    Set<String> keySet = config.keySet();
    PortType[] outTypes = new PortType[keySet.size()];
    for (String s : keySet) {
        ConfigRO portConfig = config.getConfig(s);
        int index = portConfig.getInt("index");
        CheckUtils.checkSetting(index >= 0 && index < outTypes.length, "Invalid port index must be in [0, %d]: %d", keySet.size() - 1, index);
        Config portTypeConfig = portConfig.getConfig("type");
        PortType type = PortType.load(portTypeConfig);
        outTypes[index] = type;
    }
    int invalidIndex = Arrays.asList(outTypes).indexOf(null);
    if (invalidIndex >= 0) {
        throw new InvalidSettingsException("Unassigned port type at index " + invalidIndex);
    }
    return outTypes;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Config(org.knime.core.node.config.Config) ConfigRO(org.knime.core.node.config.ConfigRO) PortType(org.knime.core.node.port.PortType)

Example 14 with ConfigRO

use of org.knime.core.node.config.ConfigRO in project knime-core by knime.

the class PMCCPortObjectAndSpec method load.

/**
 * Factory method to load from config.
 * @param m to load from.
 * @return new object loaded from argument
 * @throws InvalidSettingsException If that fails.
 */
public static PMCCPortObjectAndSpec load(final ConfigRO m) throws InvalidSettingsException {
    ConfigRO sub = m.getConfig(CFG_INTERNAL);
    String[] names = sub.getStringArray(CFG_NAMES);
    if (names == null) {
        throw new InvalidSettingsException("Column names array is null.");
    }
    if (sub.getBoolean(CFG_CONTAINS_VALUES)) {
        HalfDoubleMatrix corrMatrix = new HalfDoubleMatrix(sub.getConfig(CFG_VALUES));
        return new PMCCPortObjectAndSpec(names, corrMatrix);
    } else {
        return new PMCCPortObjectAndSpec(names);
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) HalfDoubleMatrix(org.knime.base.util.HalfDoubleMatrix) ConfigRO(org.knime.core.node.config.ConfigRO)

Example 15 with ConfigRO

use of org.knime.core.node.config.ConfigRO in project knime-core by knime.

the class ShapeModelNominal method load.

/**
 * Reads Shape settings from given <code>Config</code> and returns a new
 * <code>ShapeModelNominal</code> object.
 * @param config Reads shape model from.
 * @return A new <code>ShapeModelNominal</code> object.
 * @throws InvalidSettingsException If the <code>ShapeModel</code> settings
 *         could not be read.
 * @throws NullPointerException If the <i>config</i> is <code>null</code>.
 */
public static ShapeModelNominal load(final ConfigRO config) throws InvalidSettingsException {
    Map<DataCell, Shape> map = new LinkedHashMap<>();
    ConfigRO keyConfig = config.getConfig(CFG_KEYS);
    for (String key : keyConfig.keySet()) {
        String shape = config.getString(key.toString());
        DataCell cell = keyConfig.getDataCell(key);
        map.put(cell, ShapeFactory.getShape(shape));
    }
    return new ShapeModelNominal(map);
}
Also used : Shape(org.knime.core.data.property.ShapeFactory.Shape) DataCell(org.knime.core.data.DataCell) ConfigRO(org.knime.core.node.config.ConfigRO) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ConfigRO (org.knime.core.node.config.ConfigRO)16 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)8 FileInputStream (java.io.FileInputStream)7 Config (org.knime.core.node.config.Config)7 GZIPInputStream (java.util.zip.GZIPInputStream)6 File (java.io.File)5 LinkedHashMap (java.util.LinkedHashMap)5 Color (java.awt.Color)4 HashMap (java.util.HashMap)4 DataCell (org.knime.core.data.DataCell)4 ArrayList (java.util.ArrayList)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Set (java.util.Set)2 DefaultDataArray (org.knime.base.node.util.DefaultDataArray)2 ContainerTable (org.knime.core.data.container.ContainerTable)2 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)2 PortType (org.knime.core.node.port.PortType)2 Point (java.awt.Point)1 HashSet (java.util.HashSet)1