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 ${B2BOX.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 com.amalto.b2box.groovy
will be scanned for the annotation @B2GroovyBinding
.
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 com.amalto.b2box.groovy.mybindings; import com.amalto.b2box.groovy.binding.B2GroovyBinding; @B2GroovyBinding( 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.
@B2ExecutionContext
¶
Injects a ScriptExecutionContext
with the following useful methods
Map< String, TypedContent > getPipeline() B2boxUser getUser()
Examples¶
@B2ExecutionContext private ScriptExecutionContext ctx; public class HelloWorld { public HelloWorld(){ // My no-args constructor } public String Say(){ return "Hello " + ctx.getUser().getUsername(); } }