Search in sources :

Example 11 with JavaScriptingSettings

use of org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings in project knime-core by knime.

the class JavaRowSplitterNodeModel method loadValidatedSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadValidatedSettingsFrom(final NodeSettingsRO settings) throws InvalidSettingsException {
    JavaScriptingSettings jsSettings = m_customizer.createSettings();
    jsSettings.loadSettingsInModel(settings);
    m_settings = jsSettings;
}
Also used : JavaScriptingSettings(org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings)

Example 12 with JavaScriptingSettings

use of org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings in project knime-core by knime.

the class StringManipulationNodeModel method createColumnRearranger.

private ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
    if (m_settings == null || m_settings.getExpression() == null) {
        throw new InvalidSettingsException("No expression has been set.");
    }
    boolean isReplace = m_settings.isReplace();
    String colName = m_settings.getColName();
    JavaScriptingSettings settings = m_settings.createJavaScriptingSettings();
    try {
        settings.setInputAndCompile(spec);
        ColumnCalculator cc = new ColumnCalculator(settings, this);
        ColumnRearranger result = new ColumnRearranger(spec);
        if (isReplace) {
            result.replace(cc, colName);
        } else {
            result.append(cc);
        }
        return result;
    } catch (Exception e) {
        throw new InvalidSettingsException(e.getMessage(), e);
    }
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ColumnCalculator(org.knime.ext.sun.nodes.script.calculator.ColumnCalculator) JavaScriptingSettings(org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException)

Example 13 with JavaScriptingSettings

use of org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings in project knime-core by knime.

the class StringManipulationSettings method createJavaScriptingSettings.

/**
 * Create settings to be used by {@link ColumnCalculator} in order
 * to execute the expression.
 *
 * @return settings java scripting settings
 * @throws InvalidSettingsException when settings are not correct
 * @since 3.3
 */
public JavaScriptingSettings createJavaScriptingSettings() throws InvalidSettingsException {
    // determine return type
    m_returnType = null == m_returnType ? determineReturnType(StringUtils.strip(m_expression)) : m_returnType;
    JavaScriptingSettings s = new JavaScriptingSettings(null);
    s.setArrayReturn(false);
    s.setColName(this.getColName());
    s.setExpression("return " + this.getExpression() + ";");
    s.setExpressionVersion(Expression.VERSION_2X);
    s.setHeader("");
    s.setInsertMissingAsNull(this.isInsertMissingAsNull());
    Bundle bundle = FrameworkUtil.getBundle(this.getClass());
    try {
        List<String> includes = new ArrayList<String>();
        URL snippetIncURL = FileLocator.find(bundle, new Path("/lib/snippet_inc"), null);
        File includeDir = new File(FileLocator.toFileURL(snippetIncURL).getPath());
        for (File includeJar : includeDir.listFiles()) {
            if (includeJar.isFile() && includeJar.getName().endsWith(".jar")) {
                includes.add(includeJar.getPath());
                LOGGER.debug("Include jar file: " + includeJar.getPath());
            }
        }
        StringManipulatorProvider provider = StringManipulatorProvider.getDefault();
        includes.add(provider.getJarFile().getAbsolutePath());
        includes.add(FileLocator.getBundleFile(FrameworkUtil.getBundle(StringUtils.class)).getAbsolutePath());
        s.setJarFiles(includes.toArray(new String[includes.size()]));
    } catch (IOException e) {
        throw new IllegalStateException("Cannot locate necessary libraries due to I/O problem: " + e.getMessage(), e);
    }
    s.setReplace(this.isReplace());
    s.setReturnType(m_returnType.getName());
    s.setTestCompilationOnDialogClose(this.isTestCompilationOnDialogClose());
    List<String> imports = new ArrayList<String>();
    // Use defaults imports
    imports.addAll(Arrays.asList(Expression.getDefaultImports()));
    StringManipulatorProvider provider = StringManipulatorProvider.getDefault();
    // Add StringManipulators to the imports
    Collection<Manipulator> manipulators = provider.getManipulators(ManipulatorProvider.ALL_CATEGORY);
    for (Manipulator manipulator : manipulators) {
        String toImport = manipulator.getClass().getName();
        imports.add("static " + toImport + ".*");
    }
    s.setImports(imports.toArray(new String[imports.size()]));
    return s;
}
Also used : Path(org.eclipse.core.runtime.Path) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JavaScriptingSettings(org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings) URL(java.net.URL) Manipulator(org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator) StringUtils(org.apache.commons.lang3.StringUtils) File(java.io.File)

Aggregations

JavaScriptingSettings (org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings)13 IOException (java.io.IOException)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 ColumnCalculator (org.knime.ext.sun.nodes.script.calculator.ColumnCalculator)2 File (java.io.File)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 NoSuchElementException (java.util.NoSuchElementException)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Path (org.eclipse.core.runtime.Path)1 Manipulator (org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator)1 DataCell (org.knime.core.data.DataCell)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 RowKey (org.knime.core.data.RowKey)1 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)1 DefaultRow (org.knime.core.data.def.DefaultRow)1 DoubleCell (org.knime.core.data.def.DoubleCell)1 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)1 FlowVariable (org.knime.core.node.workflow.FlowVariable)1 UniqueNameGenerator (org.knime.core.util.UniqueNameGenerator)1