Scripted Builder

ScriptedPicoContainer is primarily intended to be embedded inside other applications and frameworks. We recommend using a scripted container when your application consists of many loosely-coupled components that need composition driven by external scripts at runtime, ie when re-compilation is not possible.

Building a PicoContainer from a script is simple and straightforward using a ScriptedContainerBuilder. Let's look at an example:

Do note that both parent container and assembly scope are optional and may be set to null. The assembly scope is simply a hint that may be used by container builders to build multiple container content. The container may or may not be added to the parent container - provided it is present.

The contract for interpreted languages is defined as follows:

  1. The scripts have to define a pico variable of type MutablePicoContainer
  2. The script has access to a variable named "parent", which is a MutablePicoContainer instance or null. It should be used when constructing the pico MutablePicoContainer
  3. The script has access to a variable named assemblyScope that may be used in order to decide how to compose the container. The value of this variable can be any kind of object.

Let's now in more detail at the supported interpreted languages for container composition, giving a sample script for each:

  • Beanshell: we can just use Java
  • Groovy: we can use Java as in Beanshell or use the builder syntax
  • JRuby: a similar builder syntax to Groovy
  • Jython:
  • Rhino:

The above examples in XML would be rendered as: