Introduction

This container assembles components using JavaScript.  The container can be used from the command line or embedded in other applications. Those application may be standalone, in-servlet context, in-EJB context or even as part of applets or Java WebStart applications.

Example usage

Embedded :-

      NanoContainer nano = new JavaScriptAssemblyNanoContainer(new StringReader("" +
                "var parentContainer = new NanoRhinoScriptable();\n" +
                "with (parentContainer) {\n" +
                "  addComponent('CompOne');\n" +
                "}\n" +
                "nano.setNanoRhinoScriptable(parentContainer)\n"
        ));

StringReader allows us to define all of this inline, but any other Reader implementation may do the trick for File or URL based component assembly definitions.

From the comand line :-

    java -cp nanocontainer-1.0.jar;picocontainer-rhino-1.0.jar;picocontainer-reflection-1.0.jar;picocontainer-1.0.jar;yourcomps.jar org.nanocontainer.JavaScriptCompositionNanoContainer components.js

The first four jars are needed by NanoContainer, the last one (yourcomps.jar) is the one your components are in.  The components.js file details the assembly and configuration of components.

Advanced use

   var parentContainer = new NanoRhinoScriptable();
   with (parentContainer) {
     addComponent('ComponentOne');
     var childContainer = new NanoRhinoScriptable();
     addContainer(childContainer);
     with (childContainer) {
        addComponent('ComponentTwo');
        addComponent('ComponentThree');
        addComponent('ComponentFour');
        addComponent('ComponentFive');
     }
     var childContainer = new NanoRhinoScriptable();
     addContainer(childContainer);
     with (childContainer) {
        addComponent('ComponentSix');
        addComponent('ComponentSeven');
     }
     addComponent('ComponentEight');
   }
   nano.setNanoRhinoScriptable(parentContainer);

Here the assembler has specified two sub-containers.The components in each of those sub-contaners can depend on the components in the the parent container but not in the adjacent container.