Chapter 8 Scripting Patterns

Overview

This chapter covers some traditional and new patterns for Java-based scripting, including:

  • Scripted Components – This pattern explains how to compose an application out of reusable components (written in Java) with scripts.
  • Mediator (Glue Code) – This pattern explains how to create flexible many-to-one relationships among components.
  • Script Object Factory – This pattern explains how to improve the runtime performance
    of scripting solutions in the production environment.
  • Observer (Broadcasters) – This pattern explains how to create flexible one-to-many relationships among components.
  • Extension Point – This pattern explains how to extend components’ behavior with simple-to-write scripts.
  • Active File – This pattern explains how to use scripting to store both data and the code that handles that data in the file.

Notes

  • The example of the Script Object Factory pattern is located in the net.scriptinginjava.ch8.mediator.FactoryApp class.To build this example run:
    ant -f ch8-build.xml

    To execute this example run:

    java 
    -cp classes:$GROOVY_HOME/embeddable/groovy-all-1.0-JSR-06.jar 
    net.scriptinginjava.ch8.mediator.FactoryApp
  • The example of the Extension point pattern is located in the net.scriptinginjava.ch8.extension package.Classes Component1 and Component2 contain the first and second example respectively.
  • The example of the Active file pattern is located in the net.scriptinginjava.ch8.active package.