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;
}
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);
}
}
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;
}
Aggregations