Search in sources :

Example 1 with CredentialsFlowVariableValue

use of org.knime.core.node.workflow.CredentialsStore.CredentialsFlowVariableValue in project knime-core by knime.

the class FlowVariable method load.

/**
 * Read a flow variable from a settings object. This is the counterpart
 * to {@link #save(NodeSettingsWO)}.
 * @param sub To load from.
 * @return A new {@link FlowVariable} read from the settings object.
 * @throws InvalidSettingsException If that fails for any reason.
 */
static FlowVariable load(final NodeSettingsRO sub) throws InvalidSettingsException {
    String name = sub.getString("name");
    String typeS = sub.getString("class");
    if (typeS == null || name == null) {
        throw new InvalidSettingsException("name or type is null");
    }
    Type varType;
    try {
        varType = Type.valueOf(typeS);
    } catch (final IllegalArgumentException e) {
        throw new InvalidSettingsException("invalid type " + typeS);
    }
    FlowVariable v;
    switch(varType) {
        case DOUBLE:
            v = new FlowVariable(name, sub.getDouble("value"));
            break;
        case INTEGER:
            v = new FlowVariable(name, sub.getInt("value"));
            break;
        case STRING:
            v = new FlowVariable(name, sub.getString("value"));
            break;
        case CREDENTIALS:
            NodeSettingsRO subSettings = sub.getNodeSettings("value");
            CredentialsFlowVariableValue credentialsValue = CredentialsFlowVariableValue.load(subSettings);
            v = new FlowVariable(name, credentialsValue);
            break;
        default:
            throw new InvalidSettingsException("Unknown type " + varType);
    }
    return v;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) CredentialsFlowVariableValue(org.knime.core.node.workflow.CredentialsStore.CredentialsFlowVariableValue)

Aggregations

InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)1 CredentialsFlowVariableValue (org.knime.core.node.workflow.CredentialsStore.CredentialsFlowVariableValue)1