Search in sources :

Example 1 with FlowVariableException

use of org.knime.base.node.jsnippet.expression.FlowVariableException in project knime-core by knime.

the class FlowVariableRepository method getValueOfType.

/**
 * Get value of a flow variable. The type of the returned object is equal
 * to the given className.
 * @param name the name of the flow variable
 * @param className the type of the returned object
 * @return the value of the flow variable
 */
@SuppressWarnings("rawtypes")
public Object getValueOfType(final String name, final Class className) {
    FlowVariable flowVar = getFlowVariable(name);
    if (null == flowVar) {
        throw new FlowVariableException("The flow variable with name \"" + name + "\" does not exist.");
    }
    TypeConverter converter = TypeProvider.getDefault().getTypeConverter(flowVar.getType());
    return converter.getValue(flowVar, className);
}
Also used : TypeConverter(org.knime.base.node.jsnippet.type.flowvar.TypeConverter) FlowVariable(org.knime.core.node.workflow.FlowVariable) FlowVariableException(org.knime.base.node.jsnippet.expression.FlowVariableException)

Example 2 with FlowVariableException

use of org.knime.base.node.jsnippet.expression.FlowVariableException in project knime-core by knime.

the class FlowVariableRepository method isOfType.

/**
 * Returns true when getValueOfType(String, Class) does not throw
 * an TypeException when called with the given flow variable and the given
 * class name.
 * @param name the name of the flow variable
 * @param className the type
 * @return true when flow variable is of type.
 */
@SuppressWarnings("rawtypes")
public boolean isOfType(final String name, final Class className) {
    FlowVariable flowVar = getFlowVariable(name);
    if (null == flowVar) {
        throw new FlowVariableException("The flow variable with name \"" + name + "\" does not exist.");
    }
    TypeConverter converter = TypeProvider.getDefault().getTypeConverter(flowVar.getType());
    return converter.canProvideJavaType(className);
}
Also used : TypeConverter(org.knime.base.node.jsnippet.type.flowvar.TypeConverter) FlowVariable(org.knime.core.node.workflow.FlowVariable) FlowVariableException(org.knime.base.node.jsnippet.expression.FlowVariableException)

Aggregations

FlowVariableException (org.knime.base.node.jsnippet.expression.FlowVariableException)2 TypeConverter (org.knime.base.node.jsnippet.type.flowvar.TypeConverter)2 FlowVariable (org.knime.core.node.workflow.FlowVariable)2