Search in sources :

Example 1 with JavaSnippetSettings

use of org.knime.base.node.jsnippet.util.JavaSnippetSettings in project knime-core by knime.

the class JavaSnippetTemplate method loadSettings.

/**
 * Loads parameters.
 * @param settings to load from
 */
@Override
public void loadSettings(final NodeSettingsRO settings) {
    try {
        String metaCategory = settings.getString(META_CATEGORY, null);
        m_metaCategory = getMetaCategoryClass(metaCategory);
        m_category = settings.getString(CATEGORY, "default");
        m_name = settings.getString(NAME, "?");
        m_description = settings.getString(DESCRIPTION, "");
        m_version = settings.getString(m_version, JavaSnippetTemplate.VERSION_1_X);
        NodeSettingsRO snippet = settings.getNodeSettings(SNIPPET);
        m_snippetSettings = new JavaSnippetSettings();
        m_snippetSettings.loadSettingsForDialog(snippet);
        m_uuid = m_snippetSettings.getTemplateUUID();
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException(e);
    } catch (InvalidSettingsException e) {
        throw new IllegalStateException(e);
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) JavaSnippetSettings(org.knime.base.node.jsnippet.util.JavaSnippetSettings)

Example 2 with JavaSnippetSettings

use of org.knime.base.node.jsnippet.util.JavaSnippetSettings in project knime-core by knime.

the class JavaSnippetTest method testSimpleSnippet.

/**
 * Test execution of a simple java snippet.
 * @throws Exception
 */
@Test
public void testSimpleSnippet() throws Exception {
    final JavaSnippetSettings settings = new JavaSnippetSettings("throw new Abort(\"success\");");
    snippet.setSettings(settings);
    final AbstractJSnippet s = snippet.createSnippetInstance();
    assertNotNull(s);
    try {
        s.snippet();
        fail("Expected exception to be thrown by snippet");
    } catch (Abort e) {
        if (!e.getMessage().equals("success")) {
            throw e;
        }
    }
}
Also used : Abort(org.knime.base.node.jsnippet.expression.Abort) AbstractJSnippet(org.knime.base.node.jsnippet.expression.AbstractJSnippet) JavaSnippetSettings(org.knime.base.node.jsnippet.util.JavaSnippetSettings) Test(org.junit.Test)

Example 3 with JavaSnippetSettings

use of org.knime.base.node.jsnippet.util.JavaSnippetSettings in project knime-core by knime.

the class JavaEditVarNodeModel method validateSettings.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    JavaSnippetSettings s = new JavaSnippetSettings();
    s.loadSettings(settings);
// TODO: Check settings
}
Also used : JavaSnippetSettings(org.knime.base.node.jsnippet.util.JavaSnippetSettings)

Example 4 with JavaSnippetSettings

use of org.knime.base.node.jsnippet.util.JavaSnippetSettings in project knime-core by knime.

the class JavaSnippetTest method testAdditionalBundles.

/**
 * Test compiling with additional eclipse/osgi bundles.
 * @throws Exception
 */
@Test
public void testAdditionalBundles() throws Exception {
    final JavaSnippetSettings settings = new JavaSnippetSettings("new Complex(1.0, 1.0);");
    settings.setBundles(new String[] { "org.apache.commons.math3" });
    settings.setScriptImports("import org.apache.commons.math3.complex.Complex;");
    snippet.setSettings(settings);
    final AbstractJSnippet s = snippet.createSnippetInstance();
    assertNotNull(s);
    s.snippet();
}
Also used : AbstractJSnippet(org.knime.base.node.jsnippet.expression.AbstractJSnippet) JavaSnippetSettings(org.knime.base.node.jsnippet.util.JavaSnippetSettings) Test(org.junit.Test)

Example 5 with JavaSnippetSettings

use of org.knime.base.node.jsnippet.util.JavaSnippetSettings in project knime-core by knime.

the class JavaSnippetTest method testEncoding.

/**
 * Test encoding.
 * @throws Exception
 */
@Test
public void testEncoding() throws Exception {
    final JavaSnippetSettings settings = new JavaSnippetSettings("outString = \"���\";");
    final OutCol outCol = new OutCol();
    outCol.setJavaName("outString");
    outCol.setConverterFactory(ConverterUtil.getConverterFactory(String.class, StringCell.TYPE).get());
    settings.getJavaSnippetFields().getOutColFields().add(outCol);
    snippet.setSettings(settings);
    final AbstractJSnippet s = snippet.createSnippetInstance();
    assertNotNull(s);
    s.snippet();
    final Field outStringField = s.getClass().getField("outString");
    final String string = (String) outStringField.get(s);
    assertEquals(string, "���");
}
Also used : Field(java.lang.reflect.Field) OutCol(org.knime.base.node.jsnippet.util.field.OutCol) AbstractJSnippet(org.knime.base.node.jsnippet.expression.AbstractJSnippet) JavaSnippetSettings(org.knime.base.node.jsnippet.util.JavaSnippetSettings) Test(org.junit.Test)

Aggregations

JavaSnippetSettings (org.knime.base.node.jsnippet.util.JavaSnippetSettings)7 Test (org.junit.Test)3 AbstractJSnippet (org.knime.base.node.jsnippet.expression.AbstractJSnippet)3 Field (java.lang.reflect.Field)1 Abort (org.knime.base.node.jsnippet.expression.Abort)1 FieldsTableModel (org.knime.base.node.jsnippet.ui.FieldsTableModel)1 OutFieldsTableModel (org.knime.base.node.jsnippet.ui.OutFieldsTableModel)1 OutCol (org.knime.base.node.jsnippet.util.field.OutCol)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)1