Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

The Intro page provides an overview and describes the motivation for the features described below. This page explains the most important APIs and mechanisms of the scripting module provided by CODI.

Dependencies

The page CODI Modules provides an overview about CODI modules and how to add them to your project.

For using the features described in this page, you have to add the core and the scripting module.

ScriptExecutor

For very simple cases you can inject the ScriptExecutor directly.

...

Code Block
java
java
titleUsing the ScriptBuilder
public class ServerSideScriptingBean
{
    @Inject
    @ScriptLanguage(JavaScript.class)
    private ScriptBuilder scriptBuilder;

    //...

    private Double calc(Double a, Double b)
    {
       return this.scriptBuilder
                .script("x + y")
                .namedArgument("x", a)
                .namedArgument("y", b)
                .eval(Double.class);
    }
}

...

Code Block
java
java
titleUsing the ScriptEngine directly
public class ServerSideScriptingBean
{
    @Inject
    @ScriptLanguage(JavaScript.class)
    private ScriptEngine scriptEngine;

    //...

    protectedprivate Double calc() throws ScriptException 
    {
        return (Double)this.scriptEngine.eval("3 + 4");
    }
}

...