Custom Binding

Purpose

A custom binding is a Java class that will be instantiated and bound into the the Groovy script runtime environment.

Custom bindings are identified by their root package and class level annotations. These annotated classes are found automatically by scanning the classpath.

When a class is customer and/or implementation specific, it is typically installed as a JAR or CLASS file placed in ${P6_DATA}/lib. Care should be taken to ensure any dependent classes already exist within the b2box distribution or are also available in a folder on the classpath.

All classes with a root package of io.platform6.core.dsl will be scanned for the annotation @P6GroovyBinding. Each class identified will be instantiated using an expected no-args constructor and bound into the script environment using the name specified in the annotation.

Examples

package io.platform6.core.dsl.mybindings;

import io.platform6.core.impl.application.scripting.annotations.P6GroovyBinding;

@BP6roovyBinding( name="hello" )
public class HelloWorld {

    public HelloWorld(){
        // My no-args constructor
    }

    public String Say(){
        return "Hello World";
    }
}

Once this class is available on the Platform 6 classpath you can use the following from a Groovy script:

println hello.Say()

Annotations

For convenience, a number of field level annotations can be used to ensure your Java classes have access to useful runtime objects. Initially only a small number of field annotations will be made available but requests for others are always welcomed.

@P6ExecutionContext

Injects a ScriptExecutionContext with the following useful methods

    Map< String, TypedContent > getPipeline()
    B2boxUser getUser()

Examples

@P6ExecutionContext
private ScriptExecutionContext ctx;

public class HelloWorld {

    public HelloWorld(){
        // My no-args constructor
    }

    public String Say(){
        return "Hello " + ctx.getUser().getUsername();
    }
}